Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/range.html"> |
| 9 <link rel="import" href="/tracing/base/unit.html"> | 9 <link rel="import" href="/tracing/base/unit.html"> |
| 10 <link rel="import" href="/tracing/extras/v8/runtime_stats_entry.html"> | 10 <link rel="import" href="/tracing/extras/v8/runtime_stats_entry.html"> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 std: false, count: false, sum: false, min: false, max: false | 74 std: false, count: false, sum: false, min: false, max: false |
| 75 }); | 75 }); |
| 76 return histogram; | 76 return histogram; |
| 77 } | 77 } |
| 78 | 78 |
| 79 function convertMicroToMilli_(time) { | 79 function convertMicroToMilli_(time) { |
| 80 return tr.b.convertUnit(time, | 80 return tr.b.convertUnit(time, |
| 81 tr.b.UnitPrefixScale.METRIC.MICRO, tr.b.UnitPrefixScale.METRIC.MILLI); | 81 tr.b.UnitPrefixScale.METRIC.MICRO, tr.b.UnitPrefixScale.METRIC.MILLI); |
| 82 } | 82 } |
| 83 | 83 |
| 84 function computeRuntimeStats(values, model, endTime) { | 84 // TODO(crbug.com/688342): Remove this function when runtimeStatsMetric is |
| 85 var slices = [...model.getDescendantEvents()].filter(event => | 85 // removed. |
| 86 event instanceof tr.e.v8.V8ThreadSlice && | 86 function computeRuntimeStats(histograms, slices) { |
| 87 event.start <= endTime); | |
| 88 | 87 |
| 89 var runtimeGroupCollection = new tr.e.v8.RuntimeStatsGroupCollection(); | 88 var runtimeGroupCollection = new tr.e.v8.RuntimeStatsGroupCollection(); |
| 90 runtimeGroupCollection.addSlices(slices); | 89 runtimeGroupCollection.addSlices(slices); |
| 91 | 90 |
| 92 for (var runtimeGroup of runtimeGroupCollection.runtimeGroups) { | 91 for (var runtimeGroup of runtimeGroupCollection.runtimeGroups) { |
| 93 var durationSamples = new tr.v.d.RelatedHistogramBreakdown(); | 92 var durationSamples = new tr.v.d.RelatedHistogramBreakdown(); |
| 94 var countSamples = new tr.v.d.RelatedHistogramBreakdown(); | 93 var countSamples = new tr.v.d.RelatedHistogramBreakdown(); |
| 95 for (var entry of runtimeGroup.values) { | 94 for (var entry of runtimeGroup.values) { |
| 96 var durationSampleHistogram = createDurationHistogram_(entry.name); | 95 var durationSampleHistogram = createDurationHistogram_(entry.name); |
| 97 durationSampleHistogram.addSample(convertMicroToMilli_(entry.time)); | 96 durationSampleHistogram.addSample(convertMicroToMilli_(entry.time)); |
| 98 durationSamples.set(entry.name + ':duration', durationSampleHistogram); | 97 durationSamples.set(entry.name + ':duration', durationSampleHistogram); |
| 99 values.addHistogram(durationSampleHistogram); | 98 histograms.addHistogram(durationSampleHistogram); |
| 100 | 99 |
| 101 var countSampleHistogram = createCountHistogram_(entry.name); | 100 var countSampleHistogram = createCountHistogram_(entry.name); |
| 102 countSampleHistogram.addSample(entry.count); | 101 countSampleHistogram.addSample(entry.count); |
| 103 countSamples.set(entry.name + ':count', countSampleHistogram); | 102 countSamples.set(entry.name + ':count', countSampleHistogram); |
| 104 values.addHistogram(countSampleHistogram); | 103 histograms.addHistogram(countSampleHistogram); |
| 105 } | 104 } |
| 106 | 105 |
| 107 var durationHistogram = createDurationHistogram_(runtimeGroup.name); | 106 var durationHistogram = createDurationHistogram_(runtimeGroup.name); |
| 108 durationHistogram.addSample(convertMicroToMilli_(runtimeGroup.time), { | 107 durationHistogram.addSample(convertMicroToMilli_(runtimeGroup.time), { |
| 109 samples: durationSamples | 108 samples: durationSamples |
| 110 }); | 109 }); |
| 111 var countHistogram = createCountHistogram_(runtimeGroup.name); | 110 var countHistogram = createCountHistogram_(runtimeGroup.name); |
| 112 countHistogram.addSample(runtimeGroup.count, { | 111 countHistogram.addSample(runtimeGroup.count, { |
| 113 samples: countSamples | 112 samples: countSamples |
| 114 }); | 113 }); |
| 115 | 114 |
| 116 values.addHistogram(durationHistogram); | 115 histograms.addHistogram(durationHistogram); |
| 117 values.addHistogram(countHistogram); | 116 histograms.addHistogram(countHistogram); |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 | 119 |
| 121 function runtimeStatsMetric(values, model) { | 120 // TODO(crbug.com/688342): Remove this metric and use runtimeStatsTotalMetric |
| 121 // instead when the runtimeStatsTotalMetric is stable. | |
| 122 function runtimeStatsMetric(histograms, model) { | |
| 122 var interactiveTime = computeInteractiveTime_(model); | 123 var interactiveTime = computeInteractiveTime_(model); |
| 123 var domContentLoadedTime = computeDomContentLoadedTime_(model); | 124 var domContentLoadedTime = computeDomContentLoadedTime_(model); |
| 124 var endTime = Math.max(interactiveTime, domContentLoadedTime); | 125 var endTime = Math.max(interactiveTime, domContentLoadedTime); |
| 125 computeRuntimeStats(values, model, endTime); | 126 var slices = [...model.getDescendantEvents()].filter(event => |
| 127 event instanceof tr.e.v8.V8ThreadSlice && event.start <= endTime); | |
| 128 computeRuntimeStats(histograms, slices); | |
| 126 } | 129 } |
| 127 | 130 |
| 131 function computeRuntimeStatsBucketOnUE(histograms, slices, | |
| 132 histogramNamePrefix) { | |
| 133 var runtimeGroupCollection = new tr.e.v8.RuntimeStatsGroupCollection(); | |
| 134 runtimeGroupCollection.addSlices(slices); | |
| 135 | |
| 136 for (var runtimeGroup of runtimeGroupCollection.runtimeGroups) { | |
| 137 var histogramName = histogramNamePrefix + '_' + runtimeGroup.name; | |
| 138 var durationHistogram = createDurationHistogram_(histogramName); | |
| 139 durationHistogram.addSample(convertMicroToMilli_(runtimeGroup.time)); | |
| 140 histograms.addHistogram(durationHistogram); | |
| 141 | |
| 142 var countHistogram = createCountHistogram_(histogramName); | |
| 143 countHistogram.addSample(runtimeGroup.count); | |
| 144 histograms.addHistogram(countHistogram); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 function runtimeStatsTotalMetric(histograms, model) { | |
| 149 var v8ThreadSlices = [...model.getDescendantEvents()].filter(event => | |
| 150 event instanceof tr.e.v8.V8ThreadSlice).sort((e1, e2) => | |
| 151 e1.start - e2.start); | |
| 152 var v8SlicesBucketOnUEMap = {}; | |
|
benjhayden
2017/02/10 17:59:25
Please use ES6 Maps instead of dictionaries.
mythria
2017/02/13 15:54:49
Done.
| |
| 153 // User expectations can sometime overlap. So, certain v8 slices can be | |
| 154 // included in more than one expectation. We count such slices in each | |
| 155 // of the expectations. This is done so as to minimize the noise due to | |
| 156 // the differences in the extent of overlap between the runs. | |
| 157 for (var expectation of model.userModel.expectations) { | |
| 158 var slices = expectation.range.filterArray(v8ThreadSlices, | |
| 159 event => event.start); | |
| 160 if (slices.length === 0) continue; | |
| 161 // filterArray filters the array that intersects the range inclusively. | |
| 162 // Expectations are not inclusive i.e. expectations are like [0, 1), | |
| 163 // [1, 2). v8ThreadSlices that start at 1 should be counted only in [1,2) | |
| 164 // bucket. Filter out sample at the boundary so that they are not counted | |
| 165 // twice. | |
| 166 var lastSlice = slices[slices.length - 1]; | |
| 167 if (!expectation.range.intersectsRangeExclusive(lastSlice.range)) | |
|
benjhayden
2017/02/10 17:59:25
Please use curly braces here.
https://github.com/c
mythria
2017/02/13 15:54:49
Thanks. Done.
| |
| 168 slices.pop(); | |
| 169 | |
| 170 if (v8SlicesBucketOnUEMap[expectation.stageTitle] === undefined) { | |
| 171 v8SlicesBucketOnUEMap[expectation.stageTitle] = slices; | |
| 172 } else { | |
| 173 var totalSlices = v8SlicesBucketOnUEMap[expectation.stageTitle].concat( | |
| 174 slices); | |
| 175 v8SlicesBucketOnUEMap[expectation.stageTitle] = totalSlices; | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 // Add histograms for each UE. | |
| 180 for (var name in v8SlicesBucketOnUEMap) { | |
| 181 computeRuntimeStatsBucketOnUE(histograms, v8SlicesBucketOnUEMap[name], | |
| 182 name); | |
|
mythria
2017/02/09 17:21:39
We just want to add one sample per each UE, basica
benjhayden
2017/02/10 17:59:25
Just to clarify, this doesn't add one sample per U
mythria
2017/02/13 15:54:49
Thanks for the detailed explanation.
| |
| 183 } | |
| 184 // Also compute the metric that includes all of the samples. The values | |
| 185 // in UE buckets do not add up to the total of all samples, since we | |
| 186 // duplicate some of the samples in multiple buckets when the UEs overlap. | |
| 187 computeRuntimeStatsBucketOnUE(histograms, v8ThreadSlices, 'Any'); | |
| 188 } | |
| 189 | |
| 190 tr.metrics.MetricRegistry.register(runtimeStatsTotalMetric); | |
| 128 tr.metrics.MetricRegistry.register(runtimeStatsMetric); | 191 tr.metrics.MetricRegistry.register(runtimeStatsMetric); |
| 129 | 192 |
| 130 return { | 193 return { |
| 131 runtimeStatsMetric, | 194 runtimeStatsMetric, |
| 195 runtimeStatsTotalMetric, | |
| 132 }; | 196 }; |
| 133 }); | 197 }); |
| 134 </script> | 198 </script> |
| OLD | NEW |