-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjson-timings-to-graph
executable file
·50 lines (34 loc) · 1.24 KB
/
json-timings-to-graph
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright © 2019 Martin Ueding <[email protected]>
import argparse
import json
import math
import os
import subprocess
import jinja2
def main():
options = _parse_args()
with open(options.profile) as f:
profile = json.load(f)
env = jinja2.Environment(loader=jinja2.FileSystemLoader(
os.path.dirname(os.path.abspath(__file__))))
template = env.get_template('profile.dot.j2')
tottime = profile['nodes'][0]['cumtime']
for i, node in enumerate(profile['nodes']):
profile['nodes'][i]['hue'] = '{:.4f}'.format(250/360 * (1 - math.pow(node['cumtime'] / tottime, 0.5)))
rendered = template.render(vertices=profile['nodes'], edges=profile['edges'], tottime=tottime)
print('Generated graph.')
with open('profile.dot', 'w') as f:
f.write(rendered)
print('Wrote graph.')
subprocess.run(['dot', 'profile.dot', '-Tpdf', '-o', 'profile.pdf'])
subprocess.run(['dot', 'profile.dot', '-Tpng', '-o', 'profile.png'])
print('Compiled graph.')
def _parse_args():
parser = argparse.ArgumentParser(description='')
parser.add_argument('profile')
options = parser.parse_args()
return options
if __name__ == '__main__':
main()