-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-pptt-log.py
104 lines (85 loc) · 2.97 KB
/
parse-pptt-log.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/python3
import sys
pptt = {}
struct = {}
def print_struct():
if struct['type'] == 'socket':
struct['show'] = 'socket: '
elif struct['type'] == 'cluster':
struct['show'] = ' cluster: '
elif struct['type'] == 'core':
struct['show'] = ' core: '
elif struct['type'] == 'cache':
struct['show'] = ' cache: '
elif struct['type'] == 'thread':
struct['show'] = ' thread: '
print(f"{struct['show']} offset: {struct['address']}", end='')
if 'parent' in struct:
print(f" parent: {struct['parent']}", end='')
if 'cpuid' in struct and struct['type'] in ['core', 'thread']:
print(f" cpuId: {struct['cpuid']}", end='')
if 'l1i' in struct:
print(f" L1i: {struct['l1i']}", end='')
print(f" L1d: {struct['l1d']}", end='')
if struct['type'] == 'cache':
if 'cacheid' in struct:
print(f" cacheId: {struct['cacheid']}", end='')
print(f" size: {struct['size']}", end='')
if struct['nextcache'] != '0x0':
print(f" next: {struct['nextcache']}", end='')
print(' ')
with open(sys.argv[1], encoding='utf-8') as log:
start_parsing = False
while True:
line = log.readline()
if line.startswith('PPTT'):
start_parsing = True
elif line.startswith('-smp'):
print(line.strip())
elif line.startswith('Table Statistics'):
break
# empty
elif line.strip() == "":
continue
if not start_parsing:
continue;
# parsing starts
try:
value = line.split(':')[1].strip()
except IndexError:
break
if '* Structure Offset *' in line:
if 'type' in struct:
print_struct()
struct = {}
struct['address'] = value
elif 'Flags' in line:
struct['flags'] = value
if struct['flags'] == '0x11':
struct['type'] = 'socket'
elif struct['flags'] == '0x10':
struct['type'] = 'cluster'
elif struct['flags'] == '0x1E':
struct['type'] = 'thread'
elif struct['flags'] == '0x7F':
struct['type'] = 'cache'
elif struct['flags'] == '0xFF':
struct['type'] = 'cache'
elif 'Parent' in line:
struct['parent'] = value
elif 'Parent' in line:
struct['parent'] = value
elif 'Private resources [0]' in line:
struct['l1i'] = value
struct['type'] = 'core'
elif 'Private resources [1]' in line:
struct['l1d'] = value
elif 'Next Level of Cache' in line:
struct['nextcache'] = value
elif 'Cache ID' in line:
struct['cacheid'] = value
elif 'Size' in line:
struct['size'] = value
elif 'ACPI Processor ID' in line:
struct['cpuid'] = value
print_struct()