Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / process.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
8 <link rel="import" href="/tracing/trace_model/process_base.html">
9
10 <script>
11 'use strict';
12
13 /**
14  * @fileoverview Provides the Process class.
15  */
16 tv.exportTo('tracing.trace_model', function() {
17   var ProcessBase = tracing.trace_model.ProcessBase;
18
19   /**
20    * The Process represents a single userland process in the
21    * trace.
22    * @constructor
23    */
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);
30     this.pid = pid;
31     this.name = undefined;
32     this.labels = [];
33     this.instantEvents = [];
34   };
35
36   /**
37    * Comparison between processes that orders by pid.
38    */
39   Process.compare = function(x, y) {
40     var tmp = tracing.trace_model.ProcessBase.compare(x, y);
41     if (tmp)
42       return tmp;
43
44     tmp = tv.comparePossiblyUndefinedValues(
45         x.name, y.name,
46         function(x, y) { return x.localeCompare(y); });
47     if (tmp)
48       return tmp;
49
50     tmp = tv.compareArrays(x.labels, y.labels,
51         function(x, y) { return x.localeCompare(y); });
52     if (tmp)
53       return tmp;
54
55     return x.pid - y.pid;
56   };
57
58   Process.prototype = {
59     __proto__: tracing.trace_model.ProcessBase.prototype,
60
61     compareTo: function(that) {
62       return Process.compare(this, that);
63     },
64
65     pushInstantEvent: function(instantEvent) {
66       this.instantEvents.push(instantEvent);
67     },
68
69     addLabelIfNeeded: function(labelName) {
70       for (var i = 0; i < this.labels.length; i++) {
71         if (this.labels[i] === labelName)
72           return;
73       }
74       this.labels.push(labelName);
75     },
76
77     get userFriendlyName() {
78       var res;
79       if (this.name)
80         res = this.name + ' (pid ' + this.pid + ')';
81       else
82         res = 'Process ' + this.pid;
83       if (this.labels.length)
84         res += ': ' + this.labels.join(', ');
85       return res;
86     },
87
88     get userFriendlyDetails() {
89       if (this.name)
90         return this.name + ' (pid ' + this.pid + ')';
91       return 'pid: ' + this.pid;
92     },
93
94     getSettingsKey: function() {
95       if (!this.name)
96         return undefined;
97       if (!this.labels.length)
98         return 'processes.' + this.name;
99       return 'processes.' + this.name + '.' + this.labels.join('.');
100     },
101
102     shiftTimestampsForward: function(amount) {
103       for (var id in this.instantEvents)
104         this.instantEvents[id].start += amount;
105
106       tracing.trace_model.ProcessBase.prototype
107           .shiftTimestampsForward.apply(this, arguments);
108     },
109
110     iterateAllEvents: function(callback, opt_this) {
111       this.instantEvents.forEach(callback, opt_this);
112
113       ProcessBase.prototype.iterateAllEvents.call(this, callback, opt_this);
114     }
115   };
116
117   return {
118     Process: Process
119   };
120 });
121 </script>
122