1 <!DOCTYPE html> 2 <!-- 3 Copyright 2016 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 8 <link rel="import" href="/tracing/base/statistics.html"> 9 <link rel="import" href="/tracing/metrics/metric_registry.html"> 10 <link rel="import" href="/tracing/metrics/system_health/clock_sync_latency_metric.html"> 11 <link rel="import" href="/tracing/value/histogram.html"> 12 13 <script> 14 'use strict'; 15 16 tr.exportTo('tr.metrics.sh', function() { 17 18 var IDEAL_FRAME_RATE_FPS = 60; 19 var IDEAL_FRAME_DURATION_MS = tr.b.convertUnit(1.0 / IDEAL_FRAME_RATE_FPS, 20 tr.b.UnitScale.Metric.NONE, tr.b.UnitScale.Metric.MILLI); 21 22 function energyConsumedPerFrame(valueList, model) { 23 var frameEnergyConsumedInJ = new tr.v.Histogram('energy_consumed_per_frame', 24 tr.b.Unit.byName.energyInJoules_smallerIsBetter, 25 tr.v.HistogramBinBoundaries.createLinear(0, 0.5, 20)); 26 frameEnergyConsumedInJ.description = 27 'Energy consumption per frame in joules'; 28 29 var frameStartTs = parseFloat(model.device.powerSeries.samples[0].start); 30 while (model.device.powerSeries.getSamplesWithinRange( 31 frameStartTs, frameStartTs + IDEAL_FRAME_DURATION_MS).length) { 32 var currentFrameEnergy = model.device.powerSeries.getEnergyConsumedInJ( 33 frameStartTs, frameStartTs + IDEAL_FRAME_DURATION_MS); 34 frameStartTs += IDEAL_FRAME_DURATION_MS; 35 frameEnergyConsumedInJ.addSample(currentFrameEnergy); 36 } 37 38 valueList.addHistogram(frameEnergyConsumedInJ); 39 } 40 41 function powerMetric(valueList, model) { 42 if (!model.device.powerSeries) 43 return; 44 45 energyConsumedPerFrame(valueList, model); 46 } 47 48 tr.metrics.MetricRegistry.register(powerMetric); 49 50 return { 51 powerMetric: powerMetric 52 }; 53 }); 54 </script> 55