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/core/test_utils.html"> 9 <link rel="import" href="/tracing/metrics/system_health/power_metric.html"> 10 <link rel="import" href="/tracing/value/value_set.html"> 11 12 <script> 13 'use strict'; 14 15 tr.b.unittest.testSuite(function() { 16 test('powerMetric_multipleFrames', function() { 17 var model = new tr.Model(); 18 var valueSet = new tr.v.ValueSet(); 19 model.device.powerSeries = new tr.model.PowerSeries(model.device); 20 // We want values in different frames, so they must go up by more than 16.66 21 // milliseconds. 22 model.device.powerSeries.addPowerSample('1', '.1'); 23 model.device.powerSeries.addPowerSample('2', '.1'); 24 model.device.powerSeries.addPowerSample('18', '.2'); 25 model.device.powerSeries.addPowerSample('36', '.3'); 26 model.device.powerSeries.addPowerSample('53', '.4'); 27 model.device.powerSeries.addPowerSample('70', '.5'); 28 tr.metrics.sh.powerMetric(valueSet, model); 29 var powerEntries = valueSet.valueDicts.filter( 30 (dict) => dict.name === 'energy_consumed_per_frame'); 31 var powerEntry = tr.b.getOnlyElement(powerEntries); 32 assert.equal(powerEntry.centralBins[0].count, 5); 33 assert.closeTo(powerEntry.running.sum, 0.0172, 1e-4); 34 }); 35 36 test('powerMetric_oneFrame', function() { 37 var model = new tr.Model(); 38 var valueSet = new tr.v.ValueSet(); 39 model.device.powerSeries = new tr.model.PowerSeries(model.device); 40 // We want values in the same frame, so they must go up by less than 16.66 41 // milliseconds. 42 model.device.powerSeries.addPowerSample('1', '.1'); 43 model.device.powerSeries.addPowerSample('2', '.1'); 44 model.device.powerSeries.addPowerSample('3', '.2'); 45 model.device.powerSeries.addPowerSample('4', '.3'); 46 model.device.powerSeries.addPowerSample('5', '.4'); 47 model.device.powerSeries.addPowerSample('6', '.5'); 48 tr.metrics.sh.powerMetric(valueSet, model); 49 var powerEntries = valueSet.valueDicts.filter( 50 (dict) => dict.name === 'energy_consumed_per_frame'); 51 var powerEntry = tr.b.getOnlyElement(powerEntries); 52 assert.equal(powerEntry.centralBins[0].count, 1); 53 assert.closeTo(powerEntry.running.sum, 0.0011, 1e-4); 54 }); 55 56 test('powerMetric_noPowerSeries', function() { 57 var model = new tr.Model(); 58 var valueSet = new tr.v.ValueSet(); 59 tr.metrics.sh.powerMetric(valueSet, model); 60 var powerEntries = valueSet.valueDicts.filter( 61 (dict) => dict.name === 'energy_consumed_per_frame'); 62 assert.lengthOf(powerEntries, 0); 63 }); 64 }); 65 </script> 66