blob: 52e5f26eb308b1fd6e004e73df24c7acfec766f4 [file] [log] [blame]
Chris Craikb122baf2015-03-05 13:58:42 -08001<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/base/base.html">
9<link rel="import" href="/core/analysis/table_builder.html">
10<link rel="import" href="/core/analysis/multi_event_summary.html">
11<link rel="import" href="/core/analysis/time_span.html">
12<link rel="import" href="/core/analysis/time_stamp.html">
13<link rel="import" href="/core/analysis/generic_object_view.html">
14
15<polymer-element name='tv-c-a-multi-event-details-table'>
16 <template>
17 <style>
18 :host {
19 display: flex;
20 flex-direction: column;
21 }
22 #table {
23 flex: 1 1 auto;
24 align-self: stretch;
25 }
26
27 #titletable {
28 font-weight: bold;
29 }
30
31 #title-info {
32 font-size: 12px;
33 }
34 </style>
35 <tracing-analysis-nested-table id="titletable">
36 </tracing-analysis-nested-table>
37 <tracing-analysis-nested-table id="table">
38 </tracing-analysis-nested-table>
39 </template>
40
41 <script>
42 'use strict';
43
44 Polymer({
45 created: function() {
46 this.selection_ = undefined;
Chris Craikbeca7ae2015-04-07 13:29:55 -070047 this.eventsHaveDuration_ = true;
48 this.eventsHaveSubRows_ = true;
Chris Craikb122baf2015-03-05 13:58:42 -080049 },
50
51 ready: function() {
52 this.initTitleTable_();
53 },
54
Chris Craikbeca7ae2015-04-07 13:29:55 -070055 get eventsHaveDuration() {
56 return this.eventsHaveDuration_;
57 },
58
59 set eventsHaveDuration(eventsHaveDuration) {
60 this.eventsHaveDuration_ = eventsHaveDuration;
61 this.updateContents_();
62 },
63
64 get eventsHaveSubRows() {
65 return this.eventsHaveSubRows_;
66 },
67
68 set eventsHaveSubRows(eventsHaveSubRows) {
69 this.eventsHaveSubRows_ = eventsHaveSubRows;
70 this.updateContents_();
71 },
72
Chris Craikb122baf2015-03-05 13:58:42 -080073 get selection() {
74 return this.selection_;
75 },
76
77 set selection(selection) {
78 this.selection_ = selection;
Chris Craikbeca7ae2015-04-07 13:29:55 -070079 this.updateContents_();
80 },
81
82 updateContents_: function() {
83 var selection = this.selection_;
Chris Craikb122baf2015-03-05 13:58:42 -080084
85 this.updateTitleTable_();
86
87 if (this.selection_ === undefined) {
88 this.$.table.tableRows = [];
89 this.$.table.tableFooterRows = [];
90 this.$.table.rebuild();
91 return;
92 }
93
94 var summary = new tv.c.analysis.MultiEventSummary(
95 'Totals', this.selection_);
96 this.updateColumns_(summary);
97 this.updateRows_(summary);
98 this.$.table.rebuild();
99 },
100
101 initTitleTable_: function() {
102 var table = this.$.titletable;
103
104 table.showHeader = false;
105 table.tableColumns = [
106 {
107 title: 'Title',
108 value: function(row) { return row.title; },
109 width: '350px'
110 },
111 {
112 title: 'Value',
113 width: '100%',
114 value: function(row) {
115 return row.value;
116 }
117 }
118 ];
119 },
120
121 updateTitleTable_: function() {
122 var title;
123 if (this.selection_ && this.selection_.length)
124 title = this.selection_[0].title;
125 else
126 title = '<No selection>';
127
128 var table = this.$.titletable;
129 table.tableRows = [{
130 title: 'Title',
131 value: title
132 }];
133 },
134
135 updateColumns_: function(summary) {
136 var hasCpuData;
137 if (summary.cpuDuration !== undefined)
138 hasCpuData = true;
139 if (summary.cpuSelfTime !== undefined)
140 hasCpuData = true;
141
142 var colWidthPercentage;
143 if (hasCpuData)
144 colWidthPercentage = '20%';
145 else
146 colWidthPercentage = '33.3333%';
147
148 var columns = [];
149
150 columns.push({
151 title: 'Start',
152 value: function(row) {
153 if (row.__proto__ === tv.c.analysis.MultiEventSummary.prototype) {
154 return row.title;
155 }
156
157 var linkEl = document.createElement('tv-c-analysis-link');
158 linkEl.setSelectionAndContent(function() {
Chris Craikbeca7ae2015-04-07 13:29:55 -0700159 return new tv.c.Selection(row.event);
Chris Craikb122baf2015-03-05 13:58:42 -0800160 });
161 linkEl.appendChild(tv.c.analysis.createTimeStamp(row.start));
162 return linkEl;
163 },
164 width: '350px',
165 cmp: function(rowA, rowB) {
Chris Craikbeca7ae2015-04-07 13:29:55 -0700166 return rowA.start - rowB.start;
Chris Craikb122baf2015-03-05 13:58:42 -0800167 }
168 });
169
Chris Craikbeca7ae2015-04-07 13:29:55 -0700170 if (this.eventsHaveDuration_) {
171 columns.push({
172 title: 'Wall Duration (ms)',
173 value: function(row) {
174 return tv.c.analysis.createTimeSpan(row.duration);
175 },
176 width: '<upated further down>',
177 cmp: function(rowA, rowB) {
178 return rowA.duration - rowB.duration;
179 }
180 });
181 }
182
183 if (this.eventsHaveDuration_ && hasCpuData) {
Chris Craikb122baf2015-03-05 13:58:42 -0800184 columns.push({
185 title: 'CPU Duration (ms)',
186 value: function(row) {
187 return tv.c.analysis.createTimeSpan(row.cpuDuration);
188 },
189 width: '<upated further down>',
190 cmp: function(rowA, rowB) {
191 return rowA.cpuDuration - rowB.cpuDuration;
192 }
193 });
194 }
195
Chris Craikbeca7ae2015-04-07 13:29:55 -0700196 if (this.eventsHaveSubRows_ && this.eventsHaveDuration_) {
197 columns.push({
198 title: 'Self time (ms)',
199 value: function(row) {
200 return tv.c.analysis.createTimeSpan(row.selfTime);
201 },
202 width: '<upated further down>',
203 cmp: function(rowA, rowB) {
204 return rowA.selfTime - rowB.selfTime;
205 }
206 });
207 }
208
209 if (this.eventsHaveSubRows_ && this.eventsHaveDuration_ && hasCpuData) {
Chris Craikb122baf2015-03-05 13:58:42 -0800210 columns.push({
211 title: 'CPU Self Time (ms)',
212 value: function(row) {
213 return tv.c.analysis.createTimeSpan(row.cpuSelfTime);
214 },
215 width: '<upated further down>',
216 cmp: function(rowA, rowB) {
217 return rowA.cpuSelfTime - rowB.cpuSelfTime;
218 }
219 });
220 }
221
222 var argKeys = tv.b.dictionaryKeys(summary.totalledArgs);
223 argKeys.sort();
224
225 var otherKeys = summary.untotallableArgs.slice(0);
226 otherKeys.sort();
227
228 argKeys.push.apply(argKeys, otherKeys);
229 var keysWithColumns = argKeys.slice(0, 4);
230 var keysInOtherColumn = argKeys.slice(4);
231
232 keysWithColumns.forEach(function(argKey) {
233
234 var hasTotal = summary.totalledArgs[argKey];
235 var colDesc = {
236 title: 'Arg: ' + argKey,
237 value: function(row) {
238 if (row.__proto__ !== tv.c.analysis.MultiEventSummary.prototype) {
239 var argView =
240 document.createElement('tv-c-analysis-generic-object-view');
241 argView.object = row.args[argKey];
242 return argView;
243 }
244 if (hasTotal)
245 return row.totalledArgs[argKey];
246 return '';
247 },
248 width: '<upated further down>'
249 };
250 if (hasTotal) {
251 colDesc.cmp = function(rowA, rowB) {
252 return rowA.args[argKey] - rowB.args[argKey];
253 }
254 }
255 columns.push(colDesc);
256 });
257
258 if (keysInOtherColumn.length) {
259 columns.push({
260 title: 'Other Args',
261 value: function(row) {
262 if (row.__proto__ === tv.c.analysis.MultiEventSummary.prototype)
263 return '';
264 var argView =
265 document.createElement('tv-c-analysis-generic-object-view');
266 var obj = {};
267 for (var i = 0; i < keysInOtherColumn.length; i++)
268 obj[keysInOtherColumn[i]] = row.args[keysInOtherColumn[i]];
269 argView.object = obj;
270 return argView;
271 },
272 width: '<upated further down>'
273 });
274 }
275
Chris Craikbeca7ae2015-04-07 13:29:55 -0700276 var colWidthPercentage;
277 if (columns.length == 1)
278 colWidthPercentage = '100%';
279 else
280 colWidthPercentage = (100 / (columns.length - 1)).toFixed(3) + '%';
281
Chris Craikb122baf2015-03-05 13:58:42 -0800282 for (var i = 1; i < columns.length; i++)
283 columns[i].width = colWidthPercentage;
284
285 this.$.table.tableColumns = columns;
286 },
287
288 updateRows_: function(summary) {
289 this.$.table.sortColumnIndex = 0;
Chris Craikbeca7ae2015-04-07 13:29:55 -0700290 function Row(event) {
291 this.event = event;
292 }
293 Row.prototype = {
294 get start() { return this.event.start; },
295 get duration() { return this.event.duration; },
296 get cpuDuration() { return this.event.cpuDuration; },
297 get selfTime() { return this.event.selfTime; },
298 get cpuSelfTime() { return this.event.cpuSelfTime; },
299 get args() { return this.event.args; }
300 };
301
Chris Craikb122baf2015-03-05 13:58:42 -0800302 this.$.table.tableRows = this.selection_.map(function(event) {
Chris Craikbeca7ae2015-04-07 13:29:55 -0700303 return new Row(event);
Chris Craikb122baf2015-03-05 13:58:42 -0800304 });
305 this.$.table.footerRows = [summary];
306 }
307 });
308</script>
Chris Craik44c28202015-05-12 17:25:16 -0700309</polymer-element>
Chris Craikb122baf2015-03-05 13:58:42 -0800310
311