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 Process class.
10 tvcm.require('tracing.trace_model.process_base');
11 tvcm.exportTo('tracing.trace_model', function() {
13 var ProcessBase = tracing.trace_model.ProcessBase;
16 * The Process represents a single userland process in the
20 function Process(model, pid) {
21 if (model === undefined)
22 throw new Error('model must be provided');
23 if (pid === undefined)
24 throw new Error('pid must be provided');
25 tracing.trace_model.ProcessBase.call(this, model);
27 this.name = undefined;
29 this.instantEvents = [];
33 * Comparison between processes that orders by pid.
35 Process.compare = function(x, y) {
36 var tmp = tracing.trace_model.ProcessBase.compare(x, y);
40 tmp = tvcm.comparePossiblyUndefinedValues(
42 function(x, y) { return x.localeCompare(y); });
46 tmp = tvcm.compareArrays(x.labels, y.labels,
47 function(x, y) { return x.localeCompare(y); });
55 __proto__: tracing.trace_model.ProcessBase.prototype,
57 compareTo: function(that) {
58 return Process.compare(this, that);
61 pushInstantEvent: function(instantEvent) {
62 this.instantEvents.push(instantEvent);
65 addLabelIfNeeded: function(labelName) {
66 for (var i = 0; i < this.labels.length; i++) {
67 if (this.labels[i] === labelName)
70 this.labels.push(labelName);
73 get userFriendlyName() {
76 res = this.name + ' (pid ' + this.pid + ')';
78 res = 'Process ' + this.pid;
79 if (this.labels.length)
80 res += ': ' + this.labels.join(', ');
84 get userFriendlyDetails() {
86 return this.name + ' (pid ' + this.pid + ')';
87 return 'pid: ' + this.pid;
90 getSettingsKey: function() {
93 if (!this.labels.length)
94 return 'processes.' + this.name;
95 return 'processes.' + this.name + '.' + this.labels.join('.');
98 shiftTimestampsForward: function(amount) {
99 for (var id in this.instantEvents)
100 this.instantEvents[id].start += amount;
102 tracing.trace_model.ProcessBase.prototype
103 .shiftTimestampsForward.apply(this, arguments);
106 iterateAllEvents: function(callback, opt_this) {
107 this.instantEvents.forEach(callback, opt_this);
109 ProcessBase.prototype.iterateAllEvents.call(this, callback, opt_this);