Mercurial > hg
comparison contrib/catapipe.py @ 42475:ff562d711919
catapipe: add support for COUNTER events
Differential Revision: https://phab.mercurial-scm.org/D6524
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 12 Jun 2019 19:00:46 -0400 |
parents | c311424ea579 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42474:adb636392b3f | 42475:ff562d711919 |
---|---|
42 import timeit | 42 import timeit |
43 | 43 |
44 _TYPEMAP = { | 44 _TYPEMAP = { |
45 'START': 'B', | 45 'START': 'B', |
46 'END': 'E', | 46 'END': 'E', |
47 'COUNTER': 'C', | |
47 } | 48 } |
48 | 49 |
49 _threadmap = {} | 50 _threadmap = {} |
50 | 51 |
51 # Timeit already contains the whole logic about which timer to use based on | 52 # Timeit already contains the whole logic about which timer to use based on |
76 if args.debug: | 77 if args.debug: |
77 print(ev) | 78 print(ev) |
78 verb, session, label = ev.split(' ', 2) | 79 verb, session, label = ev.split(' ', 2) |
79 if session not in _threadmap: | 80 if session not in _threadmap: |
80 _threadmap[session] = len(_threadmap) | 81 _threadmap[session] = len(_threadmap) |
82 if verb == 'COUNTER': | |
83 amount, label = label.split(' ', 1) | |
84 payload_args = {'value': int(amount)} | |
85 else: | |
86 payload_args = {} | |
81 pid = _threadmap[session] | 87 pid = _threadmap[session] |
82 ts_micros = (now - start) * 1000000 | 88 ts_micros = (now - start) * 1000000 |
83 out.write(json.dumps( | 89 out.write(json.dumps( |
84 { | 90 { |
85 "name": label, | 91 "name": label, |
86 "cat": "misc", | 92 "cat": "misc", |
87 "ph": _TYPEMAP[verb], | 93 "ph": _TYPEMAP[verb], |
88 "ts": ts_micros, | 94 "ts": ts_micros, |
89 "pid": pid, | 95 "pid": pid, |
90 "tid": 1, | 96 "tid": 1, |
91 "args": {} | 97 "args": payload_args, |
92 })) | 98 })) |
93 out.write(',\n') | 99 out.write(',\n') |
94 finally: | 100 finally: |
95 os.unlink(fn) | 101 os.unlink(fn) |
96 | 102 |