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.require('tracing.tracks.container_track');
      8 base.require('tracing.tracks.slice_track');
      9 base.require('tracing.filter');
     10 base.require('tracing.trace_model');
     11 base.require('ui');
     12 
     13 base.exportTo('tracing.tracks', function() {
     14 
     15   /**
     16    * Visualizes a Cpu using a series of of SliceTracks.
     17    * @constructor
     18    */
     19   var CpuTrack =
     20       ui.define('cpu-track', tracing.tracks.ContainerTrack);
     21   CpuTrack.prototype = {
     22     __proto__: tracing.tracks.ContainerTrack.prototype,
     23 
     24     decorate: function(viewport) {
     25       tracing.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
     26       this.classList.add('cpu-track');
     27     },
     28 
     29     get cpu() {
     30       return this.cpu_;
     31     },
     32 
     33     set cpu(cpu) {
     34       this.cpu_ = cpu;
     35       this.updateContents_();
     36     },
     37 
     38     get tooltip() {
     39       return this.tooltip_;
     40     },
     41 
     42     set tooltip(value) {
     43       this.tooltip_ = value;
     44       this.updateContents_();
     45     },
     46 
     47     get hasVisibleContent() {
     48       return this.children.length > 0;
     49     },
     50 
     51     updateContents_: function() {
     52       this.detach();
     53       if (!this.cpu_)
     54         return;
     55       var slices = tracing.filterSliceArray(this.categoryFilter_,
     56                                             this.cpu_.slices);
     57       if (slices.length) {
     58         var track = new tracing.tracks.SliceTrack(this.viewport);
     59         track.slices = slices;
     60         track.heading = 'CPU ' + this.cpu_.cpuNumber + ':';
     61         this.appendChild(track);
     62       }
     63 
     64       for (var counterName in this.cpu_.counters) {
     65         var counter = this.cpu_.counters[counterName];
     66         if (!this.categoryFilter_.matchCounter(counter))
     67           return;
     68         track = new tracing.tracks.CounterTrack(this.viewport);
     69         track.heading = 'CPU ' + this.cpu_.cpuNumber + ' ' +
     70             counter.name + ':';
     71         track.counter = counter;
     72         track.categoryFilter = this.categoryFilter_;
     73         this.appendChild(track);
     74       }
     75     }
     76   };
     77 
     78   return {
     79     CpuTrack: CpuTrack
     80   };
     81 });
     82