3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/trace_model/process_base.html">
14 * @fileoverview Provides the Process class.
16 tv.exportTo('tracing.trace_model', function() {
17 var ProcessBase = tracing.trace_model.ProcessBase;
20 * The Process represents a single userland process in the
24 function Process(model, pid) {
25 if (model === undefined)
26 throw new Error('model must be provided');
27 if (pid === undefined)
28 throw new Error('pid must be provided');
29 tracing.trace_model.ProcessBase.call(this, model);
31 this.name = undefined;
33 this.instantEvents = [];
37 * Comparison between processes that orders by pid.
39 Process.compare = function(x, y) {
40 var tmp = tracing.trace_model.ProcessBase.compare(x, y);
44 tmp = tv.comparePossiblyUndefinedValues(
46 function(x, y) { return x.localeCompare(y); });
50 tmp = tv.compareArrays(x.labels, y.labels,
51 function(x, y) { return x.localeCompare(y); });
59 __proto__: tracing.trace_model.ProcessBase.prototype,
61 compareTo: function(that) {
62 return Process.compare(this, that);
65 pushInstantEvent: function(instantEvent) {
66 this.instantEvents.push(instantEvent);
69 addLabelIfNeeded: function(labelName) {
70 for (var i = 0; i < this.labels.length; i++) {
71 if (this.labels[i] === labelName)
74 this.labels.push(labelName);
77 get userFriendlyName() {
80 res = this.name + ' (pid ' + this.pid + ')';
82 res = 'Process ' + this.pid;
83 if (this.labels.length)
84 res += ': ' + this.labels.join(', ');
88 get userFriendlyDetails() {
90 return this.name + ' (pid ' + this.pid + ')';
91 return 'pid: ' + this.pid;
94 getSettingsKey: function() {
97 if (!this.labels.length)
98 return 'processes.' + this.name;
99 return 'processes.' + this.name + '.' + this.labels.join('.');
102 shiftTimestampsForward: function(amount) {
103 for (var id in this.instantEvents)
104 this.instantEvents[id].start += amount;
106 tracing.trace_model.ProcessBase.prototype
107 .shiftTimestampsForward.apply(this, arguments);
110 iterateAllEvents: function(callback, opt_this) {
111 this.instantEvents.forEach(callback, opt_this);
113 ProcessBase.prototype.iterateAllEvents.call(this, callback, opt_this);