OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 the V8 project authors. All rights reserved. | 2 # Copyright 2016 the V8 project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 ''' | 5 ''' |
6 Usage: callstats.py [-h] <command> ... | 6 Usage: callstats.py [-h] <command> ... |
7 | 7 |
8 Optional arguments: | 8 Optional arguments: |
9 -h, --help show this help message and exit | 9 -h, --help show this help message and exit |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 def fix_for_printing(arg): | 39 def fix_for_printing(arg): |
40 m = re.match(r'^--([^=]+)=(.*)$', arg) | 40 m = re.match(r'^--([^=]+)=(.*)$', arg) |
41 if m and (' ' in m.group(2) or m.group(2).startswith('-')): | 41 if m and (' ' in m.group(2) or m.group(2).startswith('-')): |
42 arg = "--{}='{}'".format(m.group(1), m.group(2)) | 42 arg = "--{}='{}'".format(m.group(1), m.group(2)) |
43 elif ' ' in arg: | 43 elif ' ' in arg: |
44 arg = "'{}'".format(arg) | 44 arg = "'{}'".format(arg) |
45 return arg | 45 return arg |
46 print " ".join(map(fix_for_printing, cmd_args)) | 46 print " ".join(map(fix_for_printing, cmd_args)) |
47 | 47 |
48 | 48 |
49 def start_replay_server(args, sites): | 49 def start_replay_server(args, sites, discard_output=True): |
50 with tempfile.NamedTemporaryFile(prefix='callstats-inject-', suffix='.js', | 50 with tempfile.NamedTemporaryFile(prefix='callstats-inject-', suffix='.js', |
51 mode='wt', delete=False) as f: | 51 mode='wt', delete=False) as f: |
52 injection = f.name | 52 injection = f.name |
53 generate_injection(f, sites, args.refresh) | 53 generate_injection(f, sites, args.refresh) |
54 http_port = 4080 + args.port_offset | 54 http_port = 4080 + args.port_offset |
55 https_port = 4443 + args.port_offset | 55 https_port = 4443 + args.port_offset |
56 cmd_args = [ | 56 cmd_args = [ |
57 args.replay_bin, | 57 args.replay_bin, |
58 "--port=%s" % http_port, | 58 "--port=%s" % http_port, |
59 "--ssl_port=%s" % https_port, | 59 "--ssl_port=%s" % https_port, |
60 "--no-dns_forwarding", | 60 "--no-dns_forwarding", |
61 "--use_closest_match", | 61 "--use_closest_match", |
62 "--no-diff_unknown_requests", | 62 "--no-diff_unknown_requests", |
63 "--inject_scripts=deterministic.js,{}".format(injection), | 63 "--inject_scripts=deterministic.js,{}".format(injection), |
64 args.replay_wpr, | 64 args.replay_wpr, |
65 ] | 65 ] |
66 print "=" * 80 | 66 print "=" * 80 |
67 print_command(cmd_args) | 67 print_command(cmd_args) |
68 with open(os.devnull, 'w') as null: | 68 if discard_output: |
69 server = subprocess.Popen(cmd_args, stdout=null, stderr=null) | 69 with open(os.devnull, 'w') as null: |
| 70 server = subprocess.Popen(cmd_args, stdout=null, stderr=null) |
| 71 else: |
| 72 server = subprocess.Popen(cmd_args) |
70 print "RUNNING REPLAY SERVER: %s with PID=%s" % (args.replay_bin, server.pid) | 73 print "RUNNING REPLAY SERVER: %s with PID=%s" % (args.replay_bin, server.pid) |
71 print "=" * 80 | 74 print "=" * 80 |
72 return {'process': server, 'injection': injection} | 75 return {'process': server, 'injection': injection} |
73 | 76 |
74 | 77 |
75 def stop_replay_server(server): | 78 def stop_replay_server(server): |
76 print("SHUTTING DOWN REPLAY SERVER %s" % server['process'].pid) | 79 print("SHUTTING DOWN REPLAY SERVER %s" % server['process'].pid) |
77 server['process'].terminate() | 80 server['process'].terminate() |
78 os.remove(server['injection']) | 81 os.remove(server['injection']) |
79 | 82 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 288 |
286 | 289 |
287 def do_run_replay_server(args): | 290 def do_run_replay_server(args): |
288 sites = read_sites(args) | 291 sites = read_sites(args) |
289 print("- " * 40) | 292 print("- " * 40) |
290 print("Available URLs:") | 293 print("Available URLs:") |
291 for site in sites: | 294 for site in sites: |
292 print(" "+site['url']) | 295 print(" "+site['url']) |
293 print("- " * 40) | 296 print("- " * 40) |
294 print("Launch chromium with the following commands for debugging:") | 297 print("Launch chromium with the following commands for debugging:") |
295 flags = get_chrome_flags("'--runtime-calls-stats --allow-natives-syntax'", | 298 flags = get_chrome_flags("'--runtime-call-stats --allow-natives-syntax'", |
296 "/var/tmp/`date +%s`") | 299 "/var/tmp/`date +%s`") |
297 flags += get_chrome_replay_flags(args) | 300 flags += get_chrome_replay_flags(args) |
298 print(" $CHROMIUM_DIR/out/Release/chomium " + (" ".join(flags)) + " <URL>") | 301 print(" $CHROMIUM_DIR/out/Release/chomium " + (" ".join(flags)) + " <URL>") |
299 print("- " * 40) | 302 print("- " * 40) |
300 replay_server = start_replay_server(args, sites) | 303 replay_server = start_replay_server(args, sites, discard_output=False) |
301 try: | 304 try: |
302 replay_server['process'].wait() | 305 replay_server['process'].wait() |
303 finally: | 306 finally: |
304 stop_replay_server(replay_server) | 307 stop_replay_server(replay_server) |
305 | 308 |
306 | 309 |
307 # Calculate statistics. | 310 # Calculate statistics. |
308 | 311 |
309 def statistics(data): | 312 def statistics(data): |
310 N = len(data) | 313 N = len(data) |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 args.error("use either option --sites-file or site URLs") | 680 args.error("use either option --sites-file or site URLs") |
678 sys.exit(1) | 681 sys.exit(1) |
679 elif args.command == "run" and not coexist(args.replay_wpr, args.replay_bin): | 682 elif args.command == "run" and not coexist(args.replay_wpr, args.replay_bin): |
680 args.error("options --replay-wpr and --replay-bin must be used together") | 683 args.error("options --replay-wpr and --replay-bin must be used together") |
681 sys.exit(1) | 684 sys.exit(1) |
682 else: | 685 else: |
683 args.func(args) | 686 args.func(args) |
684 | 687 |
685 if __name__ == "__main__": | 688 if __name__ == "__main__": |
686 sys.exit(main()) | 689 sys.exit(main()) |
OLD | NEW |