Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / tracks / thread_track.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/thread_track.css">
9
10 <link rel="import" href="/tracing/tracks/container_track.html">
11 <link rel="import" href="/tracing/tracks/sample_track.html">
12 <link rel="import" href="/tracing/tracks/slice_track.html">
13 <link rel="import" href="/tracing/tracks/slice_group_track.html">
14 <link rel="import" href="/tracing/tracks/async_slice_group_track.html">
15 <link rel="import" href="/tracing/filter.html">
16 <link rel="import" href="/tvcm/ui.html">
17 <link rel="import" href="/tvcm/iteration_helpers.html">
18
19 <script>
20 'use strict';
21
22 tvcm.exportTo('tracing.tracks', function() {
23   /**
24    * Visualizes a Thread using a series of of SliceTracks.
25    * @constructor
26    */
27   var ThreadTrack = tvcm.ui.define('thread-track',
28                                    tracing.tracks.ContainerTrack);
29   ThreadTrack.prototype = {
30     __proto__: tracing.tracks.ContainerTrack.prototype,
31
32     decorate: function(viewport) {
33       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
34       this.classList.add('thread-track');
35     },
36
37     get thread() {
38       return this.thread_;
39     },
40
41     set thread(thread) {
42       this.thread_ = thread;
43       this.updateContents_();
44     },
45
46     get hasVisibleContent() {
47       return this.tracks_.length > 0;
48     },
49
50     updateContents_: function() {
51       this.detach();
52
53       if (!this.thread_)
54         return;
55
56       this.heading = this.thread_.userFriendlyName + ': ';
57       this.tooltip = this.thread_.userFriendlyDetails;
58
59       if (this.thread_.asyncSliceGroup.length)
60         this.appendAsyncSliceTracks_();
61
62       this.appendThreadSamplesTracks_();
63
64       if (this.thread_.timeSlices) {
65         var timeSlicesTrack = new tracing.tracks.SliceTrack(this.viewport);
66         timeSlicesTrack.heading = '';
67         timeSlicesTrack.height = tracing.THIN_SLICE_HEIGHT + 'px';
68         timeSlicesTrack.slices = this.thread_.timeSlices;
69         if (timeSlicesTrack.hasVisibleContent)
70           this.appendChild(timeSlicesTrack);
71       }
72
73       if (this.thread_.sliceGroup.length) {
74         var track = new tracing.tracks.SliceGroupTrack(this.viewport);
75         track.heading = this.thread_.userFriendlyName;
76         track.tooltip = this.thread_.userFriendlyDetails;
77         track.group = this.thread_.sliceGroup;
78         if (track.hasVisibleContent)
79           this.appendChild(track);
80       }
81     },
82
83     appendAsyncSliceTracks_: function() {
84       var subGroups = this.thread_.asyncSliceGroup.titleSubGroups;
85       subGroups.forEach(function(subGroup) {
86         var asyncTrack = new tracing.tracks.AsyncSliceGroupTrack(this.viewport);
87         var title = subGroup.slices[0].title;
88         asyncTrack.group = subGroup;
89         asyncTrack.heading = title;
90         if (asyncTrack.hasVisibleContent)
91           this.appendChild(asyncTrack);
92       }, this);
93     },
94
95     appendThreadSamplesTracks_: function() {
96       var threadSamples = this.thread_.samples;
97       if (threadSamples === undefined || threadSamples.length === 0)
98         return;
99       var samplesByTitle = {};
100       threadSamples.forEach(function(sample) {
101         if (samplesByTitle[sample.title] === undefined)
102           samplesByTitle[sample.title] = [];
103         samplesByTitle[sample.title].push(sample);
104       });
105
106       var sampleTitles = tvcm.dictionaryKeys(samplesByTitle);
107       sampleTitles.sort();
108
109       sampleTitles.forEach(function(sampleTitle) {
110         var samples = samplesByTitle[sampleTitle];
111         var samplesTrack = new tracing.tracks.SampleTrack(this.viewport);
112         samplesTrack.group = this.thread_;
113         samplesTrack.samples = samples;
114         samplesTrack.heading = this.thread_.userFriendlyName + ': ' +
115             sampleTitle;
116         samplesTrack.tooltip = this.thread_.userFriendlyDetails;
117         samplesTrack.selectionGenerator = function() {
118           var selection = new tracing.Selection();
119           for (var i = 0; i < samplesTrack.samples.length; i++) {
120             selection.push(samplesTrack.samples[i]);
121           }
122           return selection;
123         };
124         this.appendChild(samplesTrack);
125       }, this);
126     },
127
128     collapsedDidChange: function(collapsed) {
129       if (collapsed) {
130         var h = parseInt(this.tracks[0].height);
131         for (var i = 0; i < this.tracks.length; ++i) {
132           if (h > 2) {
133             this.tracks[i].height = Math.floor(h) + 'px';
134           } else {
135             this.tracks[i].style.display = 'none';
136           }
137           h = h * 0.5;
138         }
139       } else {
140         for (var i = 0; i < this.tracks.length; ++i) {
141           this.tracks[i].height = this.tracks[0].height;
142           this.tracks[i].style.display = '';
143         }
144       }
145     }
146   };
147
148   return {
149     ThreadTrack: ThreadTrack
150   };
151 });
152 </script>