1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview View visualizes TRACE_EVENT events using the
* tracing.Timeline component and adds in selection summary and control buttons.
*/
base.requireStylesheet('ui.trace_viewer');
base.requireStylesheet('tracing.timeline_view');
base.requireTemplate('tracing.timeline_view');
base.require('base.utils');
base.require('base.settings');
base.require('tracing.analysis.analysis_view');
base.require('tracing.find_control');
base.require('tracing.timeline_track_view');
base.require('ui.dom_helpers');
base.require('ui.overlay');
base.require('ui.drag_handle');
base.require('tracing.analysis.cpu_slice_view');
base.require('tracing.analysis.thread_time_slice_view');
base.exportTo('tracing', function() {
/**
* View
* @constructor
* @extends {HTMLUnknownElement}
*/
var TimelineView = ui.define('x-timeline-view');
TimelineView.prototype = {
__proto__: HTMLUnknownElement.prototype,
decorate: function() {
var node = base.instantiateTemplate('#timeline-view-template');
this.appendChild(node);
this.titleEl_ = this.querySelector('.title');
this.leftControlsEl_ = this.querySelector('#left-controls');
this.rightControlsEl_ = this.querySelector('#right-controls');
this.timelineContainer_ = this.querySelector('.container');
this.findCtl_ = new tracing.FindControl();
this.findCtl_.controller = new tracing.FindController();
this.showFlowEvents_ = false;
this.rightControls.appendChild(ui.createCheckBox(
this, 'showFlowEvents',
'tracing.TimelineView.showFlowEvents', false,
'Flow events'));
this.rightControls.appendChild(this.createMetadataButton_());
this.rightControls.appendChild(this.findCtl_);
this.rightControls.appendChild(this.createHelpButton_());
this.dragEl_ = new ui.DragHandle();
this.appendChild(this.dragEl_);
this.analysisEl_ = new tracing.analysis.AnalysisView();
this.analysisEl_.addEventListener(
'requestSelectionChange',
this.onRequestSelectionChange_.bind(this));
this.appendChild(this.analysisEl_);
// Bookkeeping.
this.onSelectionChanged_ = this.onSelectionChanged_.bind(this);
document.addEventListener('keydown', this.onKeyDown_.bind(this), true);
document.addEventListener('keypress', this.onKeypress_.bind(this), true);
this.dragEl_.target = this.analysisEl_;
},
get showFlowEvents() {
return this.showFlowEvents_;
},
set showFlowEvents(showFlowEvents) {
this.showFlowEvents_ = showFlowEvents;
if (!this.timeline_)
return;
this.timeline_.viewport.showFlowEvents = showFlowEvents;
},
createHelpButton_: function() {
var node = base.instantiateTemplate('#help-btn-template');
var showEl = node.querySelector('.view-help-button');
var helpTextEl = node.querySelector('.view-help-text');
var dlg = new ui.Overlay();
dlg.title = 'chrome://tracing Help';
dlg.classList.add('view-help-overlay');
dlg.appendChild(node);
function onClick(e) {
dlg.visible = !dlg.visible;
var mod = base.isMac ? 'cmd ' : 'ctrl';
var spans = helpTextEl.querySelectorAll('span.mod');
for (var i = 0; i < spans.length; i++) {
spans[i].textContent = mod;
}
// Stop event so it doesn't trigger new click listener on document.
e.stopPropagation();
return false;
}
showEl.addEventListener('click', onClick.bind(this));
return showEl;
},
createMetadataButton_: function() {
var node = base.instantiateTemplate('#metadata-btn-template');
var showEl = node.querySelector('.view-metadata-button');
var textEl = node.querySelector('.info-button-text');
var dlg = new ui.Overlay();
dlg.title = 'Metadata for trace';
dlg.classList.add('view-metadata-overlay');
dlg.appendChild(node);
function onClick(e) {
dlg.visible = true;
var metadataStrings = [];
var model = this.model;
for (var data in model.metadata) {
var meta = model.metadata[data];
var name = JSON.stringify(meta.name);
var value = JSON.stringify(meta.value, undefined, ' ');
metadataStrings.push(name + ': ' + value);
}
textEl.textContent = metadataStrings.join('\n');
e.stopPropagation();
return false;
}
showEl.addEventListener('click', onClick.bind(this));
function updateVisibility() {
showEl.style.display =
(this.model && this.model.metadata.length) ? '' : 'none';
}
var updateVisibility_ = updateVisibility.bind(this);
updateVisibility_();
this.addEventListener('modelChange', updateVisibility_);
return showEl;
},
get leftControls() {
return this.leftControlsEl_;
},
get rightControls() {
return this.rightControlsEl_;
},
get viewTitle() {
return this.titleEl_.textContent.substring(
this.titleEl_.textContent.length - 2);
},
set viewTitle(text) {
if (text === undefined) {
this.titleEl_.textContent = '';
this.titleEl_.hidden = true;
return;
}
this.titleEl_.hidden = false;
this.titleEl_.textContent = text;
},
get model() {
if (this.timeline_)
return this.timeline_.model;
return undefined;
},
set model(model) {
var modelInstanceChanged = model != this.model;
var modelValid = model && !model.bounds.isEmpty;
// Remove old timeline if the model has completely changed.
if (modelInstanceChanged) {
this.timelineContainer_.textContent = '';
if (this.timeline_) {
this.timeline_.removeEventListener(
'selectionChange', this.onSelectionChanged_);
this.timeline_.detach();
this.timeline_ = undefined;
this.findCtl_.controller.timeline = undefined;
}
}
// Create new timeline if needed.
if (modelValid && !this.timeline_) {
this.timeline_ = new tracing.TimelineTrackView();
this.timeline_.focusElement =
this.focusElement_ ? this.focusElement_ : this.parentElement;
this.timelineContainer_.appendChild(this.timeline_);
this.findCtl_.controller.timeline = this.timeline_;
this.timeline_.addEventListener(
'selectionChange', this.onSelectionChanged_);
this.timeline_.viewport.showFlowEvents = this.showFlowEvents;
this.analysisEl_.clearSelectionHistory();
}
// Set the model.
if (modelValid)
this.timeline_.model = model;
base.dispatchSimpleEvent(this, 'modelChange');
// Do things that are selection specific
if (modelInstanceChanged)
this.onSelectionChanged_();
},
get timeline() {
return this.timeline_;
},
get settings() {
if (!this.settings_)
this.settings_ = new base.Settings();
return this.settings_;
},
/**
* Sets the element whose focus state will determine whether
* to respond to keybaord input.
*/
set focusElement(value) {
this.focusElement_ = value;
if (this.timeline_)
this.timeline_.focusElement = value;
},
/**
* @return {Element} The element whose focused state determines
* whether to respond to keyboard inputs.
* Defaults to the parent element.
*/
get focusElement() {
if (this.focusElement_)
return this.focusElement_;
return this.parentElement;
},
/**
* @return {boolean} Whether the current timeline is attached to the
* document.
*/
get isAttachedToDocument_() {
var cur = this;
while (cur.parentNode)
cur = cur.parentNode;
return cur == this.ownerDocument;
},
get listenToKeys_() {
if (!this.isAttachedToDocument_)
return;
if (!this.focusElement_)
return true;
if (this.focusElement.tabIndex >= 0)
return document.activeElement == this.focusElement;
return true;
},
onKeyDown_: function(e) {
if (!this.listenToKeys_)
return;
if (e.keyCode === 27) { // ESC
this.focus();
e.preventDefault();
}
},
onKeypress_: function(e) {
if (!this.listenToKeys_)
return;
if (e.keyCode === '/'.charCodeAt(0)) {
if (this.findCtl_.hasFocus())
this.focus();
else
this.findCtl_.focus();
e.preventDefault();
} else if (e.keyCode === '?'.charCodeAt(0)) {
this.querySelector('.view-help-button').click();
e.preventDefault();
}
},
beginFind: function() {
if (this.findInProgress_)
return;
this.findInProgress_ = true;
var dlg = tracing.FindControl();
dlg.controller = new tracing.FindController();
dlg.controller.timeline = this.timeline;
dlg.visible = true;
dlg.addEventListener('close', function() {
this.findInProgress_ = false;
}.bind(this));
dlg.addEventListener('findNext', function() {
});
dlg.addEventListener('findPrevious', function() {
});
},
onSelectionChanged_: function(e) {
var oldScrollTop = this.timelineContainer_.scrollTop;
var selection = this.timeline_ ?
this.timeline_.selectionOfInterest :
new tracing.Selection();
this.analysisEl_.selection = selection;
this.timelineContainer_.scrollTop = oldScrollTop;
},
onRequestSelectionChange_: function(e) {
this.timeline_.selection = e.selection;
e.stopPropagation();
}
};
return {
TimelineView: TimelineView
};
});
|