1<!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="/tracing/base/iteration_helpers.html"> 9<link rel="import" href="/tracing/ui/analysis/analysis_sub_view.html"> 10<link rel="import" href="/tracing/ui/base/table.html"> 11 12<polymer-element name='tr-ui-a-counter-sample-sub-view' 13 extends='tr-ui-a-sub-view'> 14 <template> 15 <style> 16 :host { 17 display: flex; 18 flex-direction: column; 19 } 20 </style> 21 <tr-ui-b-table id='table'></tr-ui-b-table> 22 </template> 23</polymer-element> 24 25<script> 26'use strict'; 27(function() { 28 var COUNTER_SAMPLE_TABLE_COLUMNS = [ 29 { 30 title: 'Counter', 31 width: '150px', 32 value: function(row) { return row.counter; } 33 }, 34 { 35 title: 'Series', 36 width: '150px', 37 value: function(row) { return row.series; } 38 }, 39 { 40 title: 'Time', 41 width: '150px', 42 value: function(row) { return row.start; } 43 }, 44 { 45 title: 'Value', 46 width: '100%', 47 value: function(row) { return row.value; } 48 } 49 ]; 50 51 Polymer('tr-ui-a-counter-sample-sub-view', { 52 ready: function() { 53 this.currentSelection_ = undefined; 54 this.$.table.tableColumns = COUNTER_SAMPLE_TABLE_COLUMNS; 55 }, 56 57 get selection() { 58 return this.currentSelection_; 59 }, 60 61 set selection(selection) { 62 this.currentSelection_ = selection; 63 this.updateContents_(); 64 }, 65 66 updateContents_: function() { 67 this.$.table.tableRows = 68 this.selection ? this.getRows_(this.selection.toArray()) : []; 69 this.$.table.rebuild(); 70 }, 71 72 /** 73 * Returns the table rows for the specified samples. 74 * 75 * We print each counter/series combination the first time that it 76 * appears. For subsequent samples in each series, we omit the counter 77 * and series name. This makes it easy to scan to find the next series. 78 * 79 * Each series can be collapsed. In the expanded state, all samples 80 * are shown. In the collapsed state, only the first sample is displayed. 81 */ 82 getRows_: function(samples) { 83 var samplesByCounter = tr.b.group(samples, function(sample) { 84 return sample.series.counter.guid; 85 }); 86 87 var rows = []; 88 tr.b.iterItems(samplesByCounter, function(unused, counterSamples) { 89 var samplesBySeries = tr.b.group(counterSamples, function(sample) { 90 return sample.series.guid; 91 }); 92 93 tr.b.iterItems(samplesBySeries, function(unused, seriesSamples) { 94 var seriesRows = this.getRowsForSamples_(seriesSamples); 95 seriesRows[0].counter = seriesSamples[0].series.counter.name; 96 seriesRows[0].series = seriesSamples[0].series.name; 97 98 if (seriesRows.length > 1) { 99 seriesRows[0].subRows = seriesRows.slice(1); 100 seriesRows[0].isExpanded = true; 101 } 102 103 rows.push(seriesRows[0]); 104 }, this); 105 }, this); 106 107 return rows; 108 }, 109 110 getRowsForSamples_: function(samples) { 111 return samples.map(function(sample) { 112 return { 113 start: sample.timestamp, 114 value: sample.value 115 }; 116 }); 117 } 118 }); 119})(); 120</script> 121