This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
hybrid-json-to-perf-json.py
executable file
·75 lines (62 loc) · 2.44 KB
/
hybrid-json-to-perf-json.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
#!/usr/bin/python
# generate hybrid perf json files from two perf json files (core and atom)
# For example,
# hybrid-json-to-perf-json.py alderlake_gracemont_core_v0.01_private.json alderlake_goldencove_v0.01_private.json
import os
import re
import json
import argparse
import sys
import importlib
from typing import TextIO
json_to_perf_json = importlib.import_module("json-to-perf-json")
def hybrid_json_to_perf_json(atomjson: TextIO, corejson: TextIO, outdir: str):
def combine_jsons(atom_path, core_path, name, out_path):
jn = []
if len(atom_path) > 0:
f = open(atom_path, 'r')
ja = json.load(f)
if isinstance(ja, dict) and ja["Header"]:
ja = ja["Events"]
for l in ja:
jn.append(l)
f.close()
if len(core_path) > 0:
f = open(core_path, 'r')
jc = json.load(f)
if isinstance(jc, dict) and jc["Header"]:
jc = jc["Events"]
for l in jc:
jn.append(l)
f.close()
ofile = open("%s/%s" % (out_path, name), "w")
json.dump(jn, ofile, sort_keys=True, indent=4, separators=(',', ': '))
ofile.write("\n")
ofile.close()
os.system('rm -rf tmp-atom tmp-core')
os.system('mkdir -p tmp-atom')
os.system('mkdir -p tmp-core')
atom_out = json_to_perf_json.json_to_perf_json(atomjson, "tmp-atom", "cpu_atom")
core_out = json_to_perf_json.json_to_perf_json(corejson, "tmp-core", "cpu_core")
inter = list(set(atom_out).intersection(set(core_out)))
diff1 = list(set(core_out).difference(set(atom_out)))
diff2 = list(set(atom_out).difference(set(core_out)))
for s in inter:
atom_path = "./tmp-atom/" + s
core_path = "./tmp-core/" + s
combine_jsons(atom_path, core_path, s,outdir)
for s in diff1:
core_path = "./tmp-core/" + s
combine_jsons('', core_path, s, outdir)
for s in diff2:
atom_path = "./tmp-atom/" + s
combine_jsons(atom_path, '', s, outdir)
def main():
ap = argparse.ArgumentParser()
ap.add_argument('atomjson', type=argparse.FileType('r'), help="Input atom json file")
ap.add_argument('corejson', type=argparse.FileType('r'), help="Input core json file")
ap.add_argument('--outdir', default='.')
args = ap.parse_args()
hybrid_json_to_perf_json(args.atomjson, args.corejson, args.outdir)
if __name__ == '__main__':
main()