OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2017 The Chromium Authors. All rights reserved. | 3 Copyright 2017 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/resource_usage_sample.html"> | 12 <link rel="import" href="/tracing/model/resource_usage_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 ResourceUsageSample = tr.model.ResourceUsageSample; | 18 var ResourceUsageSample = tr.model.ResourceUsageSample; |
19 | 19 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 var sample = new ResourceUsageSample(this, ts, val); | 52 var sample = new ResourceUsageSample(this, ts, val); |
53 this.samples_.push(sample); | 53 this.samples_.push(sample); |
54 return sample; | 54 return sample; |
55 } | 55 } |
56 | 56 |
57 /** | 57 /** |
58 * Returns the total time consumed by a resource (e.g. CPU or GPU) between | 58 * Returns the total time consumed by a resource (e.g. CPU or GPU) between |
59 * the specified start and end timestamps (in milliseconds). | 59 * the specified start and end timestamps (in milliseconds). |
60 */ | 60 */ |
61 computeResourceTimeConsumedInMs(start, end) { | 61 computeResourceTimeConsumedInMs(start, end) { |
62 var measurementRange = tr.b.Range.fromExplicitRange(start, end); | 62 var measurementRange = tr.b.math.Range.fromExplicitRange(start, end); |
63 | 63 |
64 var resourceTimeInMs = 0; | 64 var resourceTimeInMs = 0; |
65 var startIndex = tr.b.findLowIndexInSortedArray( | 65 var startIndex = tr.b.math.findLowIndexInSortedArray( |
66 this.samples, x => x.start, start) - 1; | 66 this.samples, x => x.start, start) - 1; |
67 var endIndex = tr.b.findLowIndexInSortedArray( | 67 var endIndex = tr.b.math.findLowIndexInSortedArray( |
68 this.samples, x => x.start, end); | 68 this.samples, x => x.start, end); |
69 | 69 |
70 if (startIndex < 0) startIndex = 0; | 70 if (startIndex < 0) startIndex = 0; |
71 | 71 |
72 for (var i = startIndex; i < endIndex; i++) { | 72 for (var i = startIndex; i < endIndex; i++) { |
73 var sample = this.samples[i]; | 73 var sample = this.samples[i]; |
74 var nextSample = this.samples[i + 1]; | 74 var nextSample = this.samples[i + 1]; |
75 | 75 |
76 var sampleRange = new tr.b.Range(); | 76 var sampleRange = new tr.b.math.Range(); |
77 sampleRange.addValue(sample.start); | 77 sampleRange.addValue(sample.start); |
78 sampleRange.addValue(nextSample ? nextSample.start : sample.start); | 78 sampleRange.addValue(nextSample ? nextSample.start : sample.start); |
79 | 79 |
80 var intersectionRangeInMs = measurementRange.findIntersection( | 80 var intersectionRangeInMs = measurementRange.findIntersection( |
81 sampleRange); | 81 sampleRange); |
82 | 82 |
83 resourceTimeInMs += intersectionRangeInMs.duration * sample.usage; | 83 resourceTimeInMs += intersectionRangeInMs.duration * sample.usage; |
84 } | 84 } |
85 | 85 |
86 return resourceTimeInMs; | 86 return resourceTimeInMs; |
87 } | 87 } |
88 | 88 |
89 getSamplesWithinRange(start, end) { | 89 getSamplesWithinRange(start, end) { |
90 var startIndex = tr.b.findLowIndexInSortedArray( | 90 var startIndex = tr.b.math.findLowIndexInSortedArray( |
91 this.samples, x => x.start, start); | 91 this.samples, x => x.start, start); |
92 var endIndex = tr.b.findLowIndexInSortedArray( | 92 var endIndex = tr.b.math.findLowIndexInSortedArray( |
93 this.samples, x => x.start, end); | 93 this.samples, x => x.start, end); |
94 return this.samples.slice(startIndex, endIndex); | 94 return this.samples.slice(startIndex, endIndex); |
95 } | 95 } |
96 | 96 |
97 shiftTimestampsForward(amount) { | 97 shiftTimestampsForward(amount) { |
98 for (var i = 0; i < this.samples_.length; ++i) | 98 for (var i = 0; i < this.samples_.length; ++i) |
99 this.samples_[i].start += amount; | 99 this.samples_[i].start += amount; |
100 } | 100 } |
101 | 101 |
102 updateBounds() { | 102 updateBounds() { |
103 this.bounds.reset(); | 103 this.bounds.reset(); |
104 | 104 |
105 if (this.samples_.length === 0) return; | 105 if (this.samples_.length === 0) return; |
106 | 106 |
107 this.bounds.addValue(this.samples_[0].start); | 107 this.bounds.addValue(this.samples_[0].start); |
108 this.bounds.addValue(this.samples_[this.samples_.length - 1].start); | 108 this.bounds.addValue(this.samples_[this.samples_.length - 1].start); |
109 } | 109 } |
110 | 110 |
111 * childEvents() { | 111 * childEvents() { |
112 yield* this.samples_; | 112 yield* this.samples_; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 return { | 116 return { |
117 ResourceUsageSeries, | 117 ResourceUsageSeries, |
118 }; | 118 }; |
119 }); | 119 }); |
120 </script> | 120 </script> |
OLD | NEW |