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 TimelineProcess class. 9 */ 10 base.require('timeline_thread'); 11 base.require('timeline_counter'); 12 base.exportTo('tracing', function() { 13 14 var TimelineThread = tracing.TimelineThread; 15 var TimelineCounter = tracing.TimelineCounter; 16 17 /** 18 * The TimelineProcess represents a single process in the 19 * trace. Right now, we keep this around purely for bookkeeping 20 * reasons. 21 * @constructor 22 */ 23 function TimelineProcess(pid) { 24 this.pid = pid; 25 this.threads = {}; 26 this.counters = {}; 27 }; 28 29 TimelineProcess.prototype = { 30 get numThreads() { 31 var n = 0; 32 for (var p in this.threads) { 33 n++; 34 } 35 return n; 36 }, 37 38 /** 39 * Shifts all the timestamps inside this process forward by the amount 40 * specified. 41 */ 42 shiftTimestampsForward: function(amount) { 43 for (var tid in this.threads) 44 this.threads[tid].shiftTimestampsForward(amount); 45 for (var id in this.counters) 46 this.counters[id].shiftTimestampsForward(amount); 47 }, 48 49 /** 50 * @return {TimlineThread} The thread identified by tid on this process, 51 * creating it if it doesn't exist. 52 */ 53 getOrCreateThread: function(tid) { 54 if (!this.threads[tid]) 55 this.threads[tid] = new TimelineThread(this, tid); 56 return this.threads[tid]; 57 }, 58 59 /** 60 * @return {TimlineCounter} The counter on this process named 'name', 61 * creating it if it doesn't exist. 62 */ 63 getOrCreateCounter: function(cat, name) { 64 var id = cat + '.' + name; 65 if (!this.counters[id]) 66 this.counters[id] = new TimelineCounter(this, id, cat, name); 67 return this.counters[id]; 68 } 69 }; 70 71 /** 72 * Comparison between processes that orders by pid. 73 */ 74 TimelineProcess.compare = function(x, y) { 75 return x.pid - y.pid; 76 }; 77 78 return { 79 TimelineProcess: TimelineProcess 80 }; 81 }); 82