Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / tracks / thread_track.js
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 tvcm.requireStylesheet('tracing.tracks.thread_track');
8
9 tvcm.require('tracing.tracks.container_track');
10 tvcm.require('tracing.tracks.slice_track');
11 tvcm.require('tracing.tracks.slice_group_track');
12 tvcm.require('tracing.tracks.async_slice_group_track');
13 tvcm.require('tracing.filter');
14 tvcm.require('tvcm.ui');
15
16 tvcm.exportTo('tracing.tracks', function() {
17
18   /**
19    * Visualizes a Thread using a series of of SliceTracks.
20    * @constructor
21    */
22   var ThreadTrack = tvcm.ui.define('thread-track',
23                                    tracing.tracks.ContainerTrack);
24   ThreadTrack.prototype = {
25     __proto__: tracing.tracks.ContainerTrack.prototype,
26
27     decorate: function(viewport) {
28       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
29       this.classList.add('thread-track');
30     },
31
32     get thread() {
33       return this.thread_;
34     },
35
36     set thread(thread) {
37       this.thread_ = thread;
38       this.updateContents_();
39     },
40
41     get hasVisibleContent() {
42       return this.tracks_.length > 0;
43     },
44
45     updateContents_: function() {
46       this.detach();
47
48       if (!this.thread_)
49         return;
50
51       this.heading = this.thread_.userFriendlyName + ': ';
52       this.tooltip = this.thread_.userFriendlyDetails;
53
54       if (this.thread_.asyncSliceGroup.length) {
55         var asyncTrack = new tracing.tracks.AsyncSliceGroupTrack(this.viewport);
56         asyncTrack.group = this.thread_.asyncSliceGroup;
57         if (asyncTrack.hasVisibleContent)
58           this.appendChild(asyncTrack);
59       }
60
61       if (this.thread_.samples.length) {
62         var samplesTrack = new tracing.tracks.SliceTrack(this.viewport);
63         samplesTrack.group = this.thread_;
64         samplesTrack.slices = this.thread_.samples;
65         samplesTrack.heading = this.thread_.userFriendlyName;
66         samplesTrack.tooltip = this.thread_.userFriendlyDetails;
67         samplesTrack.selectionGenerator = function() {
68           var selection = new tracing.Selection();
69           for (var i = 0; i < samplesTrack.slices.length; i++) {
70             selection.push(samplesTrack.slices[i]);
71           }
72           return selection;
73         };
74         this.appendChild(samplesTrack);
75       }
76
77       if (this.thread_.timeSlices) {
78         var timeSlicesTrack = new tracing.tracks.SliceTrack(this.viewport);
79         timeSlicesTrack.heading = '';
80         timeSlicesTrack.height = '4px';
81         timeSlicesTrack.slices = this.thread_.timeSlices;
82         if (timeSlicesTrack.hasVisibleContent)
83           this.appendChild(timeSlicesTrack);
84       }
85
86       if (this.thread_.sliceGroup.length) {
87         var track = new tracing.tracks.SliceGroupTrack(this.viewport);
88         track.heading = this.thread_.userFriendlyName;
89         track.tooltip = this.thread_.userFriendlyDetails;
90         track.group = this.thread_.sliceGroup;
91         if (track.hasVisibleContent)
92           this.appendChild(track);
93       }
94     },
95
96     collapsedDidChange: function(collapsed) {
97       if (collapsed) {
98         var h = parseInt(this.tracks[0].height);
99         for (var i = 0; i < this.tracks.length; ++i) {
100           if (h > 2) {
101             this.tracks[i].height = Math.floor(h) + 'px';
102           } else {
103             this.tracks[i].style.display = 'none';
104           }
105           h = h * 0.5;
106         }
107       } else {
108         for (var i = 0; i < this.tracks.length; ++i) {
109           this.tracks[i].height = this.tracks[0].height;
110           this.tracks[i].style.display = '';
111         }
112       }
113     }
114   };
115
116   return {
117     ThreadTrack: ThreadTrack
118   };
119 });