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

Side by Side Diff: tools/profviz/profviz.js

Issue 17592002: Add v8.log visualizer page. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: small changes Created 7 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « tools/profviz/profviz.html ('k') | tools/profviz/stdio.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 var worker_scripts = [
29 "../csvparser.js",
30 "../splaytree.js",
31 "../codemap.js",
32 "../profile.js",
33 "../profile_view.js",
34 "../logreader.js",
35 "../tickprocessor.js",
36 "composer.js",
37 "gnuplot-4.6.3-emscripten.js"
38 ];
39
40
41 function plotWorker() {
42 var worker = null;
43
44 var delegateList = {
45 "log" : log,
46 "error" : logError,
47 "display" : display,
48 "range" : setRange,
49 "script" : scriptLoaded
50 }
51
52 function initialize() {
53 ui.freeze();
54 worker = new Worker("worker.js");
55 running = false;
56
57 worker.postMessage({ "call" : "load scripts",
58 "args" : worker_scripts });
59
60 worker.addEventListener("message", function(event) {
61 var call = delegateList[event.data["call"]];
62 call(event.data["args"]);
63 });
64 }
65
66 function scriptLoaded() {
67 ui.thaw();
68 }
69
70 // Public methods.
71 this.run = function(filename,
72 resx, resy,
73 distortion,
74 range_start, range_end) {
75 var args = {
76 'file' : filename,
77 'resx' : resx,
78 'resy' : resy,
79 'distortion' : distortion,
80 'range_start' : range_start,
81 'range_end' : range_end
82 }
83 worker.postMessage({ 'call' : 'run', 'args' : args });
84 }
85
86 this.reset = function() {
87 if (worker) worker.terminate();
88 initialize();
89 }
90 }
91
92
93 function UIWrapper() {
94 var input_elements = ["range_start",
95 "range_end",
96 "distortion",
97 "start",
98 "file"];
99
100 this.log = document.getElementById("log");
101 this.plot = document.getElementById('plot');
102 for (var i in input_elements) {
103 var id = input_elements[i];
104 this[id] = document.getElementById(id);
105 }
106
107 this.freeze = function() {
108 this.plot.style.webkitFilter = "grayscale(1)";
109 for (var i in input_elements) {
110 this[input_elements[i]].disabled = true;
111 }
112 }
113
114 this.thaw = function() {
115 this.plot.style.webkitFilter = "";
116 for (var i in input_elements) {
117 this[input_elements[i]].disabled = false;
118 }
119 }
120
121 this.reset = function() {
122 this.thaw();
123 this.log.value = "";
124 this.range_start.value = "automatic";
125 this.range_end.value = "automatic";
126 }
127 }
128
129
130 function log(text) {
131 ui.log.value += text;
132 ui.log.scrollTop = ui.log.scrollHeight;
133 }
134
135
136 function logError(text) {
137 if (ui.log.value.length > 0 &&
138 ui.log.value[ui.log.value.length-1] != "\n") {
139 ui.log.value += "\n";
140 }
141 ui.log.value += "ERROR: " + text + "\n";
142 ui.log.scrollTop = ui.log.scrollHeight;
143 error_logged = true;
144 }
145
146
147 function display(args) {
148 if (error_logged) {
149 log("Plot failed.\n\n");
150 } else {
151 log("Displaying plot. Total time: " +
152 (Date.now() - timer) / 1000 + "ms.\n\n");
153 var blob = new Blob([new Uint8Array(args.contents).buffer],
154 { "type" : "image\/svg+xml" });
155 window.URL = window.URL || window.webkitURL;
156 ui.plot.src = window.URL.createObjectURL(blob);
157 }
158
159 ui.thaw();
160 }
161
162
163 function start(event) {
164 error_logged = false;
165 ui.freeze();
166
167 try {
168 var file = getSelectedFile();
169 var distortion = getDistortion();
170 var range = getRange();
171 } catch (e) {
172 logError(e.message);
173 display();
174 return;
175 }
176
177 timer = Date.now();
178 worker.run(file, kResX, kResY, distortion, range[0], range[1]);
179 }
180
181
182 function getSelectedFile() {
183 var file = ui.file.files[0];
184 if (!file) throw Error("No valid file selected.");
185 if (!file.type.toString().match(/text/)) {
186 throw Error("'" + escape(file.name) + "' is not a text file.");
187 }
188 return file;
189 }
190
191
192 function getDistortion() {
193 var input_distortion =
194 parseInt(ui.distortion.value, 10);
195 if (isNaN(input_distortion)) {
196 input_distortion = ui.distortion.value = 4500;
197 }
198 return input_distortion / 1000000;
199 }
200
201
202 function getRange() {
203 var input_start =
204 parseInt(ui.range_start.value, 10);
205 if (isNaN(input_start)) input_start = undefined;
206 var input_end =
207 parseInt(ui.range_end.value, 10);
208 if (isNaN(input_end)) input_end = undefined;
209 return [input_start, input_end];
210 }
211
212
213 function setRange(args) {
214 ui.range_start.value = args.start.toFixed(1);
215 ui.range_end.value = args.end.toFixed(1);
216 }
217
218
219 function onload() {
220 kResX = 1600;
221 kResY = 900;
222 error_logged = false;
223 ui = new UIWrapper();
224 ui.reset();
225 worker = new plotWorker();
226 worker.reset();
227 }
228
229
230 var kResX;
231 var kResY;
232 var error_logged;
233 var ui;
234 var worker;
235 var timer;
OLDNEW
« no previous file with comments | « tools/profviz/profviz.html ('k') | tools/profviz/stdio.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698