Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2013 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. |
| 6 | --> |
| 7 | |
| 8 | <link rel="import" href="/base/base.html"> |
| 9 | <link rel="import" href="/base/iteration_helpers.html"> |
| 10 | <link rel="import" href="/base/statistics.html"> |
| 11 | <link rel="import" href="/core/analysis/analysis_link.html"> |
| 12 | <link rel="import" href="/core/analysis/multi_event_summary.html"> |
| 13 | <link rel="import" href="/core/analysis/table_builder.html"> |
| 14 | <link rel="import" href="/core/analysis/time_span.html"> |
| 15 | |
| 16 | </script> |
| 17 | <polymer-element name='tv-c-a-multi-event-summary-table'> |
| 18 | <template> |
| 19 | <style> |
| 20 | :host { |
| 21 | display: flex; |
| 22 | } |
| 23 | #table { |
| 24 | flex: 1 1 auto; |
| 25 | align-self: stretch; |
| 26 | } |
| 27 | </style> |
| 28 | <tracing-analysis-nested-table id="table"> |
| 29 | </tracing-analysis-nested-table> |
| 30 | </div> |
| 31 | </template> |
| 32 | <script> |
| 33 | 'use strict'; |
| 34 | |
| 35 | Polymer({ |
| 36 | ready: function() { |
| 37 | this.showTotals_ = false; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 38 | this.eventsHaveDuration_ = true; |
| 39 | this.eventsHaveSubRows_ = true; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 40 | this.eventsByTitle_ = undefined; |
| 41 | }, |
| 42 | |
| 43 | updateTableColumns_: function(rows) { |
| 44 | var hasCpuData = false; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 45 | var hasAlerts = false; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 46 | rows.forEach(function(row) { |
| 47 | if (row.cpuDuration !== undefined) |
| 48 | hasCpuData = true; |
| 49 | if (row.cpuSelfTime !== undefined) |
| 50 | hasCpuData = true; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 51 | if (row.numAlerts) |
| 52 | hasAlerts = true; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 53 | }); |
| 54 | |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 55 | |
| 56 | var columns = []; |
| 57 | |
| 58 | columns.push({ |
| 59 | title: 'Name', |
| 60 | value: function(row) { |
| 61 | if (row.title === 'Totals') |
| 62 | return 'Totals'; |
| 63 | |
| 64 | var linkEl = document.createElement('tv-c-analysis-link'); |
| 65 | linkEl.setSelectionAndContent(function() { |
| 66 | return new tv.c.Selection(row.events); |
| 67 | }, row.title); |
| 68 | return linkEl; |
| 69 | }, |
| 70 | width: '350px', |
| 71 | cmp: function(rowA, rowB) { |
| 72 | return rowA.title.localeCompare(rowB.title); |
| 73 | } |
| 74 | }); |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 75 | if (this.eventsHaveDuration_) { |
| 76 | columns.push({ |
| 77 | title: 'Wall Duration (ms)', |
| 78 | value: function(row) { |
| 79 | return tv.c.analysis.createTimeSpan(row.duration); |
| 80 | }, |
| 81 | width: '<upated further down>', |
| 82 | cmp: function(rowA, rowB) { |
| 83 | return rowA.duration - rowB.duration; |
| 84 | } |
| 85 | }); |
| 86 | } |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 87 | |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 88 | if (this.eventsHaveDuration_ && hasCpuData) { |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 89 | columns.push({ |
| 90 | title: 'CPU Duration (ms)', |
| 91 | value: function(row) { |
| 92 | return tv.c.analysis.createTimeSpan(row.cpuDuration); |
| 93 | }, |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 94 | width: '<upated further down>', |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 95 | cmp: function(rowA, rowB) { |
| 96 | return rowA.cpuDuration - rowB.cpuDuration; |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 101 | if (this.eventsHaveSubRows_ && this.eventsHaveDuration_) { |
| 102 | columns.push({ |
| 103 | title: 'Self time (ms)', |
| 104 | value: function(row) { |
| 105 | return tv.c.analysis.createTimeSpan(row.selfTime); |
| 106 | }, |
| 107 | width: '<upated further down>', |
| 108 | cmp: function(rowA, rowB) { |
| 109 | return rowA.selfTime - rowB.selfTime; |
| 110 | } |
| 111 | }); |
| 112 | } |
| 113 | |
| 114 | if (this.eventsHaveSubRows_ && this.eventsHaveDuration_ && hasCpuData) { |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 115 | columns.push({ |
| 116 | title: 'CPU Self Time (ms)', |
| 117 | value: function(row) { |
| 118 | return tv.c.analysis.createTimeSpan(row.cpuSelfTime); |
| 119 | }, |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 120 | width: '<upated further down>', |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 121 | cmp: function(rowA, rowB) { |
| 122 | return rowA.cpuSelfTime - rowB.cpuSelfTime; |
| 123 | } |
| 124 | }); |
| 125 | } |
| 126 | columns.push({ |
| 127 | title: 'Occurrences', |
| 128 | value: function(row) { |
| 129 | return row.numEvents; |
| 130 | }, |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 131 | width: '<upated further down>', |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 132 | cmp: function(rowA, rowB) { |
| 133 | return rowA.numEvents - rowB.numEvents; |
| 134 | } |
| 135 | }); |
| 136 | |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 137 | var alertsColumnIndex; |
| 138 | if (hasAlerts) { |
| 139 | columns.push({ |
| 140 | title: 'Num Alerts', |
| 141 | value: function(row) { |
| 142 | return row.numAlerts; |
| 143 | }, |
| 144 | width: '<upated further down>', |
| 145 | cmp: function(rowA, rowB) { |
| 146 | return rowA.numAlerts - rowB.numAlerts; |
| 147 | } |
| 148 | }); |
| 149 | alertsColumnIndex = columns.length - 1; |
| 150 | } |
| 151 | var colWidthPercentage; |
| 152 | if (columns.length == 1) |
| 153 | colWidthPercentage = '100%'; |
| 154 | else |
| 155 | colWidthPercentage = (100 / (columns.length - 1)).toFixed(3) + '%'; |
| 156 | |
| 157 | for (var i = 1; i < columns.length; i++) |
| 158 | columns[i].width = colWidthPercentage; |
| 159 | |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 160 | this.$.table.tableColumns = columns; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 161 | |
| 162 | if (hasAlerts) { |
| 163 | this.$.table.sortColumnIndex = alertsColumnIndex; |
| 164 | this.$.table.sortDescending = true; |
| 165 | } |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 166 | }, |
| 167 | |
| 168 | configure: function(config) { |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 169 | if (config.eventsByTitle === undefined) |
| 170 | throw new Error('Required: eventsByTitle'); |
| 171 | |
| 172 | if (config.showTotals !== undefined) |
| 173 | this.showTotals_ = config.showTotals; |
| 174 | else |
| 175 | this.showTotals_ = true; |
| 176 | |
| 177 | if (config.eventsHaveDuration !== undefined) |
| 178 | this.eventsHaveDuration_ = config.eventsHaveDuration; |
| 179 | else |
| 180 | this.eventsHaveDuration_ = true; |
| 181 | |
| 182 | if (config.eventsHaveSubRows !== undefined) |
| 183 | this.eventsHaveSubRows_ = config.eventsHaveSubRows; |
| 184 | else |
| 185 | this.eventsHaveSubRows_ = true; |
| 186 | |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 187 | this.eventsByTitle_ = config.eventsByTitle; |
| 188 | this.updateContents_(); |
| 189 | }, |
| 190 | |
| 191 | get showTotals() { |
| 192 | return this.showTotals_; |
| 193 | }, |
| 194 | |
| 195 | set showTotals(showTotals) { |
| 196 | this.showTotals_ = showTotals; |
| 197 | this.updateContents_(); |
| 198 | }, |
| 199 | |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 200 | get eventsHaveDuration() { |
| 201 | return this.eventsHaveDuration_; |
| 202 | }, |
| 203 | |
| 204 | set eventsHaveDuration(eventsHaveDuration) { |
| 205 | this.eventsHaveDuration_ = eventsHaveDuration; |
| 206 | this.updateContents_(); |
| 207 | }, |
| 208 | |
| 209 | get eventsHaveSubRows() { |
| 210 | return this.eventsHaveSubRows_; |
| 211 | }, |
| 212 | |
| 213 | set eventsHaveSubRows(eventsHaveSubRows) { |
| 214 | this.eventsHaveSubRows_ = eventsHaveSubRows; |
| 215 | this.updateContents_(); |
| 216 | }, |
| 217 | |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 218 | get eventsByTitle() { |
| 219 | return this.eventsByTitle_; |
| 220 | }, |
| 221 | |
| 222 | set eventsByTitle(eventsByTitle) { |
| 223 | this.eventsByTitle_ = eventsByTitle; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 224 | this.updateContents_(); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 225 | }, |
| 226 | |
| 227 | get selectionBounds() { |
| 228 | return this.selectionBounds_; |
| 229 | }, |
| 230 | |
| 231 | set selectionBounds(selectionBounds) { |
| 232 | this.selectionBounds_ = selectionBounds; |
| 233 | this.updateContents_(); |
| 234 | }, |
| 235 | |
| 236 | updateContents_: function() { |
| 237 | var eventsByTitle; |
| 238 | if (this.eventsByTitle_ !== undefined) |
| 239 | eventsByTitle = this.eventsByTitle_; |
| 240 | else |
| 241 | eventsByTitle = []; |
| 242 | |
| 243 | var allEvents = []; |
| 244 | var rows = []; |
| 245 | tv.b.iterItems( |
| 246 | eventsByTitle, |
| 247 | function(title, eventsOfSingleTitle) { |
| 248 | allEvents.push.apply(allEvents, eventsOfSingleTitle); |
| 249 | var row = new tv.c.analysis.MultiEventSummary(title, |
| 250 | eventsOfSingleTitle); |
| 251 | rows.push(row); |
| 252 | }); |
| 253 | |
| 254 | this.updateTableColumns_(rows); |
| 255 | this.$.table.tableRows = rows; |
| 256 | |
| 257 | var footerRows = []; |
| 258 | |
| 259 | if (this.showTotals_) { |
| 260 | footerRows.push( |
| 261 | new tv.c.analysis.MultiEventSummary('Totals', allEvents)); |
| 262 | } |
| 263 | // TODO(selection bounds). |
| 264 | |
| 265 | // TODO(sorting) |
| 266 | |
| 267 | this.$.table.footerRows = footerRows; |
| 268 | this.$.table.rebuild(); |
| 269 | } |
| 270 | }); |
| 271 | </script> |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 272 | </polymer-element> |