Home | History | Annotate | Download | only in tracks
      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('tracing.tracks.thread_track');
      8 
      9 base.require('tracing.tracks.container_track');
     10 base.require('tracing.tracks.slice_track');
     11 base.require('tracing.tracks.slice_group_track');
     12 base.require('tracing.tracks.async_slice_group_track');
     13 base.require('tracing.filter');
     14 base.require('ui');
     15 
     16 base.exportTo('tracing.tracks', function() {
     17 
     18   /**
     19    * Visualizes a Thread using a series of of SliceTracks.
     20    * @constructor
     21    */
     22   var ThreadTrack = ui.define('thread-track', tracing.tracks.ContainerTrack);
     23   ThreadTrack.prototype = {
     24     __proto__: tracing.tracks.ContainerTrack.prototype,
     25 
     26     decorate: function(viewport) {
     27       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
     28       this.classList.add('thread-track');
     29     },
     30 
     31     get thread() {
     32       return this.thread_;
     33     },
     34 
     35     set thread(thread) {
     36       this.thread_ = thread;
     37       this.updateContents_();
     38     },
     39 
     40     get hasVisibleContent() {
     41       return this.tracks_.length > 0;
     42     },
     43 
     44     updateContents_: function() {
     45       this.detach();
     46 
     47       if (!this.thread_)
     48         return;
     49 
     50       this.heading = this.thread_.userFriendlyName + ': ';
     51       this.tooltip = this.thread_.userFriendlyDetails;
     52 
     53       if (this.thread_.asyncSliceGroup.length) {
     54         var asyncTrack = new tracing.tracks.AsyncSliceGroupTrack(this.viewport);
     55         asyncTrack.categoryFilter = this.categoryFilter;
     56         asyncTrack.decorateHit = function(hit) {
     57           // TODO(simonjam): figure out how to associate subSlice hits back
     58           // to their parent slice.
     59         };
     60         asyncTrack.group = this.thread_.asyncSliceGroup;
     61         if (asyncTrack.hasVisibleContent)
     62           this.appendChild(asyncTrack);
     63       }
     64 
     65       if (this.thread_.samples.length) {
     66         var samplesTrack = new tracing.tracks.SliceTrack(this.viewport);
     67         samplesTrack.categoryFilter = samplesTrack;
     68         samplesTrack.group = this.thread_;
     69         samplesTrack.slices = this.thread_.samples;
     70         samplesTrack.decorateHit = function(hit) {
     71           // TODO(johnmccutchan): Figure out what else should be associated
     72           // with the hit.
     73           hit.thread = this.thread_;
     74         }
     75         this.appendChild(samplesTrack);
     76       }
     77 
     78       if (this.thread_.cpuSlices) {
     79         var cpuTrack = new tracing.tracks.SliceTrack(this.viewport);
     80         cpuTrack.categoryFilter = this.categoryFilter;
     81         cpuTrack.heading = '';
     82         cpuTrack.height = '4px';
     83         cpuTrack.decorateHit = function(hit) {
     84           hit.thread = this.thread_;
     85         }
     86         cpuTrack.slices = this.thread_.cpuSlices;
     87         if (cpuTrack.hasVisibleContent)
     88           this.appendChild(cpuTrack);
     89       }
     90 
     91       if (this.thread_.sliceGroup.length) {
     92         var track = new tracing.tracks.SliceGroupTrack(this.viewport);
     93         track.categoryFilter = this.categoryFilter;
     94         track.heading = this.thread_.userFriendlyName;
     95         track.tooltip = this.thread_.userFriendlyDetails;
     96 
     97         track.decorateHit = function(hit) {
     98           hit.thread = this.thread_;
     99         };
    100         track.group = this.thread_.sliceGroup;
    101         if (track.hasVisibleContent)
    102           this.appendChild(track);
    103       }
    104     },
    105 
    106     collapsedDidChange: function(collapsed) {
    107       if (collapsed) {
    108         var h = parseInt(this.tracks[0].height);
    109         for (var i = 0; i < this.tracks.length; ++i) {
    110           if (h > 2) {
    111             this.tracks[i].height = Math.floor(h) + 'px';
    112           } else {
    113             this.tracks[i].style.display = 'none';
    114           }
    115           h = h * 0.5;
    116         }
    117       } else {
    118         for (var i = 0; i < this.tracks.length; ++i) {
    119           this.tracks[i].height = this.tracks[0].height;
    120           this.tracks[i].style.display = '';
    121         }
    122       }
    123     }
    124   };
    125 
    126   return {
    127     ThreadTrack: ThreadTrack
    128   };
    129 });
    130