Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHGff562d711919: catapipe: add support for COUNTER events
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | contrib/catapipe.py (8 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
a87adea421a8 | de6d7e98b711 | Augie Fackler | Jun 12 2019, 7:00 PM |
import argparse | import argparse | ||||
import json | import json | ||||
import os | import os | ||||
import timeit | import timeit | ||||
_TYPEMAP = { | _TYPEMAP = { | ||||
'START': 'B', | 'START': 'B', | ||||
'END': 'E', | 'END': 'E', | ||||
'COUNTER': 'C', | |||||
} | } | ||||
_threadmap = {} | _threadmap = {} | ||||
# Timeit already contains the whole logic about which timer to use based on | # Timeit already contains the whole logic about which timer to use based on | ||||
# Python version and OS | # Python version and OS | ||||
timer = timeit.default_timer | timer = timeit.default_timer | ||||
if not ev: | if not ev: | ||||
continue | continue | ||||
now = timer() | now = timer() | ||||
if args.debug: | if args.debug: | ||||
print(ev) | print(ev) | ||||
verb, session, label = ev.split(' ', 2) | verb, session, label = ev.split(' ', 2) | ||||
if session not in _threadmap: | if session not in _threadmap: | ||||
_threadmap[session] = len(_threadmap) | _threadmap[session] = len(_threadmap) | ||||
if verb == 'COUNTER': | |||||
amount, label = label.split(' ', 1) | |||||
payload_args = {'value': int(amount)} | |||||
else: | |||||
payload_args = {} | |||||
pid = _threadmap[session] | pid = _threadmap[session] | ||||
ts_micros = (now - start) * 1000000 | ts_micros = (now - start) * 1000000 | ||||
out.write(json.dumps( | out.write(json.dumps( | ||||
{ | { | ||||
"name": label, | "name": label, | ||||
"cat": "misc", | "cat": "misc", | ||||
"ph": _TYPEMAP[verb], | "ph": _TYPEMAP[verb], | ||||
"ts": ts_micros, | "ts": ts_micros, | ||||
"pid": pid, | "pid": pid, | ||||
"tid": 1, | "tid": 1, | ||||
"args": {} | "args": payload_args, | ||||
})) | })) | ||||
out.write(',\n') | out.write(',\n') | ||||
finally: | finally: | ||||
os.unlink(fn) | os.unlink(fn) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |