Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / tracks / process_track_base.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
8 <link rel="stylesheet" href="/tracing/tracks/process_track_base.css">
9
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">
19
20 <script>
21 'use strict';
22
23 tv.exportTo('tracing.tracks', function() {
24
25   var ObjectSnapshotView = tracing.analysis.ObjectSnapshotView;
26   var ObjectInstanceView = tracing.analysis.ObjectInstanceView;
27   var TraceModelSettings = tracing.TraceModelSettings;
28   var SpacingTrack = tracing.tracks.SpacingTrack;
29
30   /**
31    * Visualizes a Process by building ThreadTracks and CounterTracks.
32    * @constructor
33    */
34   var ProcessTrackBase =
35       tv.ui.define('process-track-base', tracing.tracks.ContainerTrack);
36
37   ProcessTrackBase.prototype = {
38
39     __proto__: tracing.tracks.ContainerTrack.prototype,
40
41     decorate: function(viewport) {
42       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
43
44       this.processBase_ = undefined;
45
46       this.classList.add('process-track-base');
47       this.classList.add('expanded');
48
49       this.processNameEl_ = tv.ui.createSpan();
50       this.processNameEl_.classList.add('process-track-name');
51
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));
55
56       this.appendChild(this.headerEl_);
57     },
58
59     get processBase() {
60       return this.processBase_;
61     },
62
63     set processBase(processBase) {
64       this.processBase_ = processBase;
65
66       if (this.processBase_) {
67         var modelSettings = new TraceModelSettings(this.processBase_.model);
68         var defaultValue;
69         if (this.processBase_.labels !== undefined &&
70             this.processBase_.labels.length == 1 &&
71             this.processBase_.labels[0] == 'chrome://tracing') {
72           defaultValue = false;
73         } else {
74           defaultValue = true;
75         }
76         this.expanded = modelSettings.getSettingFor(
77             this.processBase_, 'expanded', defaultValue);
78       }
79
80       this.updateContents_();
81     },
82
83     get expanded() {
84       return this.classList.contains('expanded');
85     },
86
87     set expanded(expanded) {
88       expanded = !!expanded;
89
90       if (this.expanded === expanded)
91         return;
92
93       this.classList.toggle('expanded');
94
95       // Expanding and collapsing tracks is, essentially, growing and shrinking
96       // the viewport. We dispatch a change event to trigger any processing
97       // to happen.
98       this.viewport_.dispatchChangeEvent();
99
100       if (!this.processBase_)
101         return;
102
103       var modelSettings = new TraceModelSettings(this.processBase_.model);
104       modelSettings.setSettingFor(this.processBase_, 'expanded', expanded);
105     },
106
107     get hasVisibleContent() {
108       if (this.expanded)
109         return this.children.length > 1;
110       return true;
111     },
112
113     onHeaderClick_: function(e) {
114       e.stopPropagation();
115       e.preventDefault();
116       this.expanded = !this.expanded;
117     },
118
119     updateContents_: function() {
120       this.tracks_.forEach(function(track) {
121         this.removeChild(track);
122       }, this);
123
124       if (!this.processBase_)
125         return;
126
127       this.processNameEl_.textContent = this.processBase_.userFriendlyName;
128       this.headerEl_.title = this.processBase_.userFriendlyDetails;
129
130       // Create the object instance tracks for this process.
131       this.willAppendTracks_();
132       this.appendObjectInstanceTracks_();
133       this.appendCounterTracks_();
134       this.appendThreadTracks_();
135       this.didAppendTracks_();
136     },
137
138     addEventsToTrackMap: function(eventToTrackMap) {
139       this.tracks_.forEach(function(track) {
140         track.addEventsToTrackMap(eventToTrackMap);
141       });
142     },
143
144     willAppendTracks_: function() {
145     },
146
147     didAppendTracks_: function() {
148     },
149
150     appendObjectInstanceTracks_: function() {
151       var instancesByTypeName =
152           this.processBase_.objects.getAllInstancesByTypeName();
153       var instanceTypeNames = tv.dictionaryKeys(instancesByTypeName);
154       instanceTypeNames.sort();
155
156       var didAppendAtLeastOneTrack = false;
157       instanceTypeNames.forEach(function(typeName) {
158         var allInstances = instancesByTypeName[typeName];
159
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;
169
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];
175
176           // Do not create tracks for instances that have no snapshots.
177           if (instance.snapshots.length === 0)
178             continue;
179
180           // Do not create tracks for instances that have implicit snapshots
181           // and don't have a view.
182           if (instance.hasImplicitSnapshots && !hasViewInfo)
183             continue;
184
185           visibleInstances.push(instance);
186         }
187         if (visibleInstances.length === 0)
188           return;
189
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;
198           } else {
199             trackConstructor = tracing.tracks.ObjectInstanceTrack;
200           }
201         }
202         var track = new trackConstructor(this.viewport);
203         track.objectInstances = visibleInstances;
204         this.appendChild(track);
205         didAppendAtLeastOneTrack = true;
206       }, this);
207       if (didAppendAtLeastOneTrack)
208         this.appendChild(new SpacingTrack(this.viewport));
209     },
210
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);
215
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));
222       }.bind(this));
223     },
224
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);
229
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)
235           return;
236         this.appendChild(track);
237         this.appendChild(new SpacingTrack(this.viewport));
238       }.bind(this));
239     }
240   };
241
242   return {
243     ProcessTrackBase: ProcessTrackBase
244   };
245 });
246 </script>