comparison contrib/catapipe.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents ff562d711919
children 6000f5b25c9b
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
51 51
52 # 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
53 # Python version and OS 53 # Python version and OS
54 timer = timeit.default_timer 54 timer = timeit.default_timer
55 55
56
56 def main(): 57 def main():
57 parser = argparse.ArgumentParser() 58 parser = argparse.ArgumentParser()
58 parser.add_argument('pipe', type=str, nargs=1, 59 parser.add_argument(
59 help='Path of named pipe to create and listen on.') 60 'pipe',
60 parser.add_argument('output', default='trace.json', type=str, nargs='?', 61 type=str,
61 help='Path of json file to create where the traces ' 62 nargs=1,
62 'will be stored.') 63 help='Path of named pipe to create and listen on.',
63 parser.add_argument('--debug', default=False, action='store_true', 64 )
64 help='Print useful debug messages') 65 parser.add_argument(
66 'output',
67 default='trace.json',
68 type=str,
69 nargs='?',
70 help='Path of json file to create where the traces ' 'will be stored.',
71 )
72 parser.add_argument(
73 '--debug',
74 default=False,
75 action='store_true',
76 help='Print useful debug messages',
77 )
65 args = parser.parse_args() 78 args = parser.parse_args()
66 fn = args.pipe[0] 79 fn = args.pipe[0]
67 os.mkfifo(fn) 80 os.mkfifo(fn)
68 try: 81 try:
69 with open(fn) as f, open(args.output, 'w') as out: 82 with open(fn) as f, open(args.output, 'w') as out:
84 payload_args = {'value': int(amount)} 97 payload_args = {'value': int(amount)}
85 else: 98 else:
86 payload_args = {} 99 payload_args = {}
87 pid = _threadmap[session] 100 pid = _threadmap[session]
88 ts_micros = (now - start) * 1000000 101 ts_micros = (now - start) * 1000000
89 out.write(json.dumps( 102 out.write(
90 { 103 json.dumps(
91 "name": label, 104 {
92 "cat": "misc", 105 "name": label,
93 "ph": _TYPEMAP[verb], 106 "cat": "misc",
94 "ts": ts_micros, 107 "ph": _TYPEMAP[verb],
95 "pid": pid, 108 "ts": ts_micros,
96 "tid": 1, 109 "pid": pid,
97 "args": payload_args, 110 "tid": 1,
98 })) 111 "args": payload_args,
112 }
113 )
114 )
99 out.write(',\n') 115 out.write(',\n')
100 finally: 116 finally:
101 os.unlink(fn) 117 os.unlink(fn)
102 118
119
103 if __name__ == '__main__': 120 if __name__ == '__main__':
104 main() 121 main()