1 // Copyright (c) 2013 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.
8 * @fileoverview Displays an analysis of the selection.
10 tvcm.requireStylesheet('tracing.analysis.analysis_view');
12 tvcm.require('tracing.analysis.analysis_results');
13 tvcm.require('tracing.analysis.analyze_selection');
14 tvcm.require('tracing.analysis.default_object_view');
15 tvcm.require('tracing.analysis.object_instance_view');
16 tvcm.require('tracing.analysis.object_snapshot_view');
17 tvcm.require('tracing.analysis.slice_view');
18 tvcm.require('tracing.analysis.util');
19 tvcm.require('tvcm.ui');
20 tvcm.require('tvcm.guid');
21 tvcm.exportTo('tracing.analysis', function() {
23 var AnalysisView = tvcm.ui.define('div');
25 AnalysisView.prototype = {
26 __proto__: HTMLDivElement.prototype,
28 decorate: function() {
29 this.className = 'analysis-view';
31 this.currentView_ = undefined;
32 this.currentSelection_ = undefined;
33 this.selections_ = [];
34 this.guid_ = tvcm.GUID.allocate();
36 window.addEventListener('popstate', this.onPopState.bind(this));
39 changeViewType: function(viewType) {
40 if (this.currentView_ instanceof viewType)
42 this.textContent = '';
44 this.currentView_ = new viewType();
45 this.appendChild(this.currentView_);
47 this.currentView_ = undefined;
51 this.updateClassList_();
53 updateClassList_: function() {
54 if (this.currentView_ instanceof tracing.analysis.AnalysisResults)
55 this.classList.remove('viewing-old-style-analysis');
57 this.classList.add('viewing-old-style-analysis');
59 if (this.currentView_ &&
60 this.currentView_.requiresTallView) {
61 this.classList.add('tall-mode');
63 this.classList.remove('tall-mode');
68 return this.currentView_;
72 return this.currentSelection_;
75 set selection(selection) {
76 this.selections_.push(selection);
79 view_guid: this.guid_,
80 selection_guid: selection.guid
82 window.history.pushState(state);
84 this.processSelection(selection);
87 clearSelectionHistory: function() {
88 this.selections_ = [];
91 onPopState: function(event) {
92 if ((event.state === null) ||
93 (event.state.view_guid !== this.guid_))
97 for (idx = 0; idx < this.selections_.length; ++idx) {
98 if (this.selections_[idx].guid === event.state.selection_guid)
102 if (idx >= this.selections_.length)
105 this.processSelection(this.selections_[idx]);
106 event.stopPropagation();
109 processSelection: function(selection) {
110 var eventsByType = selection.getEventsOrganizedByType();
111 if (selection.length == 1 &&
112 eventsByType.counterSamples.length == 0) {
113 if (this.tryToProcessSelectionUsingCustomView(selection[0]))
117 this.changeViewType(tracing.analysis.AnalysisResults);
119 this.currentView.clear();
120 this.currentSelection_ = selection;
121 tracing.analysis.analyzeEventsByType(this.currentView, eventsByType);
124 tryToProcessSelectionUsingCustomView: function(event) {
130 if (event instanceof tracing.trace_model.ObjectSnapshot) {
131 typeName = event.objectInstance.typeName;
132 viewBaseType = tracing.analysis.ObjectSnapshotView;
133 defaultViewType = tracing.analysis.DefaultObjectSnapshotView;
134 } else if (event instanceof tracing.trace_model.ObjectInstance) {
135 typeName = event.typeName;
136 viewBaseType = tracing.analysis.ObjectInstanceView;
137 defaultViewType = tracing.analysis.DefaultObjectInstanceView;
138 } else if (event instanceof tracing.trace_model.Slice) {
139 typeName = event.analysisTypeName;
140 viewBaseType = tracing.analysis.SliceView;
141 defaultViewType = undefined;
146 var customViewInfo = viewBaseType.getViewInfo(typeName);
148 var viewType = customViewInfo ?
149 customViewInfo.constructor : defaultViewType;
151 // Some view types don't have default views. In those cases, we fall
152 // back to the standard analysis sytem.
156 this.changeViewType(viewType);
157 this.currentView.modelEvent = event;
163 AnalysisView: AnalysisView