| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/statistics.html"> | 8 <link rel="import" href="/tracing/base/statistics.html"> |
| 9 <link rel="import" href="/tracing/metrics/metric_registry.html"> |
| 9 <link rel="import" href="/tracing/metrics/system_health/utils.html"> | 10 <link rel="import" href="/tracing/metrics/system_health/utils.html"> |
| 10 <link rel="import" href="/tracing/model/user_model/animation_expectation.html"> | 11 <link rel="import" href="/tracing/model/user_model/animation_expectation.html"> |
| 11 <link rel="import" href="/tracing/model/user_model/idle_expectation.html"> | 12 <link rel="import" href="/tracing/model/user_model/idle_expectation.html"> |
| 13 <link rel="import" href="/tracing/value/numeric.html"> |
| 14 <link rel="import" href="/tracing/value/value.html"> |
| 12 | 15 |
| 13 <script> | 16 <script> |
| 14 'use strict'; | 17 'use strict'; |
| 15 | 18 |
| 16 tr.exportTo('tr.metrics.sh', function() { | 19 tr.exportTo('tr.metrics.sh', function() { |
| 17 function EfficiencyMetric() { | 20 var UNIT = tr.v.Unit.byName.normalizedPercentage_biggerIsBetter; |
| 21 |
| 22 var DESCRIPTION = 'Normalized CPU budget consumption'; |
| 23 |
| 24 function EfficiencyMetric(valueList, model) { |
| 25 model.userModel.expectations.forEach(function(ue) { |
| 26 var options = {}; |
| 27 options.description = DESCRIPTION; |
| 28 |
| 29 var groupingKeys = {}; |
| 30 groupingKeys.userExpectation = ue.stableId; |
| 31 groupingKeys.userExpectationStageTitle = ue.stageTitle; |
| 32 groupingKeys.userExpectationInitiatorTitle = ue.initiatorTitle; |
| 33 |
| 34 var score = undefined; |
| 35 |
| 36 if ((ue.totalCpuMs === undefined) || |
| 37 (ue.totalCpuMs == 0)) |
| 38 return; |
| 39 |
| 40 var cpuFractionBudget = tr.b.Range.fromExplicitRange(0.5, 1.5); |
| 41 |
| 42 if (ue instanceof tr.model.um.IdleExpectation) { |
| 43 cpuFractionBudget = tr.b.Range.fromExplicitRange(0.1, 1); |
| 44 } else if (ue instanceof tr.model.um.AnimationExpectation) { |
| 45 cpuFractionBudget = tr.b.Range.fromExplicitRange(1, 2); |
| 46 } |
| 47 |
| 48 var cpuMsBudget = tr.b.Range.fromExplicitRange( |
| 49 ue.duration * cpuFractionBudget.min, |
| 50 ue.duration * cpuFractionBudget.max); |
| 51 var normalizedCpu = tr.b.normalize( |
| 52 ue.totalCpuMs, cpuMsBudget.min, cpuMsBudget.max); |
| 53 score = 1 - tr.b.clamp(normalizedCpu, 0, 1); |
| 54 |
| 55 valueList.addValue(new tr.v.NumericValue( |
| 56 model.canonicalUrlThatCreatedThisTrace, 'efficiency', |
| 57 new tr.v.ScalarNumeric(UNIT, score), |
| 58 options, groupingKeys)); |
| 59 }); |
| 18 } | 60 } |
| 19 | 61 |
| 20 EfficiencyMetric.forModel = function(model, opt_rangeOfInterest) { | 62 tr.metrics.MetricRegistry.register(EfficiencyMetric); |
| 21 return tr.b.Statistics.weightedMean( | |
| 22 tr.metrics.sh.filterExpectationsByRange( | |
| 23 model.userModel.expectations, opt_rangeOfInterest), | |
| 24 tr.metrics.sh.perceptualBlend, | |
| 25 EfficiencyMetric.forExpectation); | |
| 26 }; | |
| 27 | |
| 28 EfficiencyMetric.forExpectation = function(ir) { | |
| 29 if ((ir.totalCpuMs === undefined) || | |
| 30 (ir.totalCpuMs == 0)) | |
| 31 return undefined; | |
| 32 | |
| 33 var cpuFractionBudget = tr.b.Range.fromExplicitRange(0.5, 1.5); | |
| 34 | |
| 35 if (ir instanceof tr.model.um.IdleExpectation) { | |
| 36 cpuFractionBudget = tr.b.Range.fromExplicitRange(0.1, 1); | |
| 37 } else if (ir instanceof tr.model.um.AnimationExpectation) { | |
| 38 cpuFractionBudget = tr.b.Range.fromExplicitRange(1, 2); | |
| 39 } | |
| 40 | |
| 41 var cpuMsBudget = tr.b.Range.fromExplicitRange( | |
| 42 ir.duration * cpuFractionBudget.min, | |
| 43 ir.duration * cpuFractionBudget.max); | |
| 44 var normalizedCpu = tr.b.normalize( | |
| 45 ir.totalCpuMs, cpuMsBudget.min, cpuMsBudget.max); | |
| 46 var normalizedCpuEfficiency = 1 - tr.b.clamp(normalizedCpu, 0, 1); | |
| 47 return normalizedCpuEfficiency; | |
| 48 }; | |
| 49 | 63 |
| 50 return { | 64 return { |
| 51 EfficiencyMetric: EfficiencyMetric | 65 EfficiencyMetric: EfficiencyMetric |
| 52 }; | 66 }; |
| 53 }); | 67 }); |
| 54 </script> | 68 </script> |
| OLD | NEW |