| <!DOCTYPE html> |
| <!-- |
| Copyright 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/model/event_set.html"> |
| <link rel="import" href="/tracing/ui/base/table.html"> |
| <link rel="import" href="/tracing/value/unit.html"> |
| |
| <polymer-element name="tr-ui-a-power-sample-summary-table"> |
| <template> |
| <tr-ui-b-table id="table"></tr-ui-b-table> |
| </template> |
| <script> |
| 'use strict'; |
| |
| Polymer({ |
| ready: function() { |
| this.$.table.tableColumns = [ |
| { |
| title: 'Min power', |
| width: '100px', |
| value: function(row) { |
| return tr.v.Unit.byName.powerInWatts.format(row.min / 1000.0); |
| } |
| }, |
| { |
| title: 'Max power', |
| width: '100px', |
| value: function(row) { |
| return tr.v.Unit.byName.powerInWatts.format(row.max / 1000.0); |
| } |
| }, |
| { |
| title: 'Time-weighted average', |
| width: '100px', |
| value: function(row) { |
| return tr.v.Unit.byName.powerInWatts.format( |
| row.timeWeightedAverage / 1000.0); |
| } |
| }, |
| { |
| title: 'Energy consumed', |
| width: '100px', |
| value: function(row) { |
| return tr.v.Unit.byName.energyInJoules.format(row.energyConsumed); |
| } |
| }, |
| { |
| title: 'Sample count', |
| width: '100%', |
| value: function(row) { return row.sampleCount; } |
| } |
| ]; |
| this.samples = new tr.model.EventSet(); |
| }, |
| |
| get samples() { |
| return this.samples_; |
| }, |
| |
| set samples(samples) { |
| if (samples === this.samples) |
| return; |
| |
| this.samples_ = |
| (samples === undefined) ? new tr.model.EventSet() : samples; |
| this.updateContents_(); |
| }, |
| |
| updateContents_: function() { |
| if (this.samples.length === 0) { |
| this.$.table.tableRows = []; |
| } else { |
| this.$.table.tableRows = [{ |
| min: this.getMin(), |
| max: this.getMax(), |
| timeWeightedAverage: this.getTimeWeightedAverage(), |
| energyConsumed: this.getEnergyConsumed(), |
| sampleCount: this.samples.length |
| }]; |
| } |
| |
| this.$.table.rebuild(); |
| }, |
| |
| getMin: function() { |
| return Math.min.apply(null, this.samples.map(function(sample) { |
| return sample.power; |
| })); |
| }, |
| |
| getMax: function() { |
| return Math.max.apply(null, this.samples.map(function(sample) { |
| return sample.power; |
| })); |
| }, |
| |
| /** |
| * Returns a time-weighted average of the power consumption in between the |
| * first sample (inclusive) and last sample (exclusive). |
| */ |
| getTimeWeightedAverage: function() { |
| var energyConsumed = this.getEnergyConsumed(); |
| |
| if (energyConsumed === 'N/A') |
| return 'N/A'; |
| |
| // Multiply by 1000 to convert Joules to milliJoules. |
| var energyInMillijoules = this.getEnergyConsumed() * 1000; |
| |
| // Divide by 1000 to convert milliseconds to seconds. |
| var durationInSeconds = this.samples.bounds.duration / 1000; |
| |
| // Convert energy to power in milliwatts by dividing by time in seconds. |
| return energyInMillijoules / durationInSeconds; |
| }, |
| |
| getEnergyConsumed: function() { |
| if (this.samples.length < 2) |
| return 'N/A'; |
| |
| var bounds = this.samples.bounds; |
| return this.samples[0].series.getEnergyConsumed(bounds.min, bounds.max); |
| } |
| }); |
| </script> |
| </polymer-element> |