| <!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/system_health/utils.html"> |
| <link rel="import" href="/tracing/model/user_model/animation_expectation.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.metrics.sh', function() { |
| // The smoothness score is maximized when frame timestamp discrepancy is |
| // less than or equal to this: |
| var MIN_DISCREPANCY = 0.05; |
| |
| // The smoothness score is minimized when frame timestamp discrepancy is |
| // greater than or equal to this: |
| var MAX_DISCREPANCY = 0.3; |
| |
| var UNIT = tr.v.Unit.byName.normalizedPercentage_biggerIsBetter; |
| |
| var DESCRIPTION = 'Mean Opinion Score for Animation smoothness'; |
| |
| function AnimationSmoothnessMetric(valueList, model) { |
| model.userModel.expectations.forEach(function(ue) { |
| if (!(ue instanceof tr.model.um.AnimationExpectation)) |
| return; |
| |
| if (ue.frameEvents === undefined || |
| ue.frameEvents.length === 0) |
| throw new Error('Animation missing frameEvents ' + ue.stableId); |
| |
| var options = {}; |
| options.description = DESCRIPTION; |
| |
| var groupingKeys = {}; |
| groupingKeys.userExpectationStableId = ue.stableId; |
| groupingKeys.userExpectationStageTitle = ue.stageTitle; |
| groupingKeys.userExpectationInitiatorTitle = ue.initiatorTitle; |
| |
| var frameTimestamps = ue.frameEvents.toArray().map(function(event) { |
| return event.start; |
| }); |
| |
| var absolute = false; |
| var discrepancy = tr.b.Statistics.timestampsDiscrepancy( |
| frameTimestamps, absolute); |
| var smoothness = 1 - tr.b.normalize( |
| discrepancy, MIN_DISCREPANCY, MAX_DISCREPANCY); |
| var score = tr.b.clamp(smoothness, 0, 1); |
| |
| valueList.addValue(new tr.v.NumericValue( |
| model.canonicalUrlThatCreatedThisTrace, 'smoothness', |
| new tr.v.ScalarNumeric(UNIT, score), |
| options, groupingKeys)); |
| }); |
| } |
| |
| AnimationSmoothnessMetric.prototype = { |
| __proto__: Function.prototype |
| }; |
| |
| tr.metrics.MetricRegistry.register(AnimationSmoothnessMetric); |
| |
| return { |
| AnimationSmoothnessMetric: AnimationSmoothnessMetric |
| }; |
| }); |
| </script> |