-
Notifications
You must be signed in to change notification settings - Fork 336
/
event-translate.py
executable file
·36 lines (35 loc) · 1.17 KB
/
event-translate.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
#!/usr/bin/env python3
# translate raw events to names
# event-translate rXXX ...
from __future__ import print_function
import re
import sys
import ocperf
from pmudef import EVMASK, EVENTSEL_EVENT, EVENTSEL_UMASK, extra_flags
emap = ocperf.find_emap()
if not emap:
sys.exit("Unknown CPU or cannot find event table")
for j in sys.argv[1:]:
m = re.match(r'r([0-9a-f]+)(:.*)?', j)
if m:
print(m.group(1))
evsel = int(m.group(1), 16)
print("%s:" % (j))
if evsel & EVMASK in emap.codes:
print(emap.codes[evsel & EVMASK].name)
elif (evsel & (EVENTSEL_EVENT|EVENTSEL_UMASK)) in emap.codes:
print(emap.codes[evsel & (EVENTSEL_EVENT|EVENTSEL_UMASK)].name, end='')
for k in extra_flags:
if evsel & k[0]:
m = k[0]
en = evsel
while (m & 1) == 0:
m >>= 1
en >>= 1
print("%s=%d" % (k[1], en & m),end='')
print()
else:
print("cannot find", m.group(1))
else:
# XXX implement offcore new style events
print("cannot parse", j)