• 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.require('tracks.timeline_container_track');
8base.require('tracks.timeline_counter_track');
9base.require('tracks.timeline_thread_track');
10base.require('timeline_filter');
11base.require('ui');
12
13base.exportTo('tracks', function() {
14
15  /**
16   * Visualizes a TimelineProcess by building TimelineThreadTracks and
17   * TimelineCounterTracks.
18   * @constructor
19   */
20  var TimelineProcessTrack = base.ui.define(tracks.TimelineContainerTrack);
21
22  TimelineProcessTrack.prototype = {
23
24    __proto__: tracks.TimelineContainerTrack.prototype,
25
26    decorate: function() {
27      this.classList.add('timeline-process-track');
28      this.categoryFilter_ = new tracing.TimelineFilter();
29    },
30
31    get process() {
32      return this.process_;
33    },
34
35    set process(process) {
36      this.process_ = process;
37      this.updateChildTracks_();
38    },
39
40    applyCategoryFilter_: function() {
41      this.visible = (this.categoryFilter.matchProcess(this.process) &&
42                      !!this.numVisibleChildTracks);
43    },
44
45    updateChildTracks_: function() {
46      this.detach();
47      if (this.process_) {
48        // Add counter tracks for this process.
49        var counters = [];
50        for (var tid in this.process.counters) {
51          counters.push(this.process.counters[tid]);
52        }
53        counters.sort(tracing.TimelineCounter.compare);
54
55        // Create the counters for this process.
56        counters.forEach(function(counter) {
57          var track = new tracks.TimelineCounterTrack();
58          track.heading = counter.name + ':';
59          track.counter = counter;
60          this.addTrack_(track);
61        }.bind(this));
62
63        // Get a sorted list of threads.
64        var threads = [];
65        for (var tid in this.process.threads)
66          threads.push(this.process.threads[tid]);
67        threads.sort(tracing.TimelineThread.compare);
68
69        // Create the threads.
70        threads.forEach(function(thread) {
71          var track = new tracks.TimelineThreadTrack();
72          track.heading = thread.userFriendlyName + ':';
73          track.tooltip = thread.userFriendlyDetails;
74          track.thread = thread;
75          this.addTrack_(track);
76        }.bind(this));
77      }
78    }
79  };
80
81  return {
82    TimelineProcessTrack: TimelineProcessTrack
83  };
84});
85