Chris Craik | 93216d0 | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 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="/core/trace_model/cpu.html"> |
| 9 | <link rel="import" href="/core/trace_model/process_base.html"> |
| 10 | <link rel="import" href="/base/iteration_helpers.html"> |
| 11 | |
| 12 | <script> |
| 13 | 'use strict'; |
| 14 | |
| 15 | /** |
| 16 | * @fileoverview Provides the Process class. |
| 17 | */ |
| 18 | tv.exportTo('tv.c.trace_model', function() { |
| 19 | var Cpu = tv.c.trace_model.Cpu; |
| 20 | var ProcessBase = tv.c.trace_model.ProcessBase; |
| 21 | |
| 22 | /** |
| 23 | * The Kernel represents kernel-level objects in the |
| 24 | * model. |
| 25 | * @constructor |
| 26 | */ |
| 27 | function Kernel(model) { |
| 28 | if (model === undefined) |
| 29 | throw new Error('model must be provided'); |
| 30 | ProcessBase.call(this, model); |
| 31 | this.cpus = {}; |
| 32 | this.softwareMeasuredCpuCount_ = undefined; |
| 33 | }; |
| 34 | |
| 35 | /** |
| 36 | * Comparison between kernels is pretty meaningless. |
| 37 | */ |
| 38 | Kernel.compare = function(x, y) { |
| 39 | return 0; |
| 40 | }; |
| 41 | |
| 42 | Kernel.prototype = { |
| 43 | __proto__: ProcessBase.prototype, |
| 44 | |
| 45 | compareTo: function(that) { |
| 46 | return Kernel.compare(this, that); |
| 47 | }, |
| 48 | |
| 49 | get userFriendlyName() { |
| 50 | return 'Kernel'; |
| 51 | }, |
| 52 | |
| 53 | get userFriendlyDetails() { |
| 54 | return 'Kernel'; |
| 55 | }, |
| 56 | |
| 57 | get stableId() { |
| 58 | return 'Kernel'; |
| 59 | }, |
| 60 | |
| 61 | /** |
| 62 | * @return {Cpu} Gets a specific Cpu or creates one if |
| 63 | * it does not exist. |
| 64 | */ |
| 65 | getOrCreateCpu: function(cpuNumber) { |
| 66 | if (!this.cpus[cpuNumber]) |
| 67 | this.cpus[cpuNumber] = new Cpu(this, cpuNumber); |
| 68 | return this.cpus[cpuNumber]; |
| 69 | }, |
| 70 | |
| 71 | get softwareMeasuredCpuCount() { |
| 72 | return this.softwareMeasuredCpuCount_; |
| 73 | }, |
| 74 | |
| 75 | set softwareMeasuredCpuCount(softwareMeasuredCpuCount) { |
| 76 | if (this.softwareMeasuredCpuCount_ !== undefined && |
| 77 | this.softwareMeasuredCpuCount_ !== softwareMeasuredCpuCount) { |
| 78 | throw new Error( |
| 79 | 'Cannot change the softwareMeasuredCpuCount once it is set'); |
| 80 | } |
| 81 | |
| 82 | this.softwareMeasuredCpuCount_ = softwareMeasuredCpuCount; |
| 83 | }, |
| 84 | |
| 85 | /** |
| 86 | * Estimates how many cpus are in the system, for use in system load |
| 87 | * estimation. |
| 88 | * |
| 89 | * If kernel trace was provided, uses that data. Otherwise, uses the |
| 90 | * software measured cpu count. |
| 91 | */ |
| 92 | get bestGuessAtCpuCount() { |
| 93 | var realCpuCount = tv.b.dictionaryLength(this.cpus); |
| 94 | if (realCpuCount !== 0) |
| 95 | return realCpuCount; |
| 96 | return this.softwareMeasuredCpuCount; |
| 97 | }, |
| 98 | |
| 99 | shiftTimestampsForward: function(amount) { |
Chris Craik | f516a62 | 2015-04-01 17:52:39 -0700 | [diff] [blame] | 100 | ProcessBase.prototype.shiftTimestampsForward.call(this, amount); |
Chris Craik | 93216d0 | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 101 | for (var cpuNumber in this.cpus) |
| 102 | this.cpus[cpuNumber].shiftTimestampsForward(amount); |
| 103 | }, |
| 104 | |
| 105 | updateBounds: function() { |
| 106 | ProcessBase.prototype.updateBounds.call(this); |
| 107 | for (var cpuNumber in this.cpus) { |
| 108 | var cpu = this.cpus[cpuNumber]; |
| 109 | cpu.updateBounds(); |
| 110 | this.bounds.addRange(cpu.bounds); |
| 111 | } |
| 112 | }, |
| 113 | |
| 114 | createSubSlices: function() { |
| 115 | ProcessBase.prototype.createSubSlices.call(this); |
| 116 | for (var cpuNumber in this.cpus) { |
| 117 | var cpu = this.cpus[cpuNumber]; |
| 118 | cpu.createSubSlices(); |
| 119 | } |
| 120 | }, |
| 121 | |
| 122 | addCategoriesToDict: function(categoriesDict) { |
| 123 | ProcessBase.prototype.addCategoriesToDict.call(this, categoriesDict); |
| 124 | for (var cpuNumber in this.cpus) |
| 125 | this.cpus[cpuNumber].addCategoriesToDict(categoriesDict); |
| 126 | }, |
| 127 | |
| 128 | getSettingsKey: function() { |
| 129 | return 'kernel'; |
| 130 | }, |
| 131 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 132 | iterateAllChildEventContainers: function(callback, opt_this) { |
| 133 | ProcessBase.prototype.iterateAllChildEventContainers.call( |
| 134 | this, callback, opt_this); |
| 135 | for (var cpuId in this.cpus) |
| 136 | callback.call(opt_this, this.cpus[cpuId]); |
Chris Craik | 93216d0 | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 137 | }, |
| 138 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 139 | iterateAllEventsInThisContainer: function(eventTypePredicate, |
| 140 | callback, opt_this) { |
| 141 | ProcessBase.prototype.iterateAllEventsInThisContainer.call( |
| 142 | this, eventTypePredicate, callback, opt_this); |
Chris Craik | 93216d0 | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 143 | } |
| 144 | }; |
| 145 | |
| 146 | return { |
| 147 | Kernel: Kernel |
| 148 | }; |
| 149 | }); |
| 150 | </script> |