• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7base.requireStylesheet('tracks.timeline_model_track');
8base.require('tracks.timeline_container_track');
9base.require('tracks.timeline_cpu_track');
10base.require('tracks.timeline_process_track');
11base.require('ui');
12
13base.exportTo('tracks', function() {
14
15  /**
16   * Visualizes a TimelineModel by building TimelineProcessTracks and
17   * TimelineCpuTracks.
18   * @constructor
19   */
20  var TimelineModelTrack = base.ui.define(tracks.TimelineContainerTrack);
21
22  TimelineModelTrack.prototype = {
23
24    __proto__: tracks.TimelineContainerTrack.prototype,
25
26    decorate: function() {
27      this.classList.add('timeline-model-track');
28      this.measuringStick_ = new tracing.MeasuringStick();
29      this.measuringStick_.attach();
30    },
31
32    detach: function() {
33      tracks.TimelineContainerTrack.prototype.detach.call(this);
34      this.measuringStick_.detach();
35    },
36
37    get model() {
38      return this.model_;
39    },
40
41    set model(model) {
42      this.model_ = model;
43      this.updateHeadingWidth_();
44      this.updateChildTracks_();
45    },
46
47    updateHeadingWidth_: function() {
48      // Figure out all the headings.
49      var allHeadings = [];
50      this.model.getAllThreads().forEach(function(t) {
51        allHeadings.push(t.userFriendlyName);
52      });
53      this.model.getAllCounters().forEach(function(c) {
54        allHeadings.push(c.name);
55      });
56      this.model.getAllCpus().forEach(function(c) {
57        allHeadings.push('CPU ' + c.cpuNumber);
58      });
59
60      // Figure out the maximum heading size.
61      var maxHeadingWidth = 0;
62      var headingEl = document.createElement('div');
63      headingEl.style.position = 'fixed';
64      headingEl.className = 'timeline-canvas-based-track-title';
65      for (var i = 0; i < allHeadings.length; i++) {
66        var text = allHeadings[i];
67        headingEl.textContent = text + ':__';
68        var w = this.measuringStick_.measure(headingEl).width;
69        // Limit heading width to 300px.
70        if (w > 300)
71          w = 300;
72        if (w > maxHeadingWidth)
73          maxHeadingWidth = w;
74      }
75      this.headingWidth = maxHeadingWidth + 'px';
76    },
77
78    updateChildTracks_: function() {
79      this.detachAllChildren();
80      if (this.model_) {
81        var cpus = this.model_.getAllCpus();
82        cpus.sort(tracing.TimelineCpu.compare);
83
84        for (var i = 0; i < cpus.length; ++i) {
85          var cpu = cpus[i];
86          var track = new tracks.TimelineCpuTrack();
87          track.heading = 'CPU ' + cpu.cpuNumber + ':';
88          track.cpu = cpu;
89          this.addTrack_(track);
90        }
91
92        // Get a sorted list of processes.
93        var processes = this.model_.getAllProcesses();
94        processes.sort(tracing.TimelineProcess.compare);
95
96        for (var i = 0; i < processes.length; ++i) {
97          var process = processes[i];
98          var track = new tracks.TimelineProcessTrack();
99          track.process = process;
100          this.addTrack_(track);
101        }
102      }
103    }
104  };
105
106  return {
107    TimelineModelTrack: TimelineModelTrack
108  };
109});
110