Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 Array.prototype.top = function() { | |
| 29 if (this.length == 0) return undefined; | |
| 30 return this[this.length - 1]; | |
| 31 } | |
| 32 | |
| 33 | |
| 34 function PlotScriptComposer(kResX, kResY) { | |
| 35 // Constants. | |
| 36 var kV8BinarySuffixes = ["/d8", "/libv8.so"]; | |
| 37 var kStackFrames = 8; // Stack frames to display in the plot. | |
| 38 | |
| 39 var kTimerEventWidth = 0.33; // Width of each timeline. | |
| 40 var kExecutionFrameWidth = 0.2; // Width of the top stack frame line. | |
| 41 var kStackFrameWidth = 0.1; // Width of the lower stack frame lines. | |
| 42 var kGapWidth = 0.05; // Gap between stack frame lines. | |
| 43 | |
| 44 var kY1Offset = 10; // Offset for stack frame vs. event lines. | |
| 45 var kPauseLabelPadding = 5; // Padding for pause time labels. | |
| 46 var kNumPauseLabels = 7; // Number of biggest pauses to label. | |
| 47 var kCodeKindLabelPadding = 100; // Padding for code kind labels. | |
| 48 | |
| 49 var kTickHalfDuration = 0.5; // Duration of half a tick in seconds. | |
|
Jakob Kummerow
2013/06/24 11:03:33
s/seconds/milliseconds/, I think
| |
| 50 var kMinRangeLength = 0.0005; // Minimum length for an event in ms. | |
| 51 | |
| 52 var kNumThreads = 2; // Number of threads. | |
| 53 var kExecutionThreadId = 0; // ID of main thread. | |
| 54 | |
| 55 // Data structures. | |
| 56 function TimerEvent(color, pause, thread_id) { | |
| 57 assert(thread_id >= 0 && thread_id < kNumThreads, "invalid thread id"); | |
| 58 this.color = color; | |
| 59 this.pause = pause; | |
| 60 this.ranges = []; | |
| 61 this.thread_id = thread_id; | |
| 62 this.index = ++num_timer_event; | |
| 63 } | |
| 64 | |
| 65 function CodeKind(color, kinds) { | |
| 66 this.color = color; | |
| 67 this.in_execution = []; | |
| 68 this.stack_frames = []; | |
| 69 for (var i = 0; i < kStackFrames; i++) this.stack_frames.push([]); | |
| 70 this.kinds = kinds; | |
| 71 } | |
| 72 | |
| 73 function Range(start, end) { | |
| 74 // Everthing 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 function Tick(tick) { | |
| 82 this.tick = tick; | |
| 83 } | |
| 84 | |
| 85 // Init values. | |
| 86 var num_timer_event = kY1Offset + 0.5; | |
| 87 | |
| 88 var TimerEvents = { | |
| 89 'V8.Execute': new TimerEvent("#000000", false, 0), | |
| 90 'V8.External': new TimerEvent("#3399FF", false, 0), | |
| 91 'V8.CompileFullCode': new TimerEvent("#CC0000", true, 0), | |
| 92 'V8.RecompileSynchronous': new TimerEvent("#CC0044", true, 0), | |
| 93 'V8.RecompileParallel': new TimerEvent("#CC4499", false, 1), | |
| 94 'V8.CompileEval': new TimerEvent("#CC4400", true, 0), | |
| 95 'V8.Parse': new TimerEvent("#00CC00", true, 0), | |
| 96 'V8.PreParse': new TimerEvent("#44CC00", true, 0), | |
| 97 'V8.ParseLazy': new TimerEvent("#00CC44", true, 0), | |
| 98 'V8.GCScavenger': new TimerEvent("#0044CC", true, 0), | |
| 99 'V8.GCCompactor': new TimerEvent("#4444CC", true, 0), | |
| 100 'V8.GCContext': new TimerEvent("#4400CC", true, 0), | |
| 101 }; | |
| 102 | |
| 103 var CodeKinds = { | |
| 104 'external ': new CodeKind("#3399FF", [-3]), | |
| 105 'reg.exp. ': new CodeKind("#0000FF", [-2]), | |
| 106 'runtime ': new CodeKind("#000000", [-1]), | |
| 107 'full code': new CodeKind("#DD0000", [0]), | |
| 108 'opt code ': new CodeKind("#00EE00", [1]), | |
| 109 'code stub': new CodeKind("#FF00FF", [2]), | |
| 110 'built-in ': new CodeKind("#AA00AA", [3]), | |
| 111 'inl.cache': new CodeKind("#4444AA", [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]), | |
| 112 }; | |
| 113 | |
| 114 var code_map = new CodeMap(); | |
| 115 var execution_pauses = []; | |
| 116 var event_stack = []; | |
| 117 var last_time_stamp = []; | |
| 118 for (var i = 0; i < kNumThreads; i++) { | |
| 119 event_stack[i] = []; | |
| 120 last_time_stamp[i] = -1; | |
| 121 } | |
| 122 | |
| 123 var range_start = undefined; | |
| 124 var range_end = undefined; | |
| 125 var obj_index = 0; | |
| 126 var pause_tolerance = 0.005; // Milliseconds. | |
| 127 var distortion = 0; | |
| 128 | |
| 129 // Utility functions. | |
| 130 function assert(something, message) { | |
| 131 if (!something) print(new Error(message).stack); | |
| 132 } | |
| 133 | |
| 134 function FindCodeKind(kind) { | |
| 135 for (name in CodeKinds) { | |
| 136 if (CodeKinds[name].kinds.indexOf(kind) >= 0) { | |
| 137 return CodeKinds[name]; | |
| 138 } | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 function TicksToRanges(ticks) { | |
| 143 var ranges = []; | |
| 144 for (var i = 0; i < ticks.length; i++) { | |
| 145 var tick = ticks[i].tick; | |
| 146 ranges.push( | |
| 147 new Range(tick - kTickHalfDuration, tick + kTickHalfDuration)); | |
| 148 } | |
| 149 return ranges; | |
| 150 } | |
| 151 | |
| 152 function MergeRanges(ranges) { | |
| 153 ranges.sort(function(a, b) { return a.start - b.start; }); | |
| 154 var result = []; | |
| 155 var j = 0; | |
| 156 for (var i = 0; i < ranges.length; i = j) { | |
| 157 var merge_start = ranges[i].start; | |
| 158 if (merge_start > range_end) break; // Out of plot range. | |
| 159 var merge_end = ranges[i].end; | |
| 160 for (j = i + 1; j < ranges.length; j++) { | |
| 161 var next_range = ranges[j]; | |
| 162 // Don't merge ranges if there is no overlap (incl. merge tolerance). | |
| 163 if (next_range.start > merge_end + pause_tolerance) break; | |
| 164 // Merge ranges. | |
| 165 if (next_range.end > merge_end) { // Extend range end. | |
| 166 merge_end = next_range.end; | |
| 167 } | |
| 168 } | |
| 169 if (merge_end < range_start) continue; // Out of plot range. | |
| 170 if (merge_end < merge_start) continue; // Not an actual range. | |
| 171 result.push(new Range(merge_start, merge_end)); | |
| 172 } | |
| 173 return result; | |
| 174 } | |
| 175 | |
| 176 function RestrictRangesTo(ranges, start, end) { | |
| 177 var result = []; | |
| 178 for (var i = 0; i < ranges.length; i++) { | |
| 179 if (ranges[i].start <= end && ranges[i].end >= start) { | |
| 180 result.push(new Range(Math.max(ranges[i].start, start), | |
| 181 Math.min(ranges[i].end, end))); | |
| 182 } | |
| 183 } | |
| 184 return result; | |
| 185 } | |
| 186 | |
| 187 // Public methods. | |
| 188 this.collectData = function(input, distortion_per_entry) { | |
| 189 | |
| 190 // Parse functions. | |
| 191 var parseTimeStamp = function(timestamp) { | |
| 192 distortion += distortion_per_entry; | |
| 193 return parseInt(timestamp) / 1000 - distortion; | |
| 194 } | |
| 195 | |
| 196 var processTimerEventStart = function(name, start) { | |
| 197 // Find out the thread id. | |
| 198 var new_event = TimerEvents[name]; | |
| 199 if (new_event === undefined) return; | |
| 200 var thread_id = new_event.thread_id; | |
| 201 | |
| 202 start = Math.max(last_time_stamp[thread_id] + kMinRangeLength, start); | |
| 203 | |
| 204 // Last event on this thread is done with the start of this event. | |
| 205 var last_event = event_stack[thread_id].top(); | |
| 206 if (last_event !== undefined) { | |
| 207 var new_range = new Range(last_time_stamp[thread_id], start); | |
| 208 last_event.ranges.push(new_range); | |
| 209 } | |
| 210 event_stack[thread_id].push(new_event); | |
| 211 last_time_stamp[thread_id] = start; | |
| 212 }; | |
| 213 | |
| 214 var processTimerEventEnd = function(name, end) { | |
| 215 // Find out about the thread_id. | |
| 216 var finished_event = TimerEvents[name]; | |
| 217 var thread_id = finished_event.thread_id; | |
| 218 assert(finished_event === event_stack[thread_id].pop(), | |
| 219 "inconsistent event stack"); | |
| 220 | |
| 221 end = Math.max(last_time_stamp[thread_id] + kMinRangeLength, end); | |
| 222 | |
| 223 var new_range = new Range(last_time_stamp[thread_id], end); | |
| 224 finished_event.ranges.push(new_range); | |
| 225 last_time_stamp[thread_id] = end; | |
| 226 }; | |
| 227 | |
| 228 var processCodeCreateEvent = function(type, kind, address, size, name) { | |
| 229 var code_entry = new CodeMap.CodeEntry(size, name); | |
| 230 code_entry.kind = kind; | |
| 231 code_map.addCode(address, code_entry); | |
| 232 }; | |
| 233 | |
| 234 var processCodeMoveEvent = function(from, to) { | |
| 235 code_map.moveCode(from, to); | |
| 236 }; | |
| 237 | |
| 238 var processCodeDeleteEvent = function(address) { | |
| 239 code_map.deleteCode(address); | |
| 240 }; | |
| 241 | |
| 242 var processSharedLibrary = function(name, start, end) { | |
| 243 var code_entry = new CodeMap.CodeEntry(end - start, name); | |
| 244 code_entry.kind = -3; // External code kind. | |
| 245 for (var i = 0; i < kV8BinarySuffixes.length; i++) { | |
| 246 var suffix = kV8BinarySuffixes[i]; | |
| 247 if (name.indexOf(suffix, name.length - suffix.length) >= 0) { | |
| 248 code_entry.kind = -1; // V8 runtime code kind. | |
| 249 break; | |
| 250 } | |
| 251 } | |
| 252 code_map.addLibrary(start, code_entry); | |
| 253 }; | |
| 254 | |
| 255 var processTimerEventStart = function(name, start) { | |
| 256 // Find out the thread id. | |
| 257 var new_event = TimerEvents[name]; | |
| 258 if (new_event === undefined) return; | |
| 259 var thread_id = new_event.thread_id; | |
| 260 | |
| 261 start = Math.max(last_time_stamp[thread_id] + kMinRangeLength, start); | |
| 262 | |
| 263 // Last event on this thread is done with the start of this event. | |
| 264 var last_event = event_stack[thread_id].top(); | |
| 265 if (last_event !== undefined) { | |
| 266 var new_range = new Range(last_time_stamp[thread_id], start); | |
| 267 last_event.ranges.push(new_range); | |
| 268 } | |
| 269 event_stack[thread_id].push(new_event); | |
| 270 last_time_stamp[thread_id] = start; | |
| 271 }; | |
| 272 | |
| 273 var processTimerEventEnd = function(name, end) { | |
| 274 // Find out about the thread_id. | |
| 275 var finished_event = TimerEvents[name]; | |
| 276 var thread_id = finished_event.thread_id; | |
| 277 assert(finished_event === event_stack[thread_id].pop(), | |
| 278 "inconsistent event stack"); | |
| 279 | |
| 280 end = Math.max(last_time_stamp[thread_id] + kMinRangeLength, end); | |
| 281 | |
| 282 var new_range = new Range(last_time_stamp[thread_id], end); | |
| 283 finished_event.ranges.push(new_range); | |
| 284 last_time_stamp[thread_id] = end; | |
| 285 }; | |
| 286 | |
| 287 var processCodeCreateEvent = function(type, kind, address, size, name) { | |
| 288 var code_entry = new CodeMap.CodeEntry(size, name); | |
| 289 code_entry.kind = kind; | |
| 290 code_map.addCode(address, code_entry); | |
| 291 }; | |
| 292 | |
| 293 var processCodeMoveEvent = function(from, to) { | |
| 294 code_map.moveCode(from, to); | |
| 295 }; | |
| 296 | |
| 297 var processCodeDeleteEvent = function(address) { | |
| 298 code_map.deleteCode(address); | |
| 299 }; | |
| 300 | |
| 301 var processSharedLibrary = function(name, start, end) { | |
| 302 var code_entry = new CodeMap.CodeEntry(end - start, name); | |
| 303 code_entry.kind = -3; // External code kind. | |
| 304 for (var i = 0; i < kV8BinarySuffixes.length; i++) { | |
| 305 var suffix = kV8BinarySuffixes[i]; | |
| 306 if (name.indexOf(suffix, name.length - suffix.length) >= 0) { | |
| 307 code_entry.kind = -1; // V8 runtime code kind. | |
| 308 break; | |
| 309 } | |
| 310 } | |
| 311 code_map.addLibrary(start, code_entry); | |
| 312 }; | |
| 313 | |
| 314 var processTickEvent = function( | |
| 315 pc, sp, timer, unused_x, unused_y, vmstate, stack) { | |
| 316 var tick = new Tick(timer); | |
| 317 | |
| 318 var entry = code_map.findEntry(pc); | |
| 319 if (entry) FindCodeKind(entry.kind).in_execution.push(tick); | |
| 320 | |
| 321 for (var i = 0; i < kStackFrames; i++) { | |
| 322 if (!stack[i]) break; | |
| 323 var entry = code_map.findEntry(stack[i]); | |
| 324 if (entry) FindCodeKind(entry.kind).stack_frames[i].push(tick); | |
| 325 } | |
| 326 }; | |
| 327 // Collect data from log. | |
| 328 var logreader = new LogReader( | |
| 329 { 'timer-event-start': { parsers: [null, parseTimeStamp], | |
| 330 processor: processTimerEventStart }, | |
| 331 'timer-event-end': { parsers: [null, parseTimeStamp], | |
| 332 processor: processTimerEventEnd }, | |
| 333 'shared-library': { parsers: [null, parseInt, parseInt], | |
| 334 processor: processSharedLibrary }, | |
| 335 'code-creation': { parsers: [null, parseInt, parseInt, parseInt, null], | |
| 336 processor: processCodeCreateEvent }, | |
| 337 'code-move': { parsers: [parseInt, parseInt], | |
| 338 processor: processCodeMoveEvent }, | |
| 339 'code-delete': { parsers: [parseInt], | |
| 340 processor: processCodeDeleteEvent }, | |
| 341 'tick': { parsers: [parseInt, parseInt, parseTimeStamp, | |
| 342 null, null, parseInt, 'var-args'], | |
| 343 processor: processTickEvent } | |
| 344 }); | |
| 345 | |
| 346 var line; | |
| 347 while (line = input()) { | |
| 348 logreader.processLogLine(line); | |
| 349 } | |
| 350 | |
| 351 // Collect execution pauses. | |
| 352 for (name in TimerEvents) { | |
| 353 var event = TimerEvents[name]; | |
| 354 if (!event.pause) continue; | |
| 355 var ranges = event.ranges; | |
| 356 for (var j = 0; j < ranges.length; j++) execution_pauses.push(ranges[j]); | |
| 357 } | |
| 358 execution_pauses = MergeRanges(execution_pauses); | |
| 359 }; | |
| 360 | |
| 361 | |
| 362 this.findPlotRange = function( | |
| 363 range_start_override, range_end_override, result_callback) { | |
| 364 var start_found = (range_start_override || range_start_override == 0); | |
| 365 var end_found = (range_end_override || range_end_override == 0); | |
| 366 range_start = start_found ? range_start_override : Infinity; | |
| 367 range_end = end_found ? range_end_override : -Infinity; | |
| 368 | |
| 369 if (!start_found || !end_found) { | |
| 370 for (name in TimerEvents) { | |
| 371 var ranges = TimerEvents[name].ranges; | |
| 372 for (var i = 0; i < ranges.length; i++) { | |
| 373 if (ranges[i].start < range_start && !start_found) { | |
| 374 range_start = ranges[i].start; | |
| 375 } | |
| 376 if (ranges[i].end > range_end && !end_found) { | |
| 377 range_end = ranges[i].end; | |
| 378 } | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 for (codekind in CodeKinds) { | |
| 383 var ticks = CodeKinds[codekind].in_execution; | |
| 384 for (var i = 0; i < ticks.length; i++) { | |
| 385 if (ticks[i].tick < range_start && !start_found) { | |
| 386 range_start = ticks[i].tick; | |
| 387 } | |
| 388 if (ticks[i].tick > range_end && !end_found) { | |
| 389 range_end = ticks[i].tick; | |
| 390 } | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 // Set pause tolerance to something appropriate for the plot resolution | |
| 395 // to make it easier for gnuplot. | |
| 396 pause_tolerance = (range_end - range_start) / kResX / 10; | |
| 397 | |
| 398 if (typeof result_callback === 'function') { | |
| 399 result_callback(range_start, range_end); | |
| 400 } | |
| 401 }; | |
| 402 | |
| 403 | |
| 404 this.assembleOutput = function(output) { | |
| 405 output("set yrange [0:" + (num_timer_event + 1) + "]"); | |
| 406 output("set xlabel \"execution time in ms\""); | |
| 407 output("set xrange [" + range_start + ":" + range_end + "]"); | |
| 408 output("set style fill pattern 2 bo 1"); | |
| 409 output("set style rect fs solid 1 noborder"); | |
| 410 output("set style line 1 lt 1 lw 1 lc rgb \"#000000\""); | |
| 411 output("set xtics out nomirror"); | |
| 412 output("unset key"); | |
| 413 | |
| 414 function DrawBar(row, color, start, end, width) { | |
| 415 obj_index++; | |
| 416 command = "set object " + obj_index + " rect"; | |
| 417 command += " from " + start + ", " + (row - width); | |
| 418 command += " to " + end + ", " + (row + width); | |
| 419 command += " fc rgb \"" + color + "\""; | |
| 420 output(command); | |
| 421 } | |
| 422 | |
| 423 var percentages = {}; | |
| 424 var total = 0; | |
| 425 for (var name in TimerEvents) { | |
| 426 var event = TimerEvents[name]; | |
| 427 var ranges = RestrictRangesTo(event.ranges, range_start, range_end); | |
| 428 ranges = MergeRanges(ranges); | |
| 429 var sum = | |
| 430 ranges.map(function(range) { return range.duration(); }) | |
| 431 .reduce(function(a, b) { return a + b; }, 0); | |
| 432 percentages[name] = (sum / (range_end - range_start) * 100).toFixed(1); | |
| 433 } | |
| 434 | |
| 435 // Name Y-axis. | |
| 436 var ytics = []; | |
| 437 for (name in TimerEvents) { | |
| 438 var index = TimerEvents[name].index; | |
| 439 ytics.push('"' + name + ' (' + percentages[name] + '%%)" ' + index); | |
| 440 } | |
| 441 ytics.push('"code kind being executed"' + ' ' + (kY1Offset - 1)); | |
| 442 ytics.push('"top ' + kStackFrames + ' js stack frames"' + ' ' + | |
| 443 (kY1Offset - 2)); | |
| 444 ytics.push('"pause times" 0'); | |
| 445 output("set ytics out nomirror (" + ytics.join(', ') + ")"); | |
| 446 | |
| 447 // Plot timeline. | |
| 448 for (var name in TimerEvents) { | |
| 449 var event = TimerEvents[name]; | |
| 450 var ranges = MergeRanges(event.ranges); | |
| 451 for (var i = 0; i < ranges.length; i++) { | |
| 452 DrawBar(event.index, event.color, | |
| 453 ranges[i].start, ranges[i].end, | |
| 454 kTimerEventWidth); | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 // Plot code kind gathered from ticks. | |
| 459 for (var name in CodeKinds) { | |
| 460 var code_kind = CodeKinds[name]; | |
| 461 var offset = kY1Offset - 1; | |
| 462 // Top most frame. | |
| 463 var row = MergeRanges(TicksToRanges(code_kind.in_execution)); | |
| 464 for (var j = 0; j < row.length; j++) { | |
| 465 DrawBar(offset, code_kind.color, | |
| 466 row[j].start, row[j].end, kExecutionFrameWidth); | |
| 467 } | |
| 468 offset = offset - 2 * kExecutionFrameWidth - kGapWidth; | |
| 469 // Javascript frames. | |
| 470 for (var i = 0; i < kStackFrames; i++) { | |
| 471 offset = offset - 2 * kStackFrameWidth - kGapWidth; | |
| 472 row = MergeRanges(TicksToRanges(code_kind.stack_frames[i])); | |
| 473 for (var j = 0; j < row.length; j++) { | |
| 474 DrawBar(offset, code_kind.color, | |
| 475 row[j].start, row[j].end, kStackFrameWidth); | |
| 476 } | |
| 477 } | |
| 478 } | |
| 479 | |
| 480 // Add labels as legend for code kind colors. | |
| 481 var padding = kCodeKindLabelPadding * (range_end - range_start) / kResX; | |
| 482 var label_x = range_start; | |
| 483 var label_y = kY1Offset; | |
| 484 for (var name in CodeKinds) { | |
| 485 label_x += padding; | |
| 486 output("set label \"" + name + "\" at " + label_x + "," + label_y + | |
| 487 " textcolor rgb \"" + CodeKinds[name].color + "\"" + | |
| 488 " font \"Helvetica,9'\""); | |
| 489 } | |
| 490 | |
| 491 if (execution_pauses.length == 0) { | |
| 492 // Force plot and return without plotting execution pause impulses. | |
| 493 output("plot 1/0"); | |
| 494 return; | |
| 495 } | |
| 496 | |
| 497 // Label the longest pauses. | |
| 498 execution_pauses.sort( | |
| 499 function(a, b) { return b.duration() - a.duration(); }); | |
| 500 | |
| 501 var max_pause_time = execution_pauses[0].duration(); | |
| 502 padding = kPauseLabelPadding * (range_end - range_start) / kResX; | |
| 503 var y_scale = kY1Offset / max_pause_time / 2; | |
| 504 for (var i = 0; i < execution_pauses.length && i < kNumPauseLabels; i++) { | |
| 505 var pause = execution_pauses[i]; | |
| 506 var label_content = (pause.duration() | 0) + " ms"; | |
| 507 var label_x = pause.end + padding; | |
| 508 var label_y = Math.max(1, (pause.duration() * y_scale)); | |
| 509 output("set label \"" + label_content + "\" at " + | |
| 510 label_x + "," + label_y + " font \"Helvetica,7'\""); | |
| 511 } | |
| 512 | |
| 513 // Scale second Y-axis appropriately. | |
| 514 var y2range = max_pause_time * num_timer_event / kY1Offset * 2; | |
| 515 output("set y2range [0:" + y2range + "]"); | |
| 516 // Plot graph with impulses as data set. | |
| 517 output("plot '-' using 1:2 axes x1y2 with impulses ls 1"); | |
| 518 for (var i = 0; i < execution_pauses.length; i++) { | |
| 519 var pause = execution_pauses[i]; | |
| 520 output(pause.end + " " + pause.duration()); | |
| 521 } | |
| 522 output("e"); | |
| 523 return obj_index; | |
| 524 }; | |
| 525 } | |
| OLD | NEW |