Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: tools/callstats.py

Issue 2464053005: Revert of [tools] Support custom script injection for callstats.py (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 def stop_replay_server(server): 78 def stop_replay_server(server):
79 print("SHUTTING DOWN REPLAY SERVER %s" % server['process'].pid) 79 print("SHUTTING DOWN REPLAY SERVER %s" % server['process'].pid)
80 server['process'].terminate() 80 server['process'].terminate()
81 os.remove(server['injection']) 81 os.remove(server['injection'])
82 82
83 83
84 def generate_injection(f, sites, refreshes=0): 84 def generate_injection(f, sites, refreshes=0):
85 print >> f, """\ 85 print >> f, """\
86 (function() { 86 (function() {
87 var sites =
88 """, json.dumps(sites), """;
89 var s = window.sessionStorage.getItem("refreshCounter"); 87 var s = window.sessionStorage.getItem("refreshCounter");
90 var refreshTotal = """, refreshes, """; 88 var refreshTotal = """, refreshes, """;
91 var refreshCounter = s ? parseInt(s) : refreshTotal; 89 var refreshCounter = s ? parseInt(s) : refreshTotal;
92 var refreshId = refreshTotal - refreshCounter; 90 var refreshId = refreshTotal - refreshCounter;
93 if (refreshCounter > 0) { 91 if (refreshCounter > 0) {
94 window.sessionStorage.setItem("refreshCounter", refreshCounter-1); 92 window.sessionStorage.setItem("refreshCounter", refreshCounter-1);
95 } 93 }
96 function match(url, item) { 94 function match(url, item) {
97 if ('regexp' in item) { return url.match(item.regexp) !== null }; 95 if ('regexp' in item) { return url.match(item.regexp) !== null };
98 var url_wanted = item.url; 96 var url_wanted = item.url;
99 /* Allow automatic redirections from http to https. */ 97 /* Allow automatic redirections from http to https. */
100 if (url_wanted.startsWith("http://") && url.startsWith("https://")) { 98 if (url_wanted.startsWith("http://") && url.startsWith("https://")) {
101 url_wanted = "https://" + url_wanted.substr(7); 99 url_wanted = "https://" + url_wanted.substr(7);
102 } 100 }
103 return url.startsWith(url_wanted); 101 return url.startsWith(url_wanted);
104 } 102 };
105 function runCustomScript(site) {
106 if (site.script === undefined) return;
107 /* Combine a script from the given array. */
108 if (typeof site.script !== "string") {
109 site.script = site.script.join(' ');
110 }
111 eval(site.script);
112 }
113 function onLoad(url) { 103 function onLoad(url) {
114 for (var item of sites) { 104 for (var item of sites) {
115 if (!match(url, item)) continue; 105 if (!match(url, item)) continue;
116 var timeout = 'timeline' in item ? 2000 * item.timeline 106 var timeout = 'timeline' in item ? 2000 * item.timeline
117 : 'timeout' in item ? 1000 * (item.timeout - 3) 107 : 'timeout' in item ? 1000 * (item.timeout - 3)
118 : 10000; 108 : 10000;
119 console.log("Setting time out of " + timeout + " for: " + url); 109 console.log("Setting time out of " + timeout + " for: " + url);
120 window.setTimeout(function() { 110 window.setTimeout(function() {
121 console.log("Time is out for: " + url); 111 console.log("Time is out for: " + url);
122 var msg = "STATS: (" + refreshId + ") " + url; 112 var msg = "STATS: (" + refreshId + ") " + url;
123 %GetAndResetRuntimeCallStats(1, msg); 113 %GetAndResetRuntimeCallStats(1, msg);
124 if (refreshCounter > 0) { 114 if (refreshCounter > 0) {
125 console.log( 115 console.log(
126 "Refresh counter is " + refreshCounter + ", refreshing: " + url); 116 "Refresh counter is " + refreshCounter + ", refreshing: " + url);
127 window.location.reload(); 117 window.location.reload();
128 } 118 }
129 }, timeout); 119 }, timeout);
130 runCustomScript(item);
131 return; 120 return;
132 } 121 }
133 console.log("Ignoring: " + url); 122 console.log("Ignoring: " + url);
134 }; 123 };
135 /* Avoid re-triggering the runtime stats for html imports */ 124 var sites =
136 if (document.currentScript.ownerDocument === document) { 125 """, json.dumps(sites), """;
137 onLoad(window.location.href); 126 onLoad(window.location.href);
138 }
139 })();""" 127 })();"""
140 128
141 def get_chrome_flags(js_flags, user_data_dir): 129 def get_chrome_flags(js_flags, user_data_dir):
142 return [ 130 return [
143 "--no-default-browser-check", 131 "--no-default-browser-check",
144 "--no-sandbox", 132 "--no-sandbox",
145 "--disable-translate", 133 "--disable-translate",
146 "--enable-benchmarking", 134 "--enable-benchmarking",
147 "--js-flags={}".format(js_flags), 135 "--js-flags={}".format(js_flags),
148 "--no-first-run", 136 "--no-first-run",
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 args.error("use either option --sites-file or site URLs") 680 args.error("use either option --sites-file or site URLs")
693 sys.exit(1) 681 sys.exit(1)
694 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):
695 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")
696 sys.exit(1) 684 sys.exit(1)
697 else: 685 else:
698 args.func(args) 686 args.func(args)
699 687
700 if __name__ == "__main__": 688 if __name__ == "__main__":
701 sys.exit(main()) 689 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698