• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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
6/**
7 * @fileoverview ProfilingView visualizes GPU_TRACE events using the
8 * gpu.Timeline component.
9 */
10cr.define('gpu', function() {
11  /**
12   * ProfilingView
13   * @constructor
14   * @extends {gpu.Tab}
15   */
16  ProfilingView = cr.ui.define(gpu.Tab);
17
18  ProfilingView.prototype = {
19    __proto__: gpu.Tab.prototype,
20
21    traceEvents_: [],
22
23    decorate: function() {
24      // make the <list>/add/save/record element
25      this.controlDiv_ = document.createElement('div');
26      this.controlDiv_.className = 'control';
27      this.appendChild(this.controlDiv_);
28
29      this.recordBn_ = document.createElement('button');
30      this.recordBn_.textContent = 'Record';
31      this.recordBn_.addEventListener('click', this.onRecord_.bind(this));
32
33      this.saveBn_ = document.createElement('button');
34      this.saveBn_.textContent = 'Save';
35      this.saveBn_.addEventListener('click', this.onSave_.bind(this));
36
37      this.loadBn_ = document.createElement('button');
38      this.loadBn_.textContent = 'Load';
39      this.loadBn_.addEventListener('click', this.onLoad_.bind(this));
40
41      this.container_ = document.createElement('div');
42      this.container_.className = 'container';
43
44      this.timelineView_ = new TimelineView();
45
46      this.controlDiv_.appendChild(this.recordBn_);
47      if (!browserBridge.debugMode) {
48        this.controlDiv_.appendChild(this.loadBn_);
49        this.controlDiv_.appendChild(this.saveBn_);
50      }
51
52      this.container_.appendChild(this.timelineView_);
53      this.appendChild(this.container_);
54
55      tracingController.addEventListener('traceEnded',
56          this.onRecordDone_.bind(this));
57      tracingController.addEventListener('loadTraceFileComplete',
58          this.onLoadTraceFileComplete_.bind(this));
59      tracingController.addEventListener('saveTraceFileComplete',
60          this.onSaveTraceFileComplete_.bind(this));
61      tracingController.addEventListener('loadTraceFileCanceled',
62          this.onLoadTraceFileCanceled_.bind(this));
63      tracingController.addEventListener('saveTraceFileCanceled',
64          this.onSaveTraceFileCanceled_.bind(this));
65      this.refresh_();
66    },
67
68    refresh_: function() {
69      var hasEvents = this.traceEvents_ && this.traceEvents_.length;
70
71      this.saveBn_.disabled = !hasEvents;
72
73      this.timelineView_.traceEvents = this.traceEvents_;
74    },
75
76    ///////////////////////////////////////////////////////////////////////////
77
78    onRecord_: function() {
79      tracingController.beginTracing();
80    },
81
82    onRecordDone_: function() {
83      this.traceEvents_ = tracingController.traceEvents;
84      this.refresh_();
85    },
86
87    ///////////////////////////////////////////////////////////////////////////
88
89    onSave_: function() {
90      this.overlayEl_ = new gpu.Overlay();
91      this.overlayEl_.className = 'profiling-overlay';
92
93      var labelEl = document.createElement('div');
94      labelEl.className = 'label';
95      labelEl.textContent = 'Saving...';
96      this.overlayEl_.appendChild(labelEl);
97      this.overlayEl_.visible = true;
98
99      tracingController.beginSaveTraceFile(this.traceEvents_);
100    },
101
102    onSaveTraceFileComplete_: function(e) {
103      this.overlayEl_.visible = false;
104      this.overlayEl_ = undefined;
105    },
106
107    onSaveTraceFileCanceled_: function(e) {
108      this.overlayEl_.visible = false;
109      this.overlayEl_ = undefined;
110    },
111
112    ///////////////////////////////////////////////////////////////////////////
113
114    onLoad_: function() {
115      this.overlayEl_ = new gpu.Overlay();
116      this.overlayEl_.className = 'profiling-overlay';
117
118      var labelEl = document.createElement('div');
119      labelEl.className = 'label';
120      labelEl.textContent = 'Loading...';
121      this.overlayEl_.appendChild(labelEl);
122      this.overlayEl_.visible = true;
123
124      tracingController.beginLoadTraceFile();
125    },
126
127    onLoadTraceFileComplete_: function(e) {
128      this.overlayEl_.visible = false;
129      this.overlayEl_ = undefined;
130
131      this.traceEvents_ = e.events;
132      this.refresh_();
133    },
134
135    onLoadTraceFileCanceled_: function(e) {
136      this.overlayEl_.visible = false;
137      this.overlayEl_ = undefined;
138    }
139  };
140
141  return {
142    ProfilingView: ProfilingView
143  };
144});
145