Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / kernel.js
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 Process class.
9  */
10 tvcm.require('tracing.trace_model.cpu');
11 tvcm.require('tracing.trace_model.process_base');
12
13 tvcm.exportTo('tracing.trace_model', function() {
14
15   var Cpu = tracing.trace_model.Cpu;
16   var ProcessBase = tracing.trace_model.ProcessBase;
17
18   /**
19    * The Kernel represents kernel-level objects in the
20    * model.
21    * @constructor
22    */
23   function Kernel(model) {
24     if (model === undefined)
25       throw new Error('model must be provided');
26     ProcessBase.call(this, model);
27     this.cpus = {};
28   };
29
30   /**
31    * Comparison between kernels is pretty meaningless.
32    */
33   Kernel.compare = function(x, y) {
34     return 0;
35   };
36
37   Kernel.prototype = {
38     __proto__: ProcessBase.prototype,
39
40     compareTo: function(that) {
41       return Kernel.compare(this, that);
42     },
43
44     get userFriendlyName() {
45       return 'Kernel';
46     },
47
48     get userFriendlyDetails() {
49       return 'Kernel';
50     },
51
52     /**
53      * @return {Cpu} Gets a specific Cpu or creates one if
54      * it does not exist.
55      */
56     getOrCreateCpu: function(cpuNumber) {
57       if (!this.cpus[cpuNumber])
58         this.cpus[cpuNumber] = new Cpu(this, cpuNumber);
59       return this.cpus[cpuNumber];
60     },
61
62     shiftTimestampsForward: function(amount) {
63       ProcessBase.prototype.shiftTimestampsForward.call(this);
64       for (var cpuNumber in this.cpus)
65         this.cpus[cpuNumber].shiftTimestampsForward(amount);
66     },
67
68     updateBounds: function() {
69       ProcessBase.prototype.updateBounds.call(this);
70       for (var cpuNumber in this.cpus) {
71         var cpu = this.cpus[cpuNumber];
72         cpu.updateBounds();
73         this.bounds.addRange(cpu.bounds);
74       }
75     },
76
77     createSubSlices: function() {
78       ProcessBase.prototype.createSubSlices.call(this);
79       for (var cpuNumber in this.cpus) {
80         var cpu = this.cpus[cpuNumber];
81         cpu.createSubSlices();
82       }
83     },
84
85     addCategoriesToDict: function(categoriesDict) {
86       ProcessBase.prototype.addCategoriesToDict.call(this, categoriesDict);
87       for (var cpuNumber in this.cpus)
88         this.cpus[cpuNumber].addCategoriesToDict(categoriesDict);
89     },
90
91     getSettingsKey: function() {
92       return 'kernel';
93     },
94
95     iterateAllEvents: function(callback, opt_this) {
96       for (var cpuNumber in this.cpus)
97         this.cpus[cpuNumber].iterateAllEvents(callback, opt_this);
98
99       ProcessBase.prototype.iterateAllEvents.call(this, callback, opt_this);
100     }
101   };
102
103   return {
104     Kernel: Kernel
105   };
106 });