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

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

Powered by Google App Engine
This is Rietveld 408576698