Upstream version 9.37.197.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 tvcm.require('tvcm.iteration_helpers');
13
14 tvcm.exportTo('tracing.trace_model', function() {
15
16   var Cpu = tracing.trace_model.Cpu;
17   var ProcessBase = tracing.trace_model.ProcessBase;
18
19   /**
20    * The Kernel represents kernel-level objects in the
21    * model.
22    * @constructor
23    */
24   function Kernel(model) {
25     if (model === undefined)
26       throw new Error('model must be provided');
27     ProcessBase.call(this, model);
28     this.cpus = {};
29     this.softwareMeasuredCpuCount_ = undefined;
30   };
31
32   /**
33    * Comparison between kernels is pretty meaningless.
34    */
35   Kernel.compare = function(x, y) {
36     return 0;
37   };
38
39   Kernel.prototype = {
40     __proto__: ProcessBase.prototype,
41
42     compareTo: function(that) {
43       return Kernel.compare(this, that);
44     },
45
46     get userFriendlyName() {
47       return 'Kernel';
48     },
49
50     get userFriendlyDetails() {
51       return 'Kernel';
52     },
53
54     /**
55      * @return {Cpu} Gets a specific Cpu or creates one if
56      * it does not exist.
57      */
58     getOrCreateCpu: function(cpuNumber) {
59       if (!this.cpus[cpuNumber])
60         this.cpus[cpuNumber] = new Cpu(this, cpuNumber);
61       return this.cpus[cpuNumber];
62     },
63
64     get softwareMeasuredCpuCount() {
65       return this.softwareMeasuredCpuCount_;
66     },
67
68     set softwareMeasuredCpuCount(softwareMeasuredCpuCount) {
69       if (this.softwareMeasuredCpuCount_ !== undefined &&
70           this.softwareMeasuredCpuCount_ !== softwareMeasuredCpuCount) {
71         throw new Error(
72             'Cannot change the softwareMeasuredCpuCount once it is set');
73       }
74
75       this.softwareMeasuredCpuCount_ = softwareMeasuredCpuCount;
76     },
77
78     /**
79      * Estimates how many cpus are in the system, for use in system load
80      * estimation.
81      *
82      * If kernel trace was provided, uses that data. Otherwise, uses the
83      * software measured cpu count.
84      */
85     get bestGuessAtCpuCount() {
86       var realCpuCount = tvcm.dictionaryLength(this.cpus);
87       if (realCpuCount !== 0)
88         return realCpuCount;
89       return this.softwareMeasuredCpuCount;
90     },
91
92     shiftTimestampsForward: function(amount) {
93       ProcessBase.prototype.shiftTimestampsForward.call(this);
94       for (var cpuNumber in this.cpus)
95         this.cpus[cpuNumber].shiftTimestampsForward(amount);
96     },
97
98     updateBounds: function() {
99       ProcessBase.prototype.updateBounds.call(this);
100       for (var cpuNumber in this.cpus) {
101         var cpu = this.cpus[cpuNumber];
102         cpu.updateBounds();
103         this.bounds.addRange(cpu.bounds);
104       }
105     },
106
107     createSubSlices: function() {
108       ProcessBase.prototype.createSubSlices.call(this);
109       for (var cpuNumber in this.cpus) {
110         var cpu = this.cpus[cpuNumber];
111         cpu.createSubSlices();
112       }
113     },
114
115     addCategoriesToDict: function(categoriesDict) {
116       ProcessBase.prototype.addCategoriesToDict.call(this, categoriesDict);
117       for (var cpuNumber in this.cpus)
118         this.cpus[cpuNumber].addCategoriesToDict(categoriesDict);
119     },
120
121     getSettingsKey: function() {
122       return 'kernel';
123     },
124
125     iterateAllEvents: function(callback, opt_this) {
126       for (var cpuNumber in this.cpus)
127         this.cpus[cpuNumber].iterateAllEvents(callback, opt_this);
128
129       ProcessBase.prototype.iterateAllEvents.call(this, callback, opt_this);
130     }
131   };
132
133   return {
134     Kernel: Kernel
135   };
136 });