blob: 765869b6f4f4a026e7c9ef320ad1db07a8e094d3 [file] [log] [blame]
<!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 Animation Throughput score is maximized at this value of average
// frames-per-second.
var MAX_FPS = 60;
// The Animation Throughput score is minimized at this value of average
// frames-per-second.
var MIN_FPS = 10;
var UNIT = tr.v.Unit.byName.normalizedPercentage_biggerIsBetter;
var DESCRIPTION = 'Mean Opinion Score for Animation throughput';
function AnimationThroughputMetric(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 durationSeconds = ue.duration / 1000;
var avgSpf = durationSeconds / ue.frameEvents.length;
var throughput = 1 - tr.b.normalize(avgSpf, 1 / MAX_FPS, 1 / MIN_FPS);
var score = tr.b.clamp(throughput, 0, 1);
valueList.addValue(new tr.v.NumericValue(
model.canonicalUrlThatCreatedThisTrace, 'throughput',
new tr.v.ScalarNumeric(UNIT, score),
options, groupingKeys));
});
}
AnimationThroughputMetric.prototype = {
__proto__: Function.prototype
};
tr.metrics.MetricRegistry.register(AnimationThroughputMetric);
return {
AnimationThroughputMetric: AnimationThroughputMetric
};
});
</script>