| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/tracing/base/statistics.html"> |
| <link rel="import" href="/tracing/metrics/metric_registry.html"> |
| <link rel="import" href="/tracing/metrics/system_health/utils.html"> |
| <link rel="import" href="/tracing/model/user_model/animation_expectation.html"> |
| <link rel="import" href="/tracing/model/user_model/idle_expectation.html"> |
| <link rel="import" href="/tracing/value/numeric.html"> |
| <link rel="import" href="/tracing/value/value.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.metrics.sh', function() { |
| var UNIT = tr.v.Unit.byName.normalizedPercentage_biggerIsBetter; |
| |
| var DESCRIPTION = 'Normalized CPU budget consumption'; |
| |
| function EfficiencyMetric(valueList, model) { |
| var scores = []; |
| |
| model.userModel.expectations.forEach(function(ue) { |
| var options = {}; |
| options.description = DESCRIPTION; |
| |
| var groupingKeys = {}; |
| groupingKeys.userExpectationStableId = ue.stableId; |
| groupingKeys.userExpectationStageTitle = ue.stageTitle; |
| groupingKeys.userExpectationInitiatorTitle = ue.initiatorTitle; |
| |
| var score = undefined; |
| |
| if ((ue.totalCpuMs === undefined) || |
| (ue.totalCpuMs == 0)) |
| return; |
| |
| var cpuFractionBudget = tr.b.Range.fromExplicitRange(0.5, 1.5); |
| |
| if (ue instanceof tr.model.um.IdleExpectation) { |
| cpuFractionBudget = tr.b.Range.fromExplicitRange(0.1, 1); |
| } else if (ue instanceof tr.model.um.AnimationExpectation) { |
| cpuFractionBudget = tr.b.Range.fromExplicitRange(1, 2); |
| } |
| |
| var cpuMsBudget = tr.b.Range.fromExplicitRange( |
| ue.duration * cpuFractionBudget.min, |
| ue.duration * cpuFractionBudget.max); |
| var normalizedCpu = tr.b.normalize( |
| ue.totalCpuMs, cpuMsBudget.min, cpuMsBudget.max); |
| score = 1 - tr.b.clamp(normalizedCpu, 0, 1); |
| |
| scores.push(score); |
| |
| valueList.addValue(new tr.v.NumericValue( |
| model.canonicalUrlThatCreatedThisTrace, 'efficiency', |
| new tr.v.ScalarNumeric(UNIT, score), |
| options, groupingKeys)); |
| }); |
| |
| // Manually reduce scores. |
| // https://github.com/catapult-project/catapult/issues/2036 |
| |
| var options = {}; |
| options.description = DESCRIPTION; |
| var groupingKeys = {}; |
| var overallScore = tr.b.Statistics.weightedMean( |
| scores, tr.metrics.sh.perceptualBlend); |
| if (overallScore === undefined) |
| return; |
| |
| valueList.addValue(new tr.v.NumericValue( |
| model.canonicalUrlThatCreatedThisTrace, 'efficiency', |
| new tr.v.ScalarNumeric(UNIT, overallScore), |
| options, groupingKeys)); |
| } |
| |
| EfficiencyMetric.prototype = { |
| __proto__: Function.prototype |
| }; |
| |
| tr.metrics.MetricRegistry.register(EfficiencyMetric); |
| |
| return { |
| EfficiencyMetric: EfficiencyMetric |
| }; |
| }); |
| </script> |