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.
8 * @fileoverview Provides the ProcessBase class.
10 tvcm.require('tvcm.guid');
11 tvcm.require('tvcm.range');
12 tvcm.require('tracing.trace_model.counter');
13 tvcm.require('tracing.trace_model.object_collection');
14 tvcm.require('tracing.trace_model.thread');
15 tvcm.require('tracing.trace_model_settings');
16 tvcm.exportTo('tracing.trace_model', function() {
18 var Thread = tracing.trace_model.Thread;
19 var Counter = tracing.trace_model.Counter;
22 * The ProcessBase is a partial base class, upon which Kernel
23 * and Process are built.
27 function ProcessBase(model) {
29 throw new Error('Must provide a model');
30 this.guid_ = tvcm.GUID.allocate();
34 this.objects = new tracing.trace_model.ObjectCollection(this);
35 this.bounds = new tvcm.Range();
37 this.ephemeralSettings = {};
40 ProcessBase.compare = function(x, y) {
41 return x.sortIndex - y.sortIndex;
44 ProcessBase.prototype = {
46 * @return {Number} A globally unique identifier for this counter.
53 * Gets the number of threads in this process.
57 for (var p in this.threads) {
64 var obj = new Object();
65 var keys = Object.keys(this);
66 for (var i = 0; i < keys.length; i++) {
68 if (typeof this[key] == 'function')
78 * Shifts all the timestamps inside this process forward by the amount
81 shiftTimestampsForward: function(amount) {
82 for (var tid in this.threads)
83 this.threads[tid].shiftTimestampsForward(amount);
84 for (var id in this.counters)
85 this.counters[id].shiftTimestampsForward(amount);
86 this.objects.shiftTimestampsForward(amount);
90 * Closes any open slices.
92 autoCloseOpenSlices: function(opt_maxTimestamp) {
93 for (var tid in this.threads) {
94 var thread = this.threads[tid];
95 thread.autoCloseOpenSlices(opt_maxTimestamp);
99 autoDeleteObjects: function(maxTimestamp) {
100 this.objects.autoDeleteObjects(maxTimestamp);
104 * Called by the model after finalizing imports,
105 * but before joining refs.
107 preInitializeObjects: function() {
108 this.objects.preInitializeAllObjects();
112 * Called by the model after joining refs.
114 initializeObjects: function() {
115 this.objects.initializeAllObjects();
119 * Merge slices from the kernel with those from userland for each thread.
121 mergeKernelWithUserland: function() {
122 for (var tid in this.threads) {
123 var thread = this.threads[tid];
124 thread.mergeKernelWithUserland();
128 updateBounds: function() {
130 for (var tid in this.threads) {
131 this.threads[tid].updateBounds();
132 this.bounds.addRange(this.threads[tid].bounds);
134 for (var id in this.counters) {
135 this.counters[id].updateBounds();
136 this.bounds.addRange(this.counters[id].bounds);
138 this.objects.updateBounds();
139 this.bounds.addRange(this.objects.bounds);
142 addCategoriesToDict: function(categoriesDict) {
143 for (var tid in this.threads)
144 this.threads[tid].addCategoriesToDict(categoriesDict);
145 for (var id in this.counters)
146 categoriesDict[this.counters[id].category] = true;
147 this.objects.addCategoriesToDict(categoriesDict);
151 * @param {String} The name of the thread to find.
152 * @return {Array} An array of all the matched threads.
154 findAllThreadsNamed: function(name) {
155 var namedThreads = [];
156 for (var tid in this.threads) {
157 var thread = this.threads[tid];
158 if (thread.name == name)
159 namedThreads.push(thread);
165 * Removes threads from the process that are fully empty.
167 pruneEmptyContainers: function() {
168 var threadsToKeep = {};
169 for (var tid in this.threads) {
170 var thread = this.threads[tid];
172 threadsToKeep[tid] = thread;
174 this.threads = threadsToKeep;
178 * @return {TimelineThread} The thread identified by tid on this process,
179 * creating it if it doesn't exist.
181 getOrCreateThread: function(tid) {
182 if (!this.threads[tid])
183 this.threads[tid] = new Thread(this, tid);
184 return this.threads[tid];
188 * @return {TimelineCounter} The counter on this process named 'name',
189 * creating it if it doesn't exist.
191 getOrCreateCounter: function(cat, name) {
192 var id = cat + '.' + name;
193 if (!this.counters[id])
194 this.counters[id] = new Counter(this, id, cat, name);
195 return this.counters[id];
198 getSettingsKey: function() {
199 throw new Error('Not implemented');
202 iterateAllEvents: function(callback) {
203 for (var tid in this.threads)
204 this.threads[tid].iterateAllEvents(callback);
206 for (var id in this.counters)
207 this.counters[id].iterateAllEvents(callback);
209 this.objects.iterateAllEvents(callback);
214 ProcessBase: ProcessBase