summaryrefslogtreecommitdiffstats
path: root/tools/gr-regs/analyze_regs.py
blob: b03aca41cfd675317664a1aa2e4a1cd82cc217ba (plain)
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
#!/usr/bin/env python3
import collections, sys
path = sys.argv[1] if len(sys.argv) > 1 else '/tmp/opencode/regs-m63.txt'
cmp_mode = len(sys.argv) > 2 and sys.argv[2] == 'cmp'
hdr = None
rows = []
with open(path) as f:
    for line in f:
        if line.startswith('#'):
            if line.startswith('# ts '):
                hdr = line.split()[2:]
            continue
        p = line.split()
        if len(p) >= 2:
            rows.append((float(p[0]), p))
print("samples:", len(rows), "t range", rows[0][0], rows[-1][0])
cols = collections.defaultdict(collections.Counter)
h = {n: i for i, n in enumerate(hdr)}
for t, p in rows:
    for i, n in enumerate(hdr):
        if 1 + i < len(p):
            cols[n][p[1 + i]] += 1
for n in ('FECS_CURRENT_CTX', 'FECS_NEW_CTX', 'CWD_TABLE_0', 'CWD_TABLE_1',
          'SKED_HWW_ESR', 'SKED_ACTIVITY', 'GRFIFO_STATUS', 'FECS_CPUCTL',
          'PGRAPH_STATUS', 'PMC_ENABLE'):
    c = cols.get(n)
    if c:
        print('%-22s %s' % (n, ', '.join('%s x%d' % (k, v) for k, v in c.most_common(8))))
# interesting transitions: where FECS_CURRENT_CTX or CWD_TABLE_0 or GRFIFO change
print("=== transitions (FECS_CURRENT_CTX / CWD_T0 / GRFIFO) ===")
last = {}
for t, p in rows:
    key = (p[1 + h['FECS_CURRENT_CTX']], p[1 + h['CWD_TABLE_0']], p[1 + h['GRFIFO_STATUS']])
    if key != last.get('k'):
        print('t=%8.2f FECS=%s NEW=%s CWD0=%s CWD1=%s SKED_ACT=%s GRFIFO=%s PGRAPH=%s' % (
            t, key[0], p[1 + h['FECS_NEW_CTX']], key[1], p[1 + h['CWD_TABLE_1']],
            p[1 + h['SKED_ACTIVITY']], key[2], p[1 + h['PGRAPH_STATUS']]))
        last['k'] = key