Home | History | Annotate | Download | only in src
      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 /**
      8  * @fileoverview Provides the TimelineCpu class.
      9  */
     10 base.require('timeline_slice');
     11 base.require('timeline_counter');
     12 base.exportTo('tracing', function() {
     13 
     14   var TimelineCounter = tracing.TimelineCounter;
     15 
     16   /**
     17    * The TimelineCpu represents a Cpu from the kernel's point of view.
     18    * @constructor
     19    */
     20   function TimelineCpu(number) {
     21     this.cpuNumber = number;
     22     this.slices = [];
     23     this.counters = {};
     24   };
     25 
     26   TimelineCpu.prototype = {
     27     /**
     28      * @return {TimlineCounter} The counter on this process named 'name',
     29      * creating it if it doesn't exist.
     30      */
     31     getOrCreateCounter: function(cat, name) {
     32       var id;
     33       if (cat.length)
     34         id = cat + '.' + name;
     35       else
     36         id = name;
     37       if (!this.counters[id])
     38         this.counters[id] = new TimelineCounter(this, id, cat, name);
     39       return this.counters[id];
     40     },
     41 
     42     /**
     43      * Shifts all the timestamps inside this CPU forward by the amount
     44      * specified.
     45      */
     46     shiftTimestampsForward: function(amount) {
     47       for (var sI = 0; sI < this.slices.length; sI++)
     48         this.slices[sI].start = (this.slices[sI].start + amount);
     49       for (var id in this.counters)
     50         this.counters[id].shiftTimestampsForward(amount);
     51     },
     52 
     53     /**
     54      * Updates the minTimestamp and maxTimestamp fields based on the
     55      * current slices attached to the cpu.
     56      */
     57     updateBounds: function() {
     58       var values = [];
     59       if (this.slices.length) {
     60         this.minTimestamp = this.slices[0].start;
     61         this.maxTimestamp = this.slices[this.slices.length - 1].end;
     62       } else {
     63         this.minTimestamp = undefined;
     64         this.maxTimestamp = undefined;
     65       }
     66     }
     67   };
     68 
     69   /**
     70    * Comparison between processes that orders by cpuNumber.
     71    */
     72   TimelineCpu.compare = function(x, y) {
     73     return x.cpuNumber - y.cpuNumber;
     74   };
     75 
     76 
     77   return {
     78     TimelineCpu: TimelineCpu
     79   };
     80 });
     81