source: tools/perf/process_stat_array.py @ 8f2f185

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 8f2f185 was d00ce99, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Several improvements to process_stat_array

  • Property mode set to 100755
File size: 4.4 KB
RevLine 
[77f1265]1#!/usr/bin/python3
2
[d00ce99]3import argparse, json, math, os, sys, re
4from PIL import Image
5import numpy as np
[77f1265]6
7def dir_path(string):
8    if os.path.isdir(string):
9        return string
10    else:
11        raise NotADirectoryError(string)
12
13parser = argparse.ArgumentParser()
14parser.add_argument('--path', type=dir_path, default=".cfadata", help= 'paste path to biog.txt file')
[d00ce99]15parser.add_argument('--out', type=argparse.FileType('w'), default=sys.stdout)
[77f1265]16
17try :
18        args = parser.parse_args()
19except NotADirectoryError:
20        print("Must use option --path to existing directory or have .cfadata in current directory", file=sys.stderr)
21        sys.exit(1)
22
23root, _, filenames = next(os.walk(args.path))
24
25merged = []
26counters = {}
27
[d00ce99]28max_cpu = 0
29min_cpu = 1000000
30max_tsc = 0
31min_tsc = 18446744073709551615
32
[77f1265]33#open the files
34for filename in filenames:
35        try:
36                m = re.search('[A-z]+0x([0-9a-f]+)\.data', filename)
37                me = m.group(1)
38                counters[me] = 0
39                with open(os.path.join(root, filename), 'r') as file:
40                        for line in file:
[d00ce99]41                                raw = [int(x.strip()) for x in line.split(',')]
42
43                                ## from/to
44                                high = (raw[1] >> 32)
45                                low  = (raw[1] & 0xffffffff)
46                                data = [me, raw[0], high, low]
47                                max_cpu = max(max_cpu, high, low)
48                                min_cpu = min(min_cpu, high, low)
49
50                                ## number
51                                # high = (raw[1] >> 8)
52                                # low  = (raw[1] & 0xff)
53                                # data = [me, raw[0], high, low]
54                                # max_cpu = max(max_cpu, low)
55                                # min_cpu = min(min_cpu, low)
56
57
58                                max_tsc = max(max_tsc, raw[0])
59                                min_tsc = min(min_tsc, raw[0])
[77f1265]60                                merged.append(data)
61
[d00ce99]62        except Exception as e:
63                print(e)
[77f1265]64                pass
65
66
[d00ce99]67print({"max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc})
68
[77f1265]69# Sort by timestamp (the second element)
70# take second element for sort
71def takeSecond(elem):
72    return elem[1]
73
74merged.sort(key=takeSecond)
75
[d00ce99]76json.dump({"values":merged, "max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc}, args.out)
77
78# vmin = merged[ 0][1]
79# vmax = float(merged[-1][1] - vmin) / 2500000000.0
80# # print(vmax)
81
82# bins = []
83# for _ in range(0, int(math.ceil(vmax * 10))):
84#       bins.append([0] * (32 * 32))
85
86# # print(len(bins))
87# bins = np.array(bins)
88
89# rejected = 0
90# highest  = 0
91
92# for x in merged:
93#       b = int(float(x[1] - vmin) / 250000000.0)
94#       from_ = x[2]
95#       if from_ < 0 or from_ > 32:
96#               rejected += 1
97#               continue;
98#       to_   = x[3]
99#       if to_ < 0 or to_ > 32:
100#               rejected += 1
101#               continue;
102#       idx = (to_ * 32) + from_
103#       bins[b][idx] = bins[b][idx] + 1
104#       highest = max(highest, bins[b][idx])
105
106# bins = np.array(map(lambda x: np.int8(x * 255.0 / float(highest)), bins))
107
108# print([highest, rejected])
109# print(bins.shape)
110
111# im = Image.fromarray(bins)
112# im.save('test.png')
113
114# vmax = merged[-1][1]
115
116# diff = float(vmax - vmin) / 2500000000.0
117# print([vmin, vmax])
118# print([vmax - vmin, diff])
119
120# print(len(merged))
121
122# for b in bins:
123#       print(b)
[77f1265]124
[d00ce99]125# single = []
126# curr = 0
[77f1265]127
[d00ce99]128# # merge the data
129# # for (me, time, value) in merged:
130# for (me, value) in merged:
131#       # check now much this changes
132#       old = counters[me]
133#       change = value - old
134#       counters[me] = value
[77f1265]135
[d00ce99]136#       # add change to the current
137#       curr = curr + change
138#       single.append( value )
[77f1265]139
[d00ce99]140#       pass
[77f1265]141
[d00ce99]142# print(single)
[b1a2c4a]143
144# single = sorted(single)[:len(single)-100]
145# ms = max(single)
146# single = [float(x) / 2500.0 for x in single]
147
[77f1265]148#print
[b1a2c4a]149# for t, v in single:
150#       print([t, v])
151# print(len(single))
152# print(max(single))
153# print(min(single))
154
155# bins = [0, 5.37751600e+04, 1.06903320e+05, 1.60031480e+05, 2.13159640e+05, 2.66287800e+05, 3.19415960e+05, 3.72544120e+05, 4.25672280e+05, 4.78800440e+05, 5.31928600e+05, 5.85056760e+05, 6.38184920e+05, 6.91313080e+05, 7.44441240e+05, 7.97569400e+05, 8.50697560e+05, 9.03825720e+05, 9.56953880e+05, 1.01008204e+06, 1.06321020e+06, 1.11633836e+06, 1.16946652e+06, 1.22259468e+06, 1.27572284e+06, 1.32885100e+06, 1.38197916e+06, 1.43510732e+06, 1.48823548e+06, 1.54136364e+06, 1.59449180e+06, 1.64761996e+06, 1.70074812e+06, 1.75387628e+06, 1.80700444e+06, 1.86013260e+06, 1.91326076e+06, 1.96638892e+06, 2.01951708e+06, 2.07264524e+06, 2.12577340e+06, 2.17890156e+06, 2.23202972e+06, 2.28515788e+06, 2.33828604e+06, 2.39141420e+06, 2.44454236e+06, 2.49767052e+06, 2.55079868e+06, 2.60392684e+06, 3.0e+06]
156# # bins = [float(x) / 2500.0 for x in bins]
157# # print([round(b, 2) for b in bins])
158
159# import numpy
160# # hist1, _ = numpy.histogram(single, density=True, bins=50)
161# hist2, _ = numpy.histogram(single, density=True, bins=bins)
162# # print(hist1)
163# print([1000.0 * h for h in hist2])
164# # for v in single:
165# #     print([v])
Note: See TracBrowser for help on using the repository browser.