OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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_tick = sorted_ticks.pop(); |
| 225 |
| 226 function UndistortTicksUntil(tick) { |
| 227 while (next_tick) { |
| 228 if (next_tick.tick > tick) return; |
| 229 next_tick.tick -= distortion; |
| 230 next_tick = sorted_ticks.pop(); |
| 231 } |
| 232 } |
| 233 |
| 234 while (true) { |
| 235 var next_start_start = next_start ? next_start.start : Infinity; |
| 236 var next_end_end = next_end ? next_end.end : Infinity; |
| 237 if (!next_start && !next_end) { |
| 238 UndistortTicksUntil(Infinity); |
| 239 break; |
| 240 } |
| 241 if (next_start_start <= next_end_end) { |
| 242 UndistortTicksUntil(next_start_start); |
| 243 // Undistort the start time stamp. |
| 244 next_start.start -= distortion; |
| 245 next_start = sort_by_start.pop(); |
| 246 } else { |
| 247 // Undistort the end time stamp. We completely attribute the overhead |
| 248 // to the point when we stop and log the timer, so we increase the |
| 249 // distortion only here. |
| 250 UndistortTicksUntil(next_end_end); |
| 251 distortion += distortion_per_entry; |
| 252 next_end.end -= distortion; |
| 253 next_end = sort_by_end.pop(); |
| 254 } |
| 255 } |
| 256 |
| 257 sort_by_start = undefined; |
| 258 sort_by_end = undefined; |
| 259 sorted_ticks = undefined; |
| 260 |
| 261 // Make sure that start <= end applies for every range. |
| 262 for (name in TimerEvents) { |
| 263 var ranges = TimerEvents[name].ranges; |
| 264 for (var j = 0; j < ranges.length; j++) { |
| 265 if (ranges[j].end < ranges[j].start) ranges[j].end = ranges[j].start; |
185 } | 266 } |
186 } | 267 } |
187 } | 268 } |
188 | 269 |
189 | 270 |
190 function CollectData() { | 271 function CollectData() { |
191 // Collect data from log. | 272 // Collect data from log. |
192 var logreader = new LogReader( | 273 var logreader = new LogReader( |
193 { 'timer-event' : { parsers: [null, parseInt, parseInt], | 274 { 'timer-event' : { parsers: [null, parseInt, parseInt], |
194 processor: ProcessTimerEvent }, | 275 processor: ProcessTimerEvent }, |
195 'shared-library': { parsers: [null, parseInt, parseInt], | 276 'shared-library': { parsers: [null, parseInt, parseInt], |
196 processor: ProcessSharedLibrary }, | 277 processor: ProcessSharedLibrary }, |
197 'code-creation': { parsers: [null, parseInt, parseInt, parseInt, null], | 278 'code-creation': { parsers: [null, parseInt, parseInt, parseInt, null], |
198 processor: ProcessCodeCreateEvent }, | 279 processor: ProcessCodeCreateEvent }, |
199 'code-move': { parsers: [parseInt, parseInt], | 280 'code-move': { parsers: [parseInt, parseInt], |
200 processor: ProcessCodeMoveEvent }, | 281 processor: ProcessCodeMoveEvent }, |
201 'code-delete': { parsers: [parseInt], | 282 'code-delete': { parsers: [parseInt], |
202 processor: ProcessCodeDeleteEvent }, | 283 processor: ProcessCodeDeleteEvent }, |
203 'tick': { parsers: [parseInt, parseInt, parseInt, | 284 'tick': { parsers: [parseInt, parseInt, parseInt, |
204 null, null, parseInt, 'var-args'], | 285 null, null, parseInt, 'var-args'], |
205 processor: ProcessTickEvent }, | 286 processor: ProcessTickEvent }, |
| 287 'distortion': { parsers: [parseInt], |
| 288 processor: ProcessDistortion }, |
| 289 'plot-range': { parsers: [parseInt, parseInt], |
| 290 processor: ProcessPlotRange }, |
206 }); | 291 }); |
207 | 292 |
208 var line; | 293 var line; |
209 while (line = readline()) { | 294 while (line = readline()) { |
210 logreader.processLogLine(line); | 295 logreader.processLogLine(line); |
211 } | 296 } |
212 | 297 |
| 298 Undistort(); |
| 299 |
| 300 // Figure out plot range. |
| 301 var execution_ranges = kExecutionEvent.ranges; |
| 302 for (var i = 0; i < execution_ranges.length; i++) { |
| 303 if (execution_ranges[i].start < xrange_start) { |
| 304 xrange_start = execution_ranges[i].start; |
| 305 } |
| 306 if (execution_ranges[i].end > xrange_end) { |
| 307 xrange_end = execution_ranges[i].end; |
| 308 } |
| 309 } |
| 310 |
213 // Collect execution pauses. | 311 // Collect execution pauses. |
214 for (name in TimerEvents) { | 312 for (name in TimerEvents) { |
215 var event = TimerEvents[name]; | 313 var event = TimerEvents[name]; |
216 if (!event.pause) continue; | 314 if (!event.pause) continue; |
217 var ranges = event.ranges; | 315 var ranges = event.ranges; |
218 for (var j = 0; j < ranges.length; j++) execution_pauses.push(ranges[j]); | 316 for (var j = 0; j < ranges.length; j++) execution_pauses.push(ranges[j]); |
219 } | 317 } |
220 execution_pauses = MergeRanges(execution_pauses); | 318 execution_pauses = MergeRanges(execution_pauses); |
221 | 319 |
222 // Knock out time not spent in javascript execution. Note that this also | 320 // Knock out time not spent in javascript execution. Note that this also |
(...skipping 20 matching lines...) Expand all Loading... |
243 function DrawBar(row, color, start, end, width) { | 341 function DrawBar(row, color, start, end, width) { |
244 obj_index++; | 342 obj_index++; |
245 command = "set object " + obj_index + " rect"; | 343 command = "set object " + obj_index + " rect"; |
246 command += " from " + start + ", " + (row - width); | 344 command += " from " + start + ", " + (row - width); |
247 command += " to " + end + ", " + (row + width); | 345 command += " to " + end + ", " + (row + width); |
248 command += " fc rgb \"" + color + "\""; | 346 command += " fc rgb \"" + color + "\""; |
249 print(command); | 347 print(command); |
250 } | 348 } |
251 | 349 |
252 | 350 |
| 351 function TicksToRanges(ticks) { |
| 352 var ranges = []; |
| 353 for (var i = 0; i < ticks.length; i++) { |
| 354 var tick = ticks[i].tick; |
| 355 ranges.push(new Range(tick - kTickHalfDuration, tick + kTickHalfDuration)); |
| 356 } |
| 357 return ranges; |
| 358 } |
| 359 |
| 360 |
253 function MergeRanges(ranges) { | 361 function MergeRanges(ranges) { |
254 ranges.sort(function(a, b) { return a.start - b.start; }); | 362 ranges.sort(function(a, b) { return a.start - b.start; }); |
255 var result = []; | 363 var result = []; |
256 var j = 0; | 364 var j = 0; |
257 for (var i = 0; i < ranges.length; i = j) { | 365 for (var i = 0; i < ranges.length; i = j) { |
258 var merge_start = ranges[i].start; | 366 var merge_start = ranges[i].start; |
259 if (merge_start > xrange_end) break; // Out of plot range. | 367 if (merge_start > xrange_end) break; // Out of plot range. |
260 var merge_end = ranges[i].end; | 368 var merge_end = ranges[i].end; |
261 for (j = i + 1; j < ranges.length; j++) { | 369 for (j = i + 1; j < ranges.length; j++) { |
262 var next_range = ranges[j]; | 370 var next_range = ranges[j]; |
263 // Don't merge ranges if there is no overlap (including merge tolerance). | 371 // Don't merge ranges if there is no overlap (including merge tolerance). |
264 if (next_range.start > merge_end + kPauseTolerance) break; | 372 if (next_range.start > merge_end + kPauseTolerance) break; |
265 // Merge ranges. | 373 // Merge ranges. |
266 if (next_range.end > merge_end) { // Extend range end. | 374 if (next_range.end > merge_end) { // Extend range end. |
267 merge_end = next_range.end; | 375 merge_end = next_range.end; |
268 } | 376 } |
269 } | 377 } |
270 if (merge_end < xrange_start) continue; // Out of plot range. | 378 if (merge_end < xrange_start) continue; // Out of plot range. |
| 379 if (merge_end < merge_start) continue; // Not an actual range. |
271 result.push(new Range(merge_start, merge_end)); | 380 result.push(new Range(merge_start, merge_end)); |
272 } | 381 } |
273 return result; | 382 return result; |
274 } | 383 } |
275 | 384 |
276 | 385 |
277 function ExcludeRanges(include, exclude) { | 386 function ExcludeRanges(include, exclude) { |
278 // We assume that both input lists are sorted and merged with MergeRanges. | 387 // We assume that both input lists are sorted and merged with MergeRanges. |
279 var result = []; | 388 var result = []; |
280 var exclude_index = 0; | 389 var exclude_index = 0; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } else { | 459 } else { |
351 throw new Error("this should not happen!"); | 460 throw new Error("this should not happen!"); |
352 } | 461 } |
353 } | 462 } |
354 | 463 |
355 return result; | 464 return result; |
356 } | 465 } |
357 | 466 |
358 | 467 |
359 function GnuplotOutput() { | 468 function GnuplotOutput() { |
360 xrange_start = kOverrideRangeStart ? kOverrideRangeStart : xrange_start; | 469 xrange_start = (xrange_start_override || xrange_start_override == 0) |
361 xrange_end = kOverrideRangeEnd ? kOverrideRangeEnd : xrange_end; | 470 ? xrange_start_override : xrange_start; |
| 471 xrange_end = (xrange_end_override || xrange_end_override == 0) |
| 472 ? xrange_end_override : xrange_end; |
362 print("set terminal pngcairo size " + kResX + "," + kResY + | 473 print("set terminal pngcairo size " + kResX + "," + kResY + |
363 " enhanced font 'Helvetica,10'"); | 474 " enhanced font 'Helvetica,10'"); |
364 print("set yrange [0:" + (num_timer_event + 1) + "]"); | 475 print("set yrange [0:" + (num_timer_event + 1) + "]"); |
365 print("set xlabel \"execution time in ms\""); | 476 print("set xlabel \"execution time in ms\""); |
366 print("set xrange [" + xrange_start + ":" + xrange_end + "]"); | 477 print("set xrange [" + xrange_start + ":" + xrange_end + "]"); |
367 print("set style fill pattern 2 bo 1"); | 478 print("set style fill pattern 2 bo 1"); |
368 print("set style rect fs solid 1 noborder"); | 479 print("set style rect fs solid 1 noborder"); |
369 print("set style line 1 lt 1 lw 1 lc rgb \"#000000\""); | 480 print("set style line 1 lt 1 lw 1 lc rgb \"#000000\""); |
370 print("set xtics out nomirror"); | 481 print("set xtics out nomirror"); |
371 print("unset key"); | 482 print("unset key"); |
(...skipping 19 matching lines...) Expand all Loading... |
391 ranges[i].start, ranges[i].end, | 502 ranges[i].start, ranges[i].end, |
392 kTimerEventWidth); | 503 kTimerEventWidth); |
393 } | 504 } |
394 } | 505 } |
395 | 506 |
396 // Plot code kind gathered from ticks. | 507 // Plot code kind gathered from ticks. |
397 for (var name in CodeKinds) { | 508 for (var name in CodeKinds) { |
398 var code_kind = CodeKinds[name]; | 509 var code_kind = CodeKinds[name]; |
399 var offset = kY1Offset - 1; | 510 var offset = kY1Offset - 1; |
400 // Top most frame. | 511 // Top most frame. |
401 var row = MergeRanges(code_kind.in_execution); | 512 var row = MergeRanges(TicksToRanges(code_kind.in_execution)); |
402 for (var j = 0; j < row.length; j++) { | 513 for (var j = 0; j < row.length; j++) { |
403 DrawBar(offset, code_kind.color, | 514 DrawBar(offset, code_kind.color, |
404 row[j].start, row[j].end, kExecutionFrameWidth); | 515 row[j].start, row[j].end, kExecutionFrameWidth); |
405 } | 516 } |
406 offset = offset - 2 * kExecutionFrameWidth - kGapWidth; | 517 offset = offset - 2 * kExecutionFrameWidth - kGapWidth; |
407 // Javascript frames. | 518 // Javascript frames. |
408 for (var i = 0; i < kStackFrames; i++) { | 519 for (var i = 0; i < kStackFrames; i++) { |
409 offset = offset - 2 * kStackFrameWidth - kGapWidth; | 520 offset = offset - 2 * kStackFrameWidth - kGapWidth; |
410 row = MergeRanges(code_kind.stack_frames[i]); | 521 row = MergeRanges(TicksToRanges(code_kind.stack_frames[i])); |
411 for (var j = 0; j < row.length; j++) { | 522 for (var j = 0; j < row.length; j++) { |
412 DrawBar(offset, code_kind.color, | 523 DrawBar(offset, code_kind.color, |
413 row[j].start, row[j].end, kStackFrameWidth); | 524 row[j].start, row[j].end, kStackFrameWidth); |
414 } | 525 } |
415 } | 526 } |
416 } | 527 } |
417 | 528 |
418 // Add labels as legend for code kind colors. | 529 // Add labels as legend for code kind colors. |
419 var padding = kCodeKindLabelPadding * (xrange_end - xrange_start) / kResX; | 530 var padding = kCodeKindLabelPadding * (xrange_end - xrange_start) / kResX; |
420 var label_x = xrange_start; | 531 var label_x = xrange_start; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 for (var i = 0; i < execution_pauses.length; i++) { | 567 for (var i = 0; i < execution_pauses.length; i++) { |
457 var pause = execution_pauses[i]; | 568 var pause = execution_pauses[i]; |
458 print(pause.end + " " + pause.duration()); | 569 print(pause.end + " " + pause.duration()); |
459 } | 570 } |
460 print("e"); | 571 print("e"); |
461 } | 572 } |
462 | 573 |
463 | 574 |
464 CollectData(); | 575 CollectData(); |
465 GnuplotOutput(); | 576 GnuplotOutput(); |
OLD | NEW |