1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 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/metrics/value_list.html"> 9<link rel="import" href="/tracing/ui/analysis/analysis_sub_view.html"> 10<link rel="import" href="/tracing/ui/analysis/single_event_sub_view.html"> 11<link rel="import" href="/tracing/value/ui/scalar_span.html"> 12<link rel="import" href="/tracing/value/unit.html"> 13 14<polymer-element name="tr-ui-a-single-user-expectation-sub-view" 15 extends="tr-ui-a-sub-view"> 16 <script> 17 'use strict'; 18 19 Polymer({ 20 created: function() { 21 this.currentSelection_ = undefined; 22 this.realView_ = undefined; 23 }, 24 25 get selection() { 26 return this.currentSelection_; 27 }, 28 29 set selection(selection) { 30 this.textContent = ''; 31 this.realView_ = document.createElement('tr-ui-a-single-event-sub-view'); 32 this.realView_.addEventListener('customize-rows', 33 this.onCustomizeRows_.bind(this)); 34 35 this.appendChild(this.realView_); 36 this.currentSelection_ = selection; 37 this.realView_.setSelectionWithoutErrorChecks(selection); 38 }, 39 40 get relatedEventsToHighlight() { 41 if (!this.currentSelection_) 42 return undefined; 43 return this.currentSelection_[0].associatedEvents; 44 }, 45 46 onCustomizeRows_: function(event) { 47 var ue = this.selection[0]; 48 49 var valueList = new tr.metrics.ValueList(); 50 51 function runMetric(metricInfo) { 52 try { 53 metricInfo.constructor(valueList, ue.parentModel); 54 } catch (failure) { 55 console.error(metricInfo, failure); 56 } 57 } 58 59 tr.metrics.MetricRegistry.getAllRegisteredTypeInfos().forEach(runMetric); 60 61 // Metrics may have been computed more than once, so avoid displaying them 62 // more than once by collecting them in a dictionary. 63 // https://github.com/catapult-project/catapult/issues/2154 64 var metricValues = {}; 65 66 valueList.valueDicts.forEach(function(value) { 67 if (value.grouping_keys.userExpectationStableId !== ue.stableId) 68 return; 69 70 if ((value.type !== 'numeric') || 71 (value.numeric.type !== 'scalar')) 72 return; 73 74 metricValues[value.grouping_keys.name] = value.numeric; 75 }); 76 77 for (var name in metricValues) { 78 event.rows.push({ 79 name: name, 80 value: tr.v.ui.createScalarSpan(metricValues[name].value, { 81 unit: tr.v.Unit.fromJSON(metricValues[name].unit) 82 }) 83 }); 84 } 85 86 if (ue.rawCpuMs) { 87 event.rows.push({ 88 name: 'Total CPU', 89 value: tr.v.ui.createScalarSpan(ue.totalCpuMs, { 90 unit: tr.v.Unit.byName.timeDurationInMs 91 }) 92 }); 93 } 94 } 95 }); 96 </script> 97</polymer-element> 98