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

Side by Side Diff: tools/plot-timer-events.js

Issue 11412125: Add parallel recompilation time to histogram and plot execution pause times. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: moar timers Created 8 years 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
OLDNEW
(Empty)
1 // Copyright 2012 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 kExecutionName = 'V8.ScriptRun';
29
30 var TimerEvents = {
31 'V8.ScriptRun' :
Jakob Kummerow 2012/11/22 10:56:08 nit: free-floating colons look weird. I'd remove t
Yang 2012/11/22 13:04:20 Done.
32 { ranges: [], color: "#444444", pause: false, index: 1 },
33 'V8.Compile' :
34 { ranges: [], color: "#CC0000", pause: true, index: 2 },
35 'V8.CompileLazy' :
36 { ranges: [], color: "#CC4400", pause: true, index: 3 },
37 'V8.CompileEval' :
38 { ranges: [], color: "#CC0044", pause: true, index: 4 },
39 'V8.CompileFullCode':
40 { ranges: [], color: "#CC44CC", pause: true, index: 5 },
41 'V8.RecompileSynchronous':
42 { ranges: [], color: "#AA44EE", pause: true, index: 6 },
43 'V8.RecompileParallel':
44 { ranges: [], color: "#EE44AA", pause: false, index: 7 },
45 'V8.Parse' :
46 { ranges: [], color: "#00CC00", pause: true, index: 8 },
47 'V8.PreParse' :
48 { ranges: [], color: "#44CC00", pause: true, index: 9 },
49 'V8.ParseLazy' :
50 { ranges: [], color: "#00CC44", pause: true, index: 10 },
51 'V8.GCScavenger' :
52 { ranges: [], color: "#0044CC", pause: true, index: 11 },
53 'V8.GCCompactor' :
54 { ranges: [], color: "#4444CC", pause: true, index: 12 },
55 'V8.GCContext' :
56 { ranges: [], color: "#4400CC", pause: true, index: 13 },
57 }
58
59 var kNumRows = 13;
60 var kBarWidth = 0.33;
61 var kPauseTolerance = 0.05; // Milliseconds.
62 var kY1Offset = 3;
63 var kY2Factor = 5;
64 var kResX = 1600;
65 var kResY = 600;
66 var kLabelPadding = 5;
67 var kNumPauseLabels = 7;
68
69 var kOverrideRangeStart = undefined;
70 var kOverrideRangeEnd = undefined;
71
72 var xrange_start = Infinity;
73 var xrange_end = 0;
74 var obj_index = 0;
75 var execution_pauses = [];
76
Jakob Kummerow 2012/11/22 10:56:08 nit: two empty lines between top-level statements.
Yang 2012/11/22 13:04:20 Done.
77 function Range(start, end) {
78 // Everthing from here are in milliseconds.
79 this.start = start;
80 this.end = end;
81 }
82
83 Range.prototype.duration = function() { return this.end - this.start; }
84
85
86 function ProcessTimerEvent(name, start, length) {
87 var event = TimerEvents[name];
88 if (event === undefined) return;
89 start /= 1000; // Convert to milliseconds.
90 length /= 1000;
91 var end = start + length;
92 event.ranges.push(new Range(start, end));
93 if (name == kExecutionName) {
94 if (start < xrange_start) xrange_start = start;
95 if (end > xrange_end) xrange_end = end;
96 }
97 }
98
99
100 function CollectData() {
101 // Collect data from log.
102 var logreader = new LogReader(
103 { 'timer-event' : { parsers: [null, parseInt, parseInt],
104 processor: ProcessTimerEvent
105 } });
106
107 var line;
108 while (line = readline()) {
109 logreader.processLogLine(line);
110 }
111
112 // Collect execution pauses.
113 for (name in TimerEvents) {
114 var event = TimerEvents[name];
115 if (!event.pause) continue;
116 var ranges = event.ranges;
117 // Add ranges of this event to the pause list.
118 for (var j = 0; j < ranges.length; j++) {
119 execution_pauses.push(ranges[j]);
120 }
121 }
122 }
123
124
125 function drawBar(row, color, start, end) {
126 obj_index++;
127 command = "set object " + obj_index + " rect";
128 command += " from " + start + ", " + (row - kBarWidth + kY1Offset);
129 command += " to " + end + ", " + (row + kBarWidth + kY1Offset);
130 command += " fc rgb \"" + color + "\"";
131 print(command);
132 }
133
134
135 function MergeRanges(ranges, merge_tolerance) {
136 ranges.sort(function(a, b) { return a.start - b.start; });
137 var result = [];
138 var j = 0;
139 for (var i = 0; i < ranges.length; i = j) {
140 var merge_start = ranges[i].start;
141 if (merge_start > xrange_end) break; // Out of plot range.
142 var merge_end = ranges[i].end;
143 for (j = i + 1; j < ranges.length; j++) {
144 var next_range = ranges[j];
145 // Don't merge ranges if there is no overlap (including merge tolerance).
146 if (next_range.start >= merge_end + kPauseTolerance) break;
147 // Merge ranges.
148 if ((next_range.end > merge_end)) { // Extend range end.
Jakob Kummerow 2012/11/22 10:56:08 nit: duplicate parentheses
Yang 2012/11/22 13:04:20 Done.
149 merge_end = next_range.end;
150 }
151 }
152 if (merge_end < xrange_start) continue; // Out of plot range.
153 result.push(new Range(merge_start, merge_end));
154 }
155 return result;
156 }
157
158
159 function ExcludeRanges(include, exclude) {
160 // We assume that both input lists are sorted and merged with MergeRanges.
161 var result = [];
162 var exclude_index = 0;
163 var include_index = 0;
164 var include_start, include_end, exclude_start, exclude_end;
165
166 function NextInclude() {
167 if (include_index >= include.length) return false;
168 include_start = include[include_index].start;
169 include_end = include[include_index].end;
170 include_index++;
171 return true;
172 }
173
174 function NextExclude() {
175 if (exclude_index >= exclude.length) {
176 // No more exclude, finish by repeating case (2).
177 exclude_start = Infinity;
178 exclude_end = Infinity;
179 return false;
180 }
181 exclude_start = exclude[exclude_index].start;
182 exclude_end = exclude[exclude_index].end;
183 exclude_index++;
184 return true;
185 }
186
187 if (!NextInclude() || !NextExclude()) return include;
188
189 while (true) {
190 if (exclude_end <= include_start) {
191 // (1) Exclude and include do not overlap.
192 // Include #####
193 // Exclude ##
194 NextExclude();
195 } else if (include_end <= exclude_start) {
196 // (2) Exclude and include do not overlap.
197 // Include #####
198 // Exclude ###
199 result.push(new Range(include_start, include_end));
200 if (!NextInclude()) break;
201 } else if (exclude_start <= include_start &&
202 exclude_end < include_end &&
203 include_start < exclude_end) {
204 // (3) Exclude overlaps with begin of include.
205 // Include #######
206 // Exclude #####
207 // Result ####
208 include_start = exclude_start;
Jakob Kummerow 2012/11/22 10:56:08 s/exclude_start/exclude_end/, I think
Yang 2012/11/22 13:04:20 Nice catch. Thanks.
209 NextExclude();
210 } else if (include_start < exclude_start &&
211 include_end <= exclude_end &&
212 exclude_start < include_end) {
213 // (4) Exclude overlaps with end of include.
214 // Include #######
215 // Exclude #####
216 // Result ####
217 result.push(new Range(include_start, exclude_start));
218 if (!NextInclude()) break;
219 } else if (exclude_start > include_start && exclude_end < include_end) {
220 // (5) Exclude splits include into two parts.
221 // Include #######
222 // Exclude ##
223 // Result ## ###
224 result.push(new Range(include_start, exclude_start));
225 include_start = exclude_end;
226 NextExclude();
227 } else if (exclude_start <= include_start && exclude_end >= include_end) {
228 // (6) Exclude entirely covers include.
229 // Include ######
230 // Exclude #########
231 if (!NextInclude()) break;
232 } else {
233 throw new Error("this should not happen!");
234 }
235 }
236
237 return result;
238 }
239
240
241 function GnuplotOutput() {
242 xrange_start = kOverrideRangeStart ? kOverrideRangeStart : xrange_start;
243 xrange_end = kOverrideRangeEnd ? kOverrideRangeEnd : xrange_end;
244
245 print("set terminal pngcairo size " + kResX + "," + kResY +
246 " enhanced font 'Helvetica,10'");
247 print("set yrange [0:" + (kNumRows + kY1Offset + 1) + "]");
248 print("set xlabel \"execution time in ms\"");
249 print("set xrange [" + xrange_start + ":" + xrange_end + "]");
250 print("set style fill pattern 2 bo 1");
251 print("set style rect fs solid 1 noborder");
252 print("set style line 1 lt 1 lw 1 lc rgb \"#000000\"");
253 print("set xtics out nomirror");
254 print("unset key");
255
256 // Name Y-axis.
257 var ytics = [];
258 for (name in TimerEvents) {
259 var index = TimerEvents[name].index;
260 ytics.push('"' + name + '"' + ' ' + (index + kY1Offset));
261 }
262 print("set ytics out nomirror (" + ytics.join(', ') + ")");
263
264 // Smallest visible gap given our resolution.
265 // We remove superfluous objects to go easy on Gnuplot.
266 var tolerance = (xrange_end - xrange_start) / kResX / 2;
267
268 // Sort, merge and remove invisible gaps for each time row.
269 for (var name in TimerEvents) {
270 var event = TimerEvents[name];
271 event.ranges = MergeRanges(event.ranges, tolerance);
272 }
273
274 // Knock out execution pauses.
275 var execution_event = TimerEvents[kExecutionName];
276 var exclude_ranges = MergeRanges(execution_pauses, tolerance);
277 execution_event.ranges = ExcludeRanges(execution_event.ranges,
278 exclude_ranges);
279 execution_event.ranges = MergeRanges(execution_event.ranges, tolerance);
280
281 // Plot timeline.
282 for (var name in TimerEvents) {
283 var event = TimerEvents[name];
284 var ranges = event.ranges;
285 for (var i = 0; i < ranges.length; i++) {
286 drawBar(event.index, event.color, ranges[i].start, ranges[i].end);
287 }
288 }
289
290 if (execution_pauses.length == 0) {
291 // Force plot and return without plotting execution pause impulses.
292 print("plot 1/0");
293 return;
294 }
295
296 // Plot execution pauses as impulses. This may be better resolved
297 // due to possibly smaller merge tolerance.
298 if (tolerance > kPauseTolerance) {
299 execution_pauses = MergeRanges(execution_pauses, kPauseTolerance);
300 } else {
301 execution_pauses = exclude_ranges;
302 }
303
304 // Label the longest pauses.
305 execution_pauses.sort(
306 function(a, b) { return b.duration() - a.duration(); });
307
308 var max_pause_time = execution_pauses[0].duration();
309 var padding = kLabelPadding * (xrange_end - xrange_start) / kResX;
310 var y_scale = kY1Offset / max_pause_time;
311 for (var i = 0; i < execution_pauses.length && i < kNumPauseLabels; i++) {
312 var pause = execution_pauses[i];
313 var label_content = (pause.duration() | 0) + " ms";
314 var label_x = pause.end + padding;
315 var label_y = Math.max(1, (pause.duration() * y_scale));
316 print("set label \"" + label_content + "\" at " +
317 label_x + "," + label_y + " font \"Helvetica,7'\"");
318 }
319
320 // Scale second Y-axis appropriately.
321 print("set y2range [0:" + (max_pause_time * kY2Factor) + "]");
322
323 // Plot graph with impulses as data set.
324 print("plot '-' using 1:2 axes x1y2 with impulses ls 1");
325 for (var i = 0; i < execution_pauses.length; i++) {
326 var pause = execution_pauses[i];
327 print(pause.end + " " + pause.duration());
328 }
329 print("e");
330 }
331
332 CollectData();
333 GnuplotOutput();
334
OLDNEW
« src/log.h ('K') | « tools/plot-timer-events ('k') | tools/tickprocessor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698