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 */
10base.require('tracing.trace_model.cpu');
11base.require('tracing.trace_model.process_base');
12
13base.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(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    addCategoriesToDict: function(categoriesDict) {
78      ProcessBase.prototype.addCategoriesToDict.call(this, categoriesDict);
79      for (var cpuNumber in this.cpus)
80        this.cpus[cpuNumber].addCategoriesToDict(categoriesDict);
81    },
82
83    getSettingsKey: function() {
84      return 'kernel';
85    }
86  };
87
88  return {
89    Kernel: Kernel
90  };
91});
92