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

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

Issue 11348298: Take instrumentation overhead into account when plotting. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « tools/plot-timer-events ('k') | 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 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 var kPauseTolerance = 0.1; // Milliseconds. 36 var kPauseTolerance = 0.1; // Milliseconds.
37 var kY1Offset = 10; 37 var kY1Offset = 10;
38 38
39 var kResX = 1600; 39 var kResX = 1600;
40 var kResY = 600; 40 var kResY = 600;
41 var kPauseLabelPadding = 5; 41 var kPauseLabelPadding = 5;
42 var kNumPauseLabels = 7; 42 var kNumPauseLabels = 7;
43 var kTickHalfDuration = 0.5; // Milliseconds 43 var kTickHalfDuration = 0.5; // Milliseconds
44 var kCodeKindLabelPadding = 100; 44 var kCodeKindLabelPadding = 100;
45 45
46 var kOverrideRangeStart = undefined;
47 var kOverrideRangeEnd = undefined;
48
49 var num_timer_event = kY1Offset + 0.5; 46 var num_timer_event = kY1Offset + 0.5;
50 47
51 48
52 function TimerEvent(color, pause, no_execution) { 49 function TimerEvent(color, pause, no_execution) {
53 this.color = color; 50 this.color = color;
54 this.pause = pause; 51 this.pause = pause;
55 this.ranges = []; 52 this.ranges = [];
56 this.no_execution = no_execution; 53 this.no_execution = no_execution;
57 this.index = ++num_timer_event; 54 this.index = ++num_timer_event;
58 } 55 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 'inl.cache': new CodeKind("#4444AA", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]), 93 'inl.cache': new CodeKind("#4444AA", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]),
97 } 94 }
98 95
99 96
100 var xrange_start = Infinity; 97 var xrange_start = Infinity;
101 var xrange_end = 0; 98 var xrange_end = 0;
102 var obj_index = 0; 99 var obj_index = 0;
103 var execution_pauses = []; 100 var execution_pauses = [];
104 var code_map = new CodeMap(); 101 var code_map = new CodeMap();
105 102
103 var xrange_start_override = undefined;
104 var xrange_end_override = undefined;
105 var distortion_per_entry = 0.005; // Milliseconds
106
107 var sort_by_start = [];
108 var sort_by_end = [];
109 var sorted_ticks = [];
110
106 111
107 function Range(start, end) { 112 function Range(start, end) {
108 // Everthing from here are in milliseconds. 113 // Everthing from here are in milliseconds.
109 this.start = start; 114 this.start = start;
110 this.end = end; 115 this.end = end;
111 } 116 }
112 117
113 118
119 function Tick(tick) {
120 this.tick = tick;
121 }
122
123
114 Range.prototype.duration = function() { return this.end - this.start; } 124 Range.prototype.duration = function() { return this.end - this.start; }
115 125
116 126
117 function ProcessTimerEvent(name, start, length) { 127 function ProcessTimerEvent(name, start, length) {
118 var event = TimerEvents[name]; 128 var event = TimerEvents[name];
119 if (event === undefined) return; 129 if (event === undefined) return;
120 start /= 1000; // Convert to milliseconds. 130 start /= 1000; // Convert to milliseconds.
121 length /= 1000; 131 length /= 1000;
122 var end = start + length; 132 var end = start + length;
123 event.ranges.push(new Range(start, end)); 133 var range = new Range(start, end);
124 if (event == kExecutionEvent) { 134 event.ranges.push(range);
125 if (start < xrange_start) xrange_start = start; 135 sort_by_start.push(range);
126 if (end > xrange_end) xrange_end = end; 136 sort_by_end.push(range);
127 }
128 } 137 }
129 138
130 139
131 function ProcessCodeCreateEvent(type, kind, address, size, name) { 140 function ProcessCodeCreateEvent(type, kind, address, size, name) {
132 var code_entry = new CodeMap.CodeEntry(size, name); 141 var code_entry = new CodeMap.CodeEntry(size, name);
133 code_entry.kind = kind; 142 code_entry.kind = kind;
134 code_map.addCode(address, code_entry); 143 code_map.addCode(address, code_entry);
135 } 144 }
136 145
137 146
(...skipping 25 matching lines...) Expand all
163 for (name in CodeKinds) { 172 for (name in CodeKinds) {
164 if (CodeKinds[name].kinds.indexOf(kind) >= 0) { 173 if (CodeKinds[name].kinds.indexOf(kind) >= 0) {
165 return CodeKinds[name]; 174 return CodeKinds[name];
166 } 175 }
167 } 176 }
168 } 177 }
169 178
170 179
171 function ProcessTickEvent(pc, sp, timer, unused_x, unused_y, vmstate, stack) { 180 function ProcessTickEvent(pc, sp, timer, unused_x, unused_y, vmstate, stack) {
172 timer /= 1000; 181 timer /= 1000;
173 var tick = new Range(timer - kTickHalfDuration, timer + kTickHalfDuration); 182 var tick = new Tick(timer);
174 183
184 var entered = false;
175 var entry = code_map.findEntry(pc); 185 var entry = code_map.findEntry(pc);
176 if (entry) { 186 if (entry) {
177 FindCodeKind(entry.kind).in_execution.push(tick); 187 FindCodeKind(entry.kind).in_execution.push(tick);
188 entered = true;
178 } 189 }
179 190
180 for (var i = 0; i < kStackFrames; i++) { 191 for (var i = 0; i < kStackFrames; i++) {
181 if (!stack[i]) break; 192 if (!stack[i]) break;
182 var entry = code_map.findEntry(stack[i]); 193 var entry = code_map.findEntry(stack[i]);
183 if (entry) { 194 if (entry) {
184 FindCodeKind(entry.kind).stack_frames[i].push(tick); 195 FindCodeKind(entry.kind).stack_frames[i].push(tick);
196 entered = true;
197 }
198 }
199
200 if (entered) sorted_ticks.push(tick);
201 }
202
203
204 function ProcessDistortion(distortion_in_picoseconds) {
205 distortion_per_entry = distortion_in_picoseconds / 1000000;
206 }
207
208
209 function ProcessPlotRange(start, end) {
210 xrange_start_override = start;
211 xrange_end_override = end;
212 }
213
214
215 function Undistort() {
216 // Undistort timers wrt instrumentation overhead.
217 sort_by_start.sort(function(a, b) { return b.start - a.start; });
218 sort_by_end.sort(function(a, b) { return b.end - a.end; });
219 sorted_ticks.sort(function(a, b) { return b.tick - a.tick; });
220 var distortion = 0;
221
222 var next_start = sort_by_start.pop();
223 var next_end = sort_by_end.pop();
224 var next_start_start = next_start ? next_start.start : Infinity;
225 var next_end_end = next_end ? next_end.end : Infinity;
226 var next_tick = sorted_ticks.pop();
227
228 function UndistortTicksUntil(tick) {
229 while (next_tick) {
230 if (next_tick.tick > tick) return;
231 next_tick.tick -= distortion;
232 next_tick = sorted_ticks.pop();
233 }
234 }
235
236 while (true) {
237 var next_start_start = next_start ? next_start.start : Infinity;
Jakob Kummerow 2012/12/05 15:53:15 redeclaration
238 var next_end_end = next_end ? next_end.end : Infinity;
Jakob Kummerow 2012/12/05 15:53:15 redeclaration
239 if (!next_start && !next_end) {
240 UndistortTicksUntil(Infinity);
241 break;
242 }
243 if (next_start_start <= next_end_end) {
244 UndistortTicksUntil(next_start_start);
245 // Undistort the start time stamp.
246 next_start.start -= distortion;
247 next_start = sort_by_start.pop();
248 } else {
249 // Undistort the end time stamp. We completely attribute the overhead
250 // to the point when we stop and log the timer, so we increase the
251 // distortion only here. Still make sure that start < end.
252 UndistortTicksUntil(next_end_end);
253 distortion += distortion_per_entry;
254 next_end.end = Math.max(next_end.start, next_end.end - distortion);
255 next_end = sort_by_end.pop();
256 }
257 }
258
259 sort_by_start = undefined;
260 sort_by_end = undefined;
261 sorted_ticks = undefined;
262
263 // Make sure that start <= end applies for every range and find the largest
264 // and shortest range.
Jakob Kummerow 2012/12/05 15:53:15 I don't see us looking for the largest and shortes
265 for (name in TimerEvents) {
266 var ranges = TimerEvents[name].ranges;
267 for (var j = 0; j < ranges.length; j++) {
268 if (ranges[j].end < ranges[j].start) ranges[j].end = ranges[j].start;
185 } 269 }
186 } 270 }
187 } 271 }
188 272
189 273
190 function CollectData() { 274 function CollectData() {
191 // Collect data from log. 275 // Collect data from log.
192 var logreader = new LogReader( 276 var logreader = new LogReader(
193 { 'timer-event' : { parsers: [null, parseInt, parseInt], 277 { 'timer-event' : { parsers: [null, parseInt, parseInt],
194 processor: ProcessTimerEvent }, 278 processor: ProcessTimerEvent },
195 'shared-library': { parsers: [null, parseInt, parseInt], 279 'shared-library': { parsers: [null, parseInt, parseInt],
196 processor: ProcessSharedLibrary }, 280 processor: ProcessSharedLibrary },
197 'code-creation': { parsers: [null, parseInt, parseInt, parseInt, null], 281 'code-creation': { parsers: [null, parseInt, parseInt, parseInt, null],
198 processor: ProcessCodeCreateEvent }, 282 processor: ProcessCodeCreateEvent },
199 'code-move': { parsers: [parseInt, parseInt], 283 'code-move': { parsers: [parseInt, parseInt],
200 processor: ProcessCodeMoveEvent }, 284 processor: ProcessCodeMoveEvent },
201 'code-delete': { parsers: [parseInt], 285 'code-delete': { parsers: [parseInt],
202 processor: ProcessCodeDeleteEvent }, 286 processor: ProcessCodeDeleteEvent },
203 'tick': { parsers: [parseInt, parseInt, parseInt, 287 'tick': { parsers: [parseInt, parseInt, parseInt,
204 null, null, parseInt, 'var-args'], 288 null, null, parseInt, 'var-args'],
205 processor: ProcessTickEvent }, 289 processor: ProcessTickEvent },
290 'distortion': { parsers: [parseInt],
291 processor: ProcessDistortion },
292 'plot-range': { parsers: [parseInt, parseInt],
293 processor: ProcessPlotRange },
206 }); 294 });
207 295
208 var line; 296 var line;
209 while (line = readline()) { 297 while (line = readline()) {
210 logreader.processLogLine(line); 298 logreader.processLogLine(line);
211 } 299 }
212 300
301 Undistort();
302
303 // Figure out plot range.
304 var execution_ranges = kExecutionEvent.ranges;
305 for (var i = 0; i < execution_ranges.length; i++) {
306 if (execution_ranges[i].start < xrange_start) {
307 xrange_start = execution_ranges[i].start;
308 }
309 if (execution_ranges[i].end > xrange_end) {
310 xrange_end = execution_ranges[i].end;
311 }
312 }
313
213 // Collect execution pauses. 314 // Collect execution pauses.
214 for (name in TimerEvents) { 315 for (name in TimerEvents) {
215 var event = TimerEvents[name]; 316 var event = TimerEvents[name];
216 if (!event.pause) continue; 317 if (!event.pause) continue;
217 var ranges = event.ranges; 318 var ranges = event.ranges;
218 for (var j = 0; j < ranges.length; j++) execution_pauses.push(ranges[j]); 319 for (var j = 0; j < ranges.length; j++) execution_pauses.push(ranges[j]);
219 } 320 }
220 execution_pauses = MergeRanges(execution_pauses); 321 execution_pauses = MergeRanges(execution_pauses);
221 322
222 // Knock out time not spent in javascript execution. Note that this also 323 // Knock out time not spent in javascript execution. Note that this also
(...skipping 20 matching lines...) Expand all
243 function DrawBar(row, color, start, end, width) { 344 function DrawBar(row, color, start, end, width) {
244 obj_index++; 345 obj_index++;
245 command = "set object " + obj_index + " rect"; 346 command = "set object " + obj_index + " rect";
246 command += " from " + start + ", " + (row - width); 347 command += " from " + start + ", " + (row - width);
247 command += " to " + end + ", " + (row + width); 348 command += " to " + end + ", " + (row + width);
248 command += " fc rgb \"" + color + "\""; 349 command += " fc rgb \"" + color + "\"";
249 print(command); 350 print(command);
250 } 351 }
251 352
252 353
354 function TicksToRanges(ticks) {
355 var ranges = [];
356 for (var i = 0; i < ticks.length; i++) {
357 var tick = ticks[i].tick;
358 ranges.push(new Range(tick - kTickHalfDuration, tick + kTickHalfDuration));
359 }
360 return ranges;
361 }
362
363
253 function MergeRanges(ranges) { 364 function MergeRanges(ranges) {
254 ranges.sort(function(a, b) { return a.start - b.start; }); 365 ranges.sort(function(a, b) { return a.start - b.start; });
255 var result = []; 366 var result = [];
256 var j = 0; 367 var j = 0;
257 for (var i = 0; i < ranges.length; i = j) { 368 for (var i = 0; i < ranges.length; i = j) {
258 var merge_start = ranges[i].start; 369 var merge_start = ranges[i].start;
259 if (merge_start > xrange_end) break; // Out of plot range. 370 if (merge_start > xrange_end) break; // Out of plot range.
260 var merge_end = ranges[i].end; 371 var merge_end = ranges[i].end;
261 for (j = i + 1; j < ranges.length; j++) { 372 for (j = i + 1; j < ranges.length; j++) {
262 var next_range = ranges[j]; 373 var next_range = ranges[j];
263 // Don't merge ranges if there is no overlap (including merge tolerance). 374 // Don't merge ranges if there is no overlap (including merge tolerance).
264 if (next_range.start > merge_end + kPauseTolerance) break; 375 if (next_range.start > merge_end + kPauseTolerance) break;
265 // Merge ranges. 376 // Merge ranges.
266 if (next_range.end > merge_end) { // Extend range end. 377 if (next_range.end > merge_end) { // Extend range end.
267 merge_end = next_range.end; 378 merge_end = next_range.end;
268 } 379 }
269 } 380 }
270 if (merge_end < xrange_start) continue; // Out of plot range. 381 if (merge_end < xrange_start) continue; // Out of plot range.
382 if (merge_end < merge_start) continue; // Not an actual range.
271 result.push(new Range(merge_start, merge_end)); 383 result.push(new Range(merge_start, merge_end));
272 } 384 }
273 return result; 385 return result;
274 } 386 }
275 387
276 388
277 function ExcludeRanges(include, exclude) { 389 function ExcludeRanges(include, exclude) {
278 // We assume that both input lists are sorted and merged with MergeRanges. 390 // We assume that both input lists are sorted and merged with MergeRanges.
279 var result = []; 391 var result = [];
280 var exclude_index = 0; 392 var exclude_index = 0;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } else { 462 } else {
351 throw new Error("this should not happen!"); 463 throw new Error("this should not happen!");
352 } 464 }
353 } 465 }
354 466
355 return result; 467 return result;
356 } 468 }
357 469
358 470
359 function GnuplotOutput() { 471 function GnuplotOutput() {
360 xrange_start = kOverrideRangeStart ? kOverrideRangeStart : xrange_start; 472 xrange_start = (xrange_start_override || xrange_start_override == 0)
361 xrange_end = kOverrideRangeEnd ? kOverrideRangeEnd : xrange_end; 473 ? xrange_start_override : xrange_start;
474 xrange_end = (xrange_end_override || xrange_end_override == 0)
475 ? xrange_end_override : xrange_end;
362 print("set terminal pngcairo size " + kResX + "," + kResY + 476 print("set terminal pngcairo size " + kResX + "," + kResY +
363 " enhanced font 'Helvetica,10'"); 477 " enhanced font 'Helvetica,10'");
364 print("set yrange [0:" + (num_timer_event + 1) + "]"); 478 print("set yrange [0:" + (num_timer_event + 1) + "]");
365 print("set xlabel \"execution time in ms\""); 479 print("set xlabel \"execution time in ms\"");
366 print("set xrange [" + xrange_start + ":" + xrange_end + "]"); 480 print("set xrange [" + xrange_start + ":" + xrange_end + "]");
367 print("set style fill pattern 2 bo 1"); 481 print("set style fill pattern 2 bo 1");
368 print("set style rect fs solid 1 noborder"); 482 print("set style rect fs solid 1 noborder");
369 print("set style line 1 lt 1 lw 1 lc rgb \"#000000\""); 483 print("set style line 1 lt 1 lw 1 lc rgb \"#000000\"");
370 print("set xtics out nomirror"); 484 print("set xtics out nomirror");
371 print("unset key"); 485 print("unset key");
(...skipping 19 matching lines...) Expand all
391 ranges[i].start, ranges[i].end, 505 ranges[i].start, ranges[i].end,
392 kTimerEventWidth); 506 kTimerEventWidth);
393 } 507 }
394 } 508 }
395 509
396 // Plot code kind gathered from ticks. 510 // Plot code kind gathered from ticks.
397 for (var name in CodeKinds) { 511 for (var name in CodeKinds) {
398 var code_kind = CodeKinds[name]; 512 var code_kind = CodeKinds[name];
399 var offset = kY1Offset - 1; 513 var offset = kY1Offset - 1;
400 // Top most frame. 514 // Top most frame.
401 var row = MergeRanges(code_kind.in_execution); 515 var row = MergeRanges(TicksToRanges(code_kind.in_execution));
402 for (var j = 0; j < row.length; j++) { 516 for (var j = 0; j < row.length; j++) {
403 DrawBar(offset, code_kind.color, 517 DrawBar(offset, code_kind.color,
404 row[j].start, row[j].end, kExecutionFrameWidth); 518 row[j].start, row[j].end, kExecutionFrameWidth);
405 } 519 }
406 offset = offset - 2 * kExecutionFrameWidth - kGapWidth; 520 offset = offset - 2 * kExecutionFrameWidth - kGapWidth;
407 // Javascript frames. 521 // Javascript frames.
408 for (var i = 0; i < kStackFrames; i++) { 522 for (var i = 0; i < kStackFrames; i++) {
409 offset = offset - 2 * kStackFrameWidth - kGapWidth; 523 offset = offset - 2 * kStackFrameWidth - kGapWidth;
410 row = MergeRanges(code_kind.stack_frames[i]); 524 row = MergeRanges(TicksToRanges(code_kind.stack_frames[i]));
411 for (var j = 0; j < row.length; j++) { 525 for (var j = 0; j < row.length; j++) {
412 DrawBar(offset, code_kind.color, 526 DrawBar(offset, code_kind.color,
413 row[j].start, row[j].end, kStackFrameWidth); 527 row[j].start, row[j].end, kStackFrameWidth);
414 } 528 }
415 } 529 }
416 } 530 }
417 531
418 // Add labels as legend for code kind colors. 532 // Add labels as legend for code kind colors.
419 var padding = kCodeKindLabelPadding * (xrange_end - xrange_start) / kResX; 533 var padding = kCodeKindLabelPadding * (xrange_end - xrange_start) / kResX;
420 var label_x = xrange_start; 534 var label_x = xrange_start;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 for (var i = 0; i < execution_pauses.length; i++) { 570 for (var i = 0; i < execution_pauses.length; i++) {
457 var pause = execution_pauses[i]; 571 var pause = execution_pauses[i];
458 print(pause.end + " " + pause.duration()); 572 print(pause.end + " " + pause.duration());
459 } 573 }
460 print("e"); 574 print("e");
461 } 575 }
462 576
463 577
464 CollectData(); 578 CollectData();
465 GnuplotOutput(); 579 GnuplotOutput();
OLDNEW
« no previous file with comments | « tools/plot-timer-events ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698