MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / create_profiling_graph

Function create_profiling_graph

tools/emprofile.py:34–68  ·  view source on GitHub ↗
(outfile)

Source from the content-addressed store, hash-verified

32
33
34def create_profiling_graph(outfile):
35 log_files = [f for f in list_files_in_directory(profiler_logs_path) if 'toolchain_profiler.pid_' in f]
36
37 all_results = []
38 if log_files:
39 print(f'Processing {len(log_files)} profile log files in {profiler_logs_path}...')
40 for f in log_files:
41 print(f'Processing: {f}')
42 json_data = Path(f).read_text(encoding='utf-8')
43 if len(json_data.strip()) == 0:
44 continue
45 lines = json_data.split('\n')
46 lines = [x for x in lines if x not in {'[', ']', ','} and len(x.strip())]
47 lines = [(x + ',') if not x.endswith(',') else x for x in lines]
48 lines[-1] = lines[-1][:-1]
49 json_data = '[' + '\n'.join(lines) + ']'
50 try:
51 all_results += json.loads(json_data)
52 except json.JSONDecodeError as e:
53 print(str(e), file=sys.stderr)
54 print('Failed to parse JSON file "' + f + '"!', file=sys.stderr)
55 return 1
56 if len(all_results) == 0:
57 print(f'No profiler logs were found in path: ${profiler_logs_path}.\nTry setting the environment variable EMPROFILE=1 and run some emcc commands, then re-run "emprofile.py --graph".', file=sys.stderr)
58 return 1
59
60 all_results.sort(key=lambda x: x['time'])
61
62 emprofile_json_data = json.dumps(all_results, indent=2)
63
64 html_file = outfile + '.html'
65 html_contents = Path(os.path.dirname(os.path.realpath(__file__)), 'toolchain_profiler.results_template.html').read_text(encoding='utf-8').replace('{{{ emprofile_json_data }}}', emprofile_json_data)
66 Path(html_file).write_text(html_contents, encoding='utf-8')
67 print(f'Wrote "{html_file}"')
68 return 0
69
70
71def main(args):

Callers 1

mainFunction · 0.85

Calls 4

list_files_in_directoryFunction · 0.85
splitMethod · 0.80
printFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected