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('tracks.timeline_thread_track'); 8 9 base.require('tracks.timeline_container_track'); 10 base.require('tracks.timeline_slice_track'); 11 base.require('tracks.timeline_slice_group_track'); 12 base.require('tracks.timeline_async_slice_group_track'); 13 base.require('timeline_filter'); 14 base.require('ui'); 15 16 base.exportTo('tracks', function() { 17 18 /** 19 * Visualizes a TimelineThread using a series of of TimelineSliceTracks. 20 * @constructor 21 */ 22 var TimelineThreadTrack = base.ui.define(tracks.TimelineContainerTrack); 23 TimelineThreadTrack.prototype = { 24 __proto__: tracks.TimelineContainerTrack.prototype, 25 26 decorate: function() { 27 this.classList.add('timeline-thread-track'); 28 this.categoryFilter_ = new tracing.TimelineFilter(); 29 }, 30 31 get thread() { 32 return this.thread_; 33 }, 34 35 set thread(thread) { 36 this.thread_ = thread; 37 this.updateChildTracks_(); 38 }, 39 40 get tooltip() { 41 return this.tooltip_; 42 }, 43 44 set tooltip(value) { 45 this.tooltip_ = value; 46 this.updateChildTracks_(); 47 }, 48 49 get heading() { 50 return this.heading_; 51 }, 52 53 set heading(h) { 54 this.heading_ = h; 55 this.updateChildTracks_(); 56 }, 57 58 applyCategoryFilter_: function() { 59 this.updateVisibility_(); 60 }, 61 62 updateChildTracks_: function() { 63 this.detach(); 64 if (this.thread_) { 65 var cpuTrack = new tracks.TimelineSliceTrack(); 66 cpuTrack.heading = ''; 67 cpuTrack.slices = this.thread_.cpuSlices; 68 cpuTrack.height = '4px'; 69 cpuTrack.decorateHit = function(hit) { 70 hit.thread = this.thread_; 71 } 72 this.addTrack_(cpuTrack); 73 74 var asyncTrack = new tracks.TimelineAsyncSliceGroupTrack(); 75 asyncTrack.categoryFilter = this.categoryFilter; 76 asyncTrack.decorateHit = function(hit) { 77 // TODO(simonjam): figure out how to associate subSlice hits back 78 // to their parent slice. 79 } 80 asyncTrack.group = this.thread_.asyncSlices; 81 this.addTrack_(asyncTrack); 82 83 var track = new tracks.TimelineSliceGroupTrack(); 84 track.decorateHit = function(hit) { 85 hit.thread = this.thread_; 86 } 87 track.group = this.thread_; 88 this.addTrack_(track); 89 90 this.updateVisibility_(); 91 } 92 this.addControlButtonElements_(this.tracks_.length >= 4); 93 }, 94 95 updateVisibility_: function() { 96 if (!this.categoryFilter.matchThread(this.thread)) { 97 this.visible = false; 98 return; 99 } 100 var shouldBeVisible = false; 101 for (var i = 0; i < this.tracks_.length; ++i) { 102 var track = this.tracks_[i]; 103 if (track.visible) { 104 shouldBeVisible = true; 105 if (i >= 1) { 106 track.heading = this.heading_; 107 track.tooltip = this.tooltip_; 108 break; 109 } 110 } 111 } 112 this.visible = shouldBeVisible; 113 }, 114 115 collapsedDidChange: function(collapsed) { 116 if (collapsed) { 117 var h = parseInt(this.tracks_[0].height); 118 for (var i = 0; i < this.tracks_.length; ++i) { 119 if (h > 2) { 120 this.tracks_[i].height = Math.floor(h) + 'px'; 121 } else { 122 this.tracks_[i].style.display = 'none'; 123 } 124 h = h * 0.5; 125 } 126 } else { 127 for (var i = 0; i < this.tracks_.length; ++i) { 128 this.tracks_[i].height = this.tracks_[0].height; 129 this.tracks_[i].style.display = ''; 130 } 131 } 132 } 133 }; 134 135 return { 136 TimelineThreadTrack: TimelineThreadTrack 137 }; 138 }); 139