| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/range.html"> | 8 <link rel="import" href="/tracing/base/math/range.html"> |
| 9 <link rel="import" href="/tracing/base/sorted_array_utils.html"> | 9 <link rel="import" href="/tracing/base/math/sorted_array_utils.html"> |
| 10 <link rel="import" href="/tracing/base/unit_scale.html"> | 10 <link rel="import" href="/tracing/base/unit_scale.html"> |
| 11 <link rel="import" href="/tracing/model/event_container.html"> | 11 <link rel="import" href="/tracing/model/event_container.html"> |
| 12 <link rel="import" href="/tracing/model/power_sample.html"> | 12 <link rel="import" href="/tracing/model/power_sample.html"> |
| 13 | 13 |
| 14 <script> | 14 <script> |
| 15 'use strict'; | 15 'use strict'; |
| 16 | 16 |
| 17 tr.exportTo('tr.model', function() { | 17 tr.exportTo('tr.model', function() { |
| 18 var PowerSample = tr.model.PowerSample; | 18 var PowerSample = tr.model.PowerSample; |
| 19 | 19 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 var sample = new PowerSample(this, ts, val); | 54 var sample = new PowerSample(this, ts, val); |
| 55 this.samples_.push(sample); | 55 this.samples_.push(sample); |
| 56 return sample; | 56 return sample; |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Returns the total energy (in Joules) consumed between the specified | 60 * Returns the total energy (in Joules) consumed between the specified |
| 61 * start and end timestamps (in milliseconds). | 61 * start and end timestamps (in milliseconds). |
| 62 */ | 62 */ |
| 63 getEnergyConsumedInJ: function(start, end) { | 63 getEnergyConsumedInJ: function(start, end) { |
| 64 var measurementRange = tr.b.Range.fromExplicitRange(start, end); | 64 var measurementRange = tr.b.math.Range.fromExplicitRange(start, end); |
| 65 | 65 |
| 66 var energyConsumedInJ = 0; | 66 var energyConsumedInJ = 0; |
| 67 var startIndex = tr.b.findLowIndexInSortedArray( | 67 var startIndex = tr.b.math.findLowIndexInSortedArray( |
| 68 this.samples, x => x.start, start) - 1; | 68 this.samples, x => x.start, start) - 1; |
| 69 var endIndex = tr.b.findLowIndexInSortedArray( | 69 var endIndex = tr.b.math.findLowIndexInSortedArray( |
| 70 this.samples, x => x.start, end); | 70 this.samples, x => x.start, end); |
| 71 | 71 |
| 72 if (startIndex < 0) | 72 if (startIndex < 0) |
| 73 startIndex = 0; | 73 startIndex = 0; |
| 74 | 74 |
| 75 for (var i = startIndex; i < endIndex; i++) { | 75 for (var i = startIndex; i < endIndex; i++) { |
| 76 var sample = this.samples[i]; | 76 var sample = this.samples[i]; |
| 77 var nextSample = this.samples[i + 1]; | 77 var nextSample = this.samples[i + 1]; |
| 78 | 78 |
| 79 var sampleRange = new tr.b.Range(); | 79 var sampleRange = new tr.b.math.Range(); |
| 80 sampleRange.addValue(sample.start); | 80 sampleRange.addValue(sample.start); |
| 81 sampleRange.addValue(nextSample ? nextSample.start : sample.start); | 81 sampleRange.addValue(nextSample ? nextSample.start : sample.start); |
| 82 | 82 |
| 83 var intersectionRangeInMs = measurementRange.findIntersection( | 83 var intersectionRangeInMs = measurementRange.findIntersection( |
| 84 sampleRange); | 84 sampleRange); |
| 85 | 85 |
| 86 var durationInS = tr.b.convertUnit(intersectionRangeInMs.duration, | 86 var durationInS = tr.b.convertUnit(intersectionRangeInMs.duration, |
| 87 tr.b.UnitPrefixScale.METRIC.MILLI, | 87 tr.b.UnitPrefixScale.METRIC.MILLI, |
| 88 tr.b.UnitPrefixScale.METRIC.NONE); | 88 tr.b.UnitPrefixScale.METRIC.NONE); |
| 89 | 89 |
| 90 energyConsumedInJ += durationInS * sample.powerInW; | 90 energyConsumedInJ += durationInS * sample.powerInW; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return energyConsumedInJ; | 93 return energyConsumedInJ; |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 getSamplesWithinRange: function(start, end) { | 96 getSamplesWithinRange: function(start, end) { |
| 97 var startIndex = tr.b.findLowIndexInSortedArray( | 97 var startIndex = tr.b.math.findLowIndexInSortedArray( |
| 98 this.samples, x => x.start, start); | 98 this.samples, x => x.start, start); |
| 99 var endIndex = tr.b.findLowIndexInSortedArray( | 99 var endIndex = tr.b.math.findLowIndexInSortedArray( |
| 100 this.samples, x => x.start, end); | 100 this.samples, x => x.start, end); |
| 101 return this.samples.slice(startIndex, endIndex); | 101 return this.samples.slice(startIndex, endIndex); |
| 102 }, | 102 }, |
| 103 | 103 |
| 104 shiftTimestampsForward: function(amount) { | 104 shiftTimestampsForward: function(amount) { |
| 105 for (var i = 0; i < this.samples_.length; ++i) | 105 for (var i = 0; i < this.samples_.length; ++i) |
| 106 this.samples_[i].start += amount; | 106 this.samples_[i].start += amount; |
| 107 }, | 107 }, |
| 108 | 108 |
| 109 updateBounds: function() { | 109 updateBounds: function() { |
| 110 this.bounds.reset(); | 110 this.bounds.reset(); |
| 111 | 111 |
| 112 if (this.samples_.length === 0) | 112 if (this.samples_.length === 0) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 this.bounds.addValue(this.samples_[0].start); | 115 this.bounds.addValue(this.samples_[0].start); |
| 116 this.bounds.addValue(this.samples_[this.samples_.length - 1].start); | 116 this.bounds.addValue(this.samples_[this.samples_.length - 1].start); |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 childEvents: function* () { | 119 childEvents: function* () { |
| 120 yield* this.samples_; | 120 yield* this.samples_; |
| 121 }, | 121 }, |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 return { | 124 return { |
| 125 PowerSeries, | 125 PowerSeries, |
| 126 }; | 126 }; |
| 127 }); | 127 }); |
| 128 </script> | 128 </script> |
| OLD | NEW |