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
|
// 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 Displays an analysis of the selection.
*/
base.requireStylesheet('tracing.analysis.analysis_view');
base.require('base.guid');
base.require('tracing.analysis.analysis_results');
base.require('tracing.analysis.analyze_selection');
base.require('tracing.analysis.default_object_view');
base.require('tracing.analysis.object_instance_view');
base.require('tracing.analysis.object_snapshot_view');
base.require('tracing.analysis.slice_view');
base.require('tracing.analysis.util');
base.require('ui');
base.exportTo('tracing.analysis', function() {
var AnalysisView = ui.define('div');
AnalysisView.prototype = {
__proto__: HTMLDivElement.prototype,
decorate: function() {
this.className = 'analysis-view';
this.currentView_ = undefined;
this.currentSelection_ = undefined;
this.selections_ = [];
this.guid_ = base.GUID.allocate();
window.addEventListener('popstate', this.onPopState.bind(this));
},
changeViewType: function(viewType) {
if (this.currentView_ instanceof viewType)
return;
this.textContent = '';
try {
this.currentView_ = new viewType();
this.appendChild(this.currentView_);
} catch (e) {
this.currentView_ = undefined;
throw e;
}
this.updateClassList_();
},
updateClassList_: function() {
if (this.currentView_ instanceof tracing.analysis.AnalysisResults)
this.classList.remove('viewing-old-style-analysis');
else
this.classList.add('viewing-old-style-analysis');
if (this.currentView_ &&
this.currentView_.requiresTallView) {
this.classList.add('tall-mode');
} else {
this.classList.remove('tall-mode');
}
},
get currentView() {
return this.currentView_;
},
get selection() {
return this.currentSelection_;
},
set selection(selection) {
this.selections_.push(selection);
var state = {
view_guid: this.guid_,
selection_guid: selection.guid
};
window.history.pushState(state);
this.processSelection(selection);
},
clearSelectionHistory: function() {
this.selections_ = [];
},
onPopState: function(event) {
if ((event.state === null) ||
(event.state.view_guid !== this.guid_))
return;
var idx;
for (idx = 0; idx < this.selections_.length; ++idx) {
if (this.selections_[idx].guid === event.state.selection_guid)
break;
}
if (idx >= this.selections_.length)
return;
this.processSelection(this.selections_[idx]);
event.stopPropagation();
},
processSelection: function(selection) {
var eventsByType = selection.getEventsOrganizedByType();
if (selection.length == 1 &&
eventsByType.counterSamples.length == 0) {
if (this.tryToProcessSelectionUsingCustomView(selection[0]))
return;
}
this.changeViewType(tracing.analysis.AnalysisResults);
this.currentView.clear();
this.currentSelection_ = selection;
tracing.analysis.analyzeEventsByType(this.currentView, eventsByType);
},
tryToProcessSelectionUsingCustomView: function(event) {
var obj;
var typeName;
var viewBaseType;
var defaultViewType;
var viewProperty;
if (event instanceof tracing.trace_model.ObjectSnapshot) {
typeName = event.objectInstance.typeName;
viewBaseType = tracing.analysis.ObjectSnapshotView;
defaultViewType = tracing.analysis.DefaultObjectSnapshotView;
} else if (event instanceof tracing.trace_model.ObjectInstance) {
typeName = event.typeName;
viewBaseType = tracing.analysis.ObjectInstanceView;
defaultViewType = tracing.analysis.DefaultObjectInstanceView;
} else if (event instanceof tracing.trace_model.Slice) {
typeName = event.analysisTypeName;
viewBaseType = tracing.analysis.SliceView;
defaultViewType = undefined;
} else {
return false;
}
var customViewInfo = viewBaseType.getViewInfo(typeName);
var viewType = customViewInfo ?
customViewInfo.constructor : defaultViewType;
// Some view types don't have default views. In those cases, we fall
// back to the standard analysis sytem.
if (!viewType)
return false;
this.changeViewType(viewType);
this.currentView.modelEvent = event;
return true;
}
};
return {
AnalysisView: AnalysisView
};
});
|