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/base/statistics.html"> 9<link rel="import" href="/tracing/metrics/system_health/utils.html"> 10<link rel="import" href="/tracing/model/user_model/animation_expectation.html"> 11 12<script> 13'use strict'; 14 15tr.exportTo('tr.metrics.sh', function() { 16 // The Animation Throughput score is maximized at this value of average 17 // frames-per-second. 18 var MAX_FPS = 60; 19 20 // The Animation Throughput score is minimized at this value of average 21 // frames-per-second. 22 var MIN_FPS = 10; 23 24 var UNIT = tr.v.Unit.byName.normalizedPercentage_biggerIsBetter; 25 26 var DESCRIPTION = 'Mean Opinion Score for Animation throughput'; 27 28 function AnimationThroughputMetric(valueList, model) { 29 model.userModel.expectations.forEach(function(ue) { 30 if (!(ue instanceof tr.model.um.AnimationExpectation)) 31 return; 32 33 if (ue.frameEvents === undefined || 34 ue.frameEvents.length === 0) 35 throw new Error('Animation missing frameEvents ' + ue.stableId); 36 37 var options = {}; 38 options.description = DESCRIPTION; 39 40 var groupingKeys = {}; 41 groupingKeys.userExpectationStableId = ue.stableId; 42 groupingKeys.userExpectationStageTitle = ue.stageTitle; 43 groupingKeys.userExpectationInitiatorTitle = ue.initiatorTitle; 44 45 var durationSeconds = ue.duration / 1000; 46 var avgSpf = durationSeconds / ue.frameEvents.length; 47 var throughput = 1 - tr.b.normalize(avgSpf, 1 / MAX_FPS, 1 / MIN_FPS); 48 var score = tr.b.clamp(throughput, 0, 1); 49 50 valueList.addValue(new tr.v.NumericValue( 51 model.canonicalUrlThatCreatedThisTrace, 'throughput', 52 new tr.v.ScalarNumeric(UNIT, score), 53 options, groupingKeys)); 54 }); 55 } 56 57 AnimationThroughputMetric.prototype = { 58 __proto__: Function.prototype 59 }; 60 61 tr.metrics.MetricRegistry.register(AnimationThroughputMetric); 62 63 return { 64 AnimationThroughputMetric: AnimationThroughputMetric 65 }; 66}); 67</script> 68 69