1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 'use strict'; 6 7 base.requireStylesheet('tracing.tracks.trace_model_track'); 8 9 base.require('base.measuring_stick'); 10 base.require('tracing.tracks.container_track'); 11 base.require('tracing.tracks.kernel_track'); 12 base.require('tracing.tracks.process_track'); 13 14 base.require('ui'); 15 16 base.exportTo('tracing.tracks', function() { 17 18 /** 19 * Visualizes a Model by building ProcessTracks and 20 * CpuTracks. 21 * @constructor 22 */ 23 var TraceModelTrack = ui.define( 24 'trace-model-track', tracing.tracks.ContainerTrack); 25 26 TraceModelTrack.prototype = { 27 28 __proto__: tracing.tracks.ContainerTrack.prototype, 29 30 decorate: function(viewport) { 31 tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport); 32 this.classList.add('model-track'); 33 }, 34 35 detach: function() { 36 tracing.tracks.ContainerTrack.prototype.detach.call(this); 37 }, 38 39 get model() { 40 return this.model_; 41 }, 42 43 set model(model) { 44 this.model_ = model; 45 this.updateContents_(); 46 }, 47 48 get hasVisibleContent() { 49 return this.children.length > 0; 50 }, 51 52 applyCategoryFilter_: function() { 53 this.updateContents_(); 54 }, 55 56 updateContents_: function() { 57 this.textContent = ''; 58 if (!this.model_ || !this.categoryFilter) 59 return; 60 61 var categoryFilter = this.categoryFilter; 62 63 this.appendKernelTrack_(); 64 65 // Get a sorted list of processes. 66 var processes = this.model_.getAllProcesses(); 67 processes.sort(tracing.trace_model.Process.compare); 68 69 for (var i = 0; i < processes.length; ++i) { 70 var process = processes[i]; 71 if (!categoryFilter.matchProcess(process)) 72 return; 73 var track = new tracing.tracks.ProcessTrack(this.viewport); 74 track.categoryFilter = categoryFilter; 75 track.process = process; 76 if (!track.hasVisibleContent) 77 continue; 78 this.appendChild(track); 79 } 80 }, 81 82 appendKernelTrack_: function() { 83 var kernel = this.model.kernel; 84 if (!this.categoryFilter.matchProcess(kernel)) 85 return; 86 var track = new tracing.tracks.KernelTrack(this.viewport); 87 track.categoryFilter = this.categoryFilter; 88 track.kernel = this.model.kernel; 89 if (!track.hasVisibleContent) 90 return; 91 this.appendChild(track); 92 }, 93 94 drawTrack: function(type) { 95 switch (type) { 96 case tracing.tracks.DrawType.INSTANT_EVENT: 97 if (!this.model_.instantEvents || 98 this.model_.instantEvents.length === 0) 99 break; 100 101 var ctx = this.context(); 102 if (ctx === undefined) 103 break; 104 105 ctx.save(); 106 var worldBounds = this.setupCanvasForDraw_(); 107 this.drawInstantEvents_( 108 this.model_.instantEvents, worldBounds.left, worldBounds.right); 109 ctx.restore(); 110 break; 111 } 112 113 tracing.tracks.ContainerTrack.prototype.drawTrack.call(this, type); 114 }, 115 116 addIntersectingItemsInRangeToSelectionInWorldSpace: function( 117 loWX, hiWX, viewPixWidthWorld, selection) { 118 function onPickHit(instantEvent) { 119 var hit = selection.addSlice(this, instantEvent); 120 this.decorateHit(hit); 121 } 122 base.iterateOverIntersectingIntervals(this.model_.instantEvents, 123 function(x) { return x.start; }, 124 function(x) { return x.duration; }, 125 loWX, hiWX, 126 onPickHit.bind(this)); 127 128 tracing.tracks.ContainerTrack.prototype. 129 addIntersectingItemsInRangeToSelectionInWorldSpace. 130 apply(this, arguments); 131 } 132 }; 133 134 return { 135 TraceModelTrack: TraceModelTrack 136 }; 137 }); 138