-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_profile_data.py
78 lines (66 loc) · 2.14 KB
/
extract_profile_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import sys
import json
CPU_DIR = "profiles/cpu"
MEM_DIR = "profiles/mem"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("missing profile name parameter")
sys.exit(1)
prof_name = sys.argv[1]
cpu_data = []
for profile_f in [f for f in os.listdir(CPU_DIR) if f.endswith(".txt")]:
profile_f = f"{CPU_DIR}/{profile_f}"
#print(profile_f)
with open(profile_f) as f:
data = [ln.split() for ln in f.read().splitlines()]
#print(data[3])
if len(data[3]) == 7:
tot_samples = data[3][6][1:-1]
elif len(data[3]) == 8:
tot_samples = data[3][7][:-1]
else:
tot_samples = "0"
datum = {
"duration": data[3][1],
"total samples": (data[3][5], tot_samples),
**{
' '.join(d[5:]): {
"flat": d[0],
"flat%": d[1],
"sum%": d[2],
"cum": d[3],
"cum%": d[4],
} for d in data[6:]
}
}
# print(json.dumps(datum, indent=2))
cpu_data.append(datum)
with open(f"profiles/res/cpu_{prof_name}.json", 'w') as f:
f.write(json.dumps(cpu_data))
#print(len(cpu_data))
del(cpu_data)
mem_data = []
for profile_f in [f for f in os.listdir(MEM_DIR) if f.endswith(".txt")]:
profile_f = f"{MEM_DIR}/{profile_f}"
#print(profile_f)
with open(profile_f) as f:
data = [ln.split() for ln in f.read().splitlines()]
# print(data[3])
datum = {
"total": data[3][-2],
**{
' '.join(d[5:]): {
"flat": d[0],
"flat%": d[1],
"sum%": d[2],
"cum": d[3],
"cum%": d[4],
} for d in data[6:]
}
}
# print(json.dumps(datum, indent=2))
mem_data.append(datum)
with open(f"profiles/res/mem_{prof_name}.json", 'w') as f:
f.write(json.dumps(mem_data))
#print(len(mem_data))