1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/ui/tracks/process_memory_dump_track.html"> 9<link rel="import" href="/tracing/ui/tracks/process_track_base.html"> 10<link rel="import" href="/tracing/ui/base/draw_helpers.html"> 11 12<script> 13'use strict'; 14 15tr.exportTo('tr.ui.tracks', function() { 16 var ProcessTrackBase = tr.ui.tracks.ProcessTrackBase; 17 18 /** 19 * @constructor 20 */ 21 var ProcessTrack = tr.ui.b.define('process-track', ProcessTrackBase); 22 23 ProcessTrack.prototype = { 24 __proto__: ProcessTrackBase.prototype, 25 26 decorate: function(viewport) { 27 tr.ui.tracks.ProcessTrackBase.prototype.decorate.call(this, viewport); 28 }, 29 30 drawTrack: function(type) { 31 switch (type) { 32 case tr.ui.tracks.DrawType.INSTANT_EVENT: 33 if (!this.processBase.instantEvents || 34 this.processBase.instantEvents.length === 0) 35 break; 36 37 var ctx = this.context(); 38 39 var pixelRatio = window.devicePixelRatio || 1; 40 var bounds = this.getBoundingClientRect(); 41 var canvasBounds = ctx.canvas.getBoundingClientRect(); 42 43 ctx.save(); 44 ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top)); 45 46 var dt = this.viewport.currentDisplayTransform; 47 var viewLWorld = dt.xViewToWorld(0); 48 var viewRWorld = dt.xViewToWorld( 49 bounds.width * pixelRatio); 50 51 tr.ui.b.drawInstantSlicesAsLines( 52 ctx, 53 this.viewport.currentDisplayTransform, 54 viewLWorld, 55 viewRWorld, 56 bounds.height, 57 this.processBase.instantEvents, 58 2); 59 60 ctx.restore(); 61 62 break; 63 64 case tr.ui.tracks.DrawType.BACKGROUND: 65 this.drawBackground_(); 66 // Don't bother recursing further, Process is the only level that 67 // draws backgrounds. 68 return; 69 } 70 71 tr.ui.tracks.ContainerTrack.prototype.drawTrack.call(this, type); 72 }, 73 74 drawBackground_: function() { 75 var ctx = this.context(); 76 var canvasBounds = ctx.canvas.getBoundingClientRect(); 77 var pixelRatio = window.devicePixelRatio || 1; 78 79 var draw = false; 80 ctx.fillStyle = '#eee'; 81 for (var i = 0; i < this.children.length; ++i) { 82 if (!(this.children[i] instanceof tr.ui.tracks.Track) || 83 (this.children[i] instanceof tr.ui.tracks.SpacingTrack)) 84 continue; 85 86 draw = !draw; 87 if (!draw) 88 continue; 89 90 var bounds = this.children[i].getBoundingClientRect(); 91 ctx.fillRect(0, pixelRatio * (bounds.top - canvasBounds.top), 92 ctx.canvas.width, pixelRatio * bounds.height); 93 } 94 }, 95 96 // Process maps to processBase because we derive from ProcessTrackBase. 97 set process(process) { 98 this.processBase = process; 99 }, 100 101 get process() { 102 return this.processBase; 103 }, 104 105 get eventContainer() { 106 return this.process; 107 }, 108 109 addContainersToTrackMap: function(containerToTrackMap) { 110 tr.ui.tracks.ProcessTrackBase.prototype.addContainersToTrackMap.apply( 111 this, arguments); 112 containerToTrackMap.addContainer(this.process, this); 113 }, 114 115 appendMemoryDumpTrack_: function() { 116 var processMemoryDumps = this.process.memoryDumps; 117 if (processMemoryDumps.length) { 118 var pmdt = new tr.ui.tracks.ProcessMemoryDumpTrack(this.viewport_); 119 pmdt.memoryDumps = processMemoryDumps; 120 this.appendChild(pmdt); 121 } 122 }, 123 124 addIntersectingEventsInRangeToSelectionInWorldSpace: function( 125 loWX, hiWX, viewPixWidthWorld, selection) { 126 function onPickHit(instantEvent) { 127 selection.push(instantEvent); 128 } 129 var instantEventWidth = 2 * viewPixWidthWorld; 130 tr.b.iterateOverIntersectingIntervals(this.processBase.instantEvents, 131 function(x) { return x.start; }, 132 function(x) { return x.duration + instantEventWidth; }, 133 loWX, hiWX, 134 onPickHit.bind(this)); 135 136 tr.ui.tracks.ContainerTrack.prototype. 137 addIntersectingEventsInRangeToSelectionInWorldSpace. 138 apply(this, arguments); 139 }, 140 141 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY, 142 selection) { 143 this.addClosestInstantEventToSelection(this.processBase.instantEvents, 144 worldX, worldMaxDist, selection); 145 tr.ui.tracks.ContainerTrack.prototype.addClosestEventToSelection. 146 apply(this, arguments); 147 } 148 }; 149 150 return { 151 ProcessTrack: ProcessTrack 152 }; 153}); 154</script> 155 156