3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="stylesheet" href="/tracing/tracks/process_track_base.css">
10 <link rel="import" href="/tracing/tracks/container_track.html">
11 <link rel="import" href="/tracing/tracks/counter_track.html">
12 <link rel="import" href="/tracing/tracks/object_instance_group_track.html">
13 <link rel="import" href="/tracing/tracks/spacing_track.html">
14 <link rel="import" href="/tracing/tracks/thread_track.html">
15 <link rel="import" href="/tracing/trace_model_settings.html">
16 <link rel="import" href="/tracing/filter.html">
17 <link rel="import" href="/base/ui.html">
18 <link rel="import" href="/base/ui/dom_helpers.html">
23 tv.exportTo('tracing.tracks', function() {
25 var ObjectSnapshotView = tracing.analysis.ObjectSnapshotView;
26 var ObjectInstanceView = tracing.analysis.ObjectInstanceView;
27 var TraceModelSettings = tracing.TraceModelSettings;
28 var SpacingTrack = tracing.tracks.SpacingTrack;
31 * Visualizes a Process by building ThreadTracks and CounterTracks.
34 var ProcessTrackBase =
35 tv.ui.define('process-track-base', tracing.tracks.ContainerTrack);
37 ProcessTrackBase.prototype = {
39 __proto__: tracing.tracks.ContainerTrack.prototype,
41 decorate: function(viewport) {
42 tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
44 this.processBase_ = undefined;
46 this.classList.add('process-track-base');
47 this.classList.add('expanded');
49 this.processNameEl_ = tv.ui.createSpan();
50 this.processNameEl_.classList.add('process-track-name');
52 this.headerEl_ = tv.ui.createDiv({className: 'process-track-header'});
53 this.headerEl_.appendChild(this.processNameEl_);
54 this.headerEl_.addEventListener('click', this.onHeaderClick_.bind(this));
56 this.appendChild(this.headerEl_);
60 return this.processBase_;
63 set processBase(processBase) {
64 this.processBase_ = processBase;
66 if (this.processBase_) {
67 var modelSettings = new TraceModelSettings(this.processBase_.model);
69 if (this.processBase_.labels !== undefined &&
70 this.processBase_.labels.length == 1 &&
71 this.processBase_.labels[0] == 'chrome://tracing') {
76 this.expanded = modelSettings.getSettingFor(
77 this.processBase_, 'expanded', defaultValue);
80 this.updateContents_();
84 return this.classList.contains('expanded');
87 set expanded(expanded) {
88 expanded = !!expanded;
90 if (this.expanded === expanded)
93 this.classList.toggle('expanded');
95 // Expanding and collapsing tracks is, essentially, growing and shrinking
96 // the viewport. We dispatch a change event to trigger any processing
98 this.viewport_.dispatchChangeEvent();
100 if (!this.processBase_)
103 var modelSettings = new TraceModelSettings(this.processBase_.model);
104 modelSettings.setSettingFor(this.processBase_, 'expanded', expanded);
107 get hasVisibleContent() {
109 return this.children.length > 1;
113 onHeaderClick_: function(e) {
116 this.expanded = !this.expanded;
119 updateContents_: function() {
120 this.tracks_.forEach(function(track) {
121 this.removeChild(track);
124 if (!this.processBase_)
127 this.processNameEl_.textContent = this.processBase_.userFriendlyName;
128 this.headerEl_.title = this.processBase_.userFriendlyDetails;
130 // Create the object instance tracks for this process.
131 this.willAppendTracks_();
132 this.appendObjectInstanceTracks_();
133 this.appendCounterTracks_();
134 this.appendThreadTracks_();
135 this.didAppendTracks_();
138 addEventsToTrackMap: function(eventToTrackMap) {
139 this.tracks_.forEach(function(track) {
140 track.addEventsToTrackMap(eventToTrackMap);
144 willAppendTracks_: function() {
147 didAppendTracks_: function() {
150 appendObjectInstanceTracks_: function() {
151 var instancesByTypeName =
152 this.processBase_.objects.getAllInstancesByTypeName();
153 var instanceTypeNames = tv.dictionaryKeys(instancesByTypeName);
154 instanceTypeNames.sort();
156 var didAppendAtLeastOneTrack = false;
157 instanceTypeNames.forEach(function(typeName) {
158 var allInstances = instancesByTypeName[typeName];
160 // If a object snapshot has a view it will be shown,
161 // unless the view asked for it to not be shown.
162 var instanceViewInfo = ObjectInstanceView.getViewInfo(typeName);
163 var snapshotViewInfo = ObjectSnapshotView.getViewInfo(typeName);
164 if (instanceViewInfo && !instanceViewInfo.options.showInTrackView)
165 instanceViewInfo = undefined;
166 if (snapshotViewInfo && !snapshotViewInfo.options.showInTrackView)
167 snapshotViewInfo = undefined;
168 var hasViewInfo = instanceViewInfo || snapshotViewInfo;
170 // There are some instances that don't merit their own track in
171 // the UI. Filter them out.
172 var visibleInstances = [];
173 for (var i = 0; i < allInstances.length; i++) {
174 var instance = allInstances[i];
176 // Do not create tracks for instances that have no snapshots.
177 if (instance.snapshots.length === 0)
180 // Do not create tracks for instances that have implicit snapshots
181 // and don't have a view.
182 if (instance.hasImplicitSnapshots && !hasViewInfo)
185 visibleInstances.push(instance);
187 if (visibleInstances.length === 0)
190 // Look up the constructor for this track, or use the default
191 // constructor if none exists.
192 var trackConstructor =
193 tracing.tracks.ObjectInstanceTrack.getTrackConstructor(typeName);
194 if (!trackConstructor) {
195 var snapshotViewInfo = ObjectSnapshotView.getViewInfo(typeName);
196 if (snapshotViewInfo && snapshotViewInfo.options.showInstances) {
197 trackConstructor = tracing.tracks.ObjectInstanceGroupTrack;
199 trackConstructor = tracing.tracks.ObjectInstanceTrack;
202 var track = new trackConstructor(this.viewport);
203 track.objectInstances = visibleInstances;
204 this.appendChild(track);
205 didAppendAtLeastOneTrack = true;
207 if (didAppendAtLeastOneTrack)
208 this.appendChild(new SpacingTrack(this.viewport));
211 appendCounterTracks_: function() {
212 // Add counter tracks for this process.
213 var counters = tv.dictionaryValues(this.processBase.counters);
214 counters.sort(tracing.trace_model.Counter.compare);
216 // Create the counters for this process.
217 counters.forEach(function(counter) {
218 var track = new tracing.tracks.CounterTrack(this.viewport);
219 track.counter = counter;
220 this.appendChild(track);
221 this.appendChild(new SpacingTrack(this.viewport));
225 appendThreadTracks_: function() {
226 // Get a sorted list of threads.
227 var threads = tv.dictionaryValues(this.processBase.threads);
228 threads.sort(tracing.trace_model.Thread.compare);
230 // Create the threads.
231 threads.forEach(function(thread) {
232 var track = new tracing.tracks.ThreadTrack(this.viewport);
233 track.thread = thread;
234 if (!track.hasVisibleContent)
236 this.appendChild(track);
237 this.appendChild(new SpacingTrack(this.viewport));
243 ProcessTrackBase: ProcessTrackBase