3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/analysis/analysis_results.html">
9 <link rel="import" href="/tracing/analysis/analyze_counters.html">
10 <link rel="import" href="/tracing/analysis/analyze_objects.html">
11 <link rel="import" href="/tracing/analysis/analyze_slices.html">
12 <link rel="import" href="/tracing/analysis/analyze_samples.html">
13 <link rel="import" href="/tracing/analysis/default_object_view.html">
14 <link rel="import" href="/tracing/analysis/object_instance_view.html">
15 <link rel="import" href="/tracing/analysis/object_snapshot_view.html">
16 <link rel="import" href="/tracing/analysis/slice_view.html">
17 <link rel="import" href="/tracing/analysis/tab_view.html">
20 @fileoverview A component used to display an analysis of a selection,
21 using custom elements specialized for different event types.
23 <polymer-element name="tracing-analysis-view"
24 constructor="TracingAnalysisView">
28 background-color: white;
30 flex-direction: column;
49 * Utility function used to convert camelCase to Title Case.
51 function convertEventTypeToTabName(eventType) {
52 var result = eventType.replace(/[A-Z]/g, ' $&');
53 result = result.charAt(0).toUpperCase() + result.slice(1);
59 this.currentView_ = undefined;
60 this.currentSelection_ = undefined;
65 this.classList.add('tall-mode');
67 this.classList.remove('tall-mode');
71 return this.classList.contains('tall-mode');
75 return this.currentView_;
79 return this.currentSelection_;
82 set selection(selection) {
83 this.processSelection_(selection);
86 processSelection_: function(selection) {
87 this.tallMode = false;
88 this.textContent = '';
90 var eventsByType = selection.getEventsOrganizedByType(true);
92 var categoriesToAnalyze = tvcm.dictionaryLength(eventsByType)
95 var usingTabs = false;
96 // If we have to analyze more than one category, we use a tab view
97 // for displaying them.
98 if (categoriesToAnalyze > 1) {
100 subViewsParent = new TracingAnalysisTabView();
101 this.appendChild(subViewsParent);
103 subViewsParent = this;
106 for (var eventType in eventsByType) {
107 var currentEvents = eventsByType[eventType];
108 var subView = undefined;
110 subView = this.findSubViewForEventsOfSingleType_(
111 eventsByType[eventType]);
112 subViewsParent.appendChild(subView);
113 // There are some subViews that get configured by 'modelEvent'
114 // instead of selection. We need to move them off of this craziness.
115 // But, cc.LayerTreeHostView has a concept called selection as
116 // well, but its selection is a cc.Selection. So the properties
117 // collide, in a scary way.
118 if (subView.__lookupSetter__('modelEvent')) {
119 if (eventsByType[eventType].length != 1)
120 throw new Error('modelEvent-configuration only supported with ' +
121 ' selections of length=1');
122 subView.modelEvent = eventsByType[eventType][0];
124 subView.selection = eventsByType[eventType];
127 this.tallMode = this.tallMode || subView.requiresTallView;
129 var tabLabel = convertEventTypeToTabName(eventType);
130 subView.tabLabel = tabLabel;
131 // Some subViews are not actually built off analysis-sub-view,
132 // thus they don't all implement the tabLabel property.
133 // This is here in place as a workaround until they are converted
135 if (!subView.hasAttribute('tab-label'))
136 subView.setAttribute('tab-label', tabLabel);
141 subViewsParent.selectedTab = subViewsParent.firstChild;
142 this.currentView_ = subViewsParent
144 this.currentView_ = this.firstChild;
148 findSubViewForEventsOfSingleType_: function(selection) {
149 var supportedSubViewTypes = tracing.getAnalysisSubViewTypes().filter(
150 function(subViewTypes) {
151 return subViewTypes.supportsSelectionPredicate(selection);
154 if (supportedSubViewTypes.length == 0)
155 throw new Error('Received events that could not be analyzed!');
157 // Pick the most important registered type handler.
158 supportedSubViewTypes.sort(function(x,y) {
159 return y.importance - x.importance;
161 var subViewType = supportedSubViewTypes[0];
163 if (subViewType.options.passSelectionToConstructor)
164 return new subViewType.viewConstructor(selection);
166 return new subViewType.viewConstructor();