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/iteration_helpers.html"> | 8 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
9 <link rel="import" href="/tracing/base/range.html"> | 9 <link rel="import" href="/tracing/base/range.html"> |
10 <link rel="import" href="/tracing/base/running_statistics.html"> | 10 <link rel="import" href="/tracing/base/running_statistics.html"> |
(...skipping 26 matching lines...) Expand all Loading... |
37 * @param {!tr.b.Range} range | 37 * @param {!tr.b.Range} range |
38 */ | 38 */ |
39 constructor(range) { | 39 constructor(range) { |
40 this.range = range; | 40 this.range = range; |
41 this.count = 0; | 41 this.count = 0; |
42 this.diagnosticMaps = []; | 42 this.diagnosticMaps = []; |
43 } | 43 } |
44 | 44 |
45 /** | 45 /** |
46 * @param {*} value | 46 * @param {*} value |
47 * @param {!tr.v.d.DiagnosticMap=} opt_diagnosticMap | |
48 */ | 47 */ |
49 add(value, opt_diagnosticMap) { | 48 addSample(value) { |
50 if ((opt_diagnosticMap !== undefined) && | |
51 !(opt_diagnosticMap instanceof tr.v.d.DiagnosticMap)) | |
52 throw new Error('Can\'t add a sample with a non-DiagnosticMap'); | |
53 this.count += 1; | 49 this.count += 1; |
54 if (opt_diagnosticMap) { | 50 } |
55 tr.b.Statistics.uniformlySampleStream( | 51 |
56 this.diagnosticMaps, this.count, opt_diagnosticMap, | 52 /** |
57 MAX_DIAGNOSTIC_MAPS); | 53 * @param {!tr.v.d.DiagnosticMap} diagnostics |
58 } | 54 */ |
| 55 addDiagnosticMap(diagnostics) { |
| 56 tr.b.Statistics.uniformlySampleStream( |
| 57 this.diagnosticMaps, this.count, diagnostics, MAX_DIAGNOSTIC_MAPS); |
59 } | 58 } |
60 | 59 |
61 addBin(other) { | 60 addBin(other) { |
62 if (!this.range.equals(other.range)) | 61 if (!this.range.equals(other.range)) |
63 throw new Error('Merging incompatible Histogram bins.'); | 62 throw new Error('Merging incompatible Histogram bins.'); |
64 tr.b.Statistics.mergeSampledStreams(this.diagnosticMaps, this.count, | 63 tr.b.Statistics.mergeSampledStreams(this.diagnosticMaps, this.count, |
65 other.diagnosticMaps, other.count, MAX_DIAGNOSTIC_MAPS); | 64 other.diagnosticMaps, other.count, MAX_DIAGNOSTIC_MAPS); |
66 this.count += other.count; | 65 this.count += other.count; |
67 } | 66 } |
68 | 67 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 * @param {!Array.<number>} samples | 180 * @param {!Array.<number>} samples |
182 * @return {!Histogram} | 181 * @return {!Histogram} |
183 */ | 182 */ |
184 static buildFromSamples(unit, samples) { | 183 static buildFromSamples(unit, samples) { |
185 var boundaries = HistogramBinBoundaries.createFromSamples(samples); | 184 var boundaries = HistogramBinBoundaries.createFromSamples(samples); |
186 var result = new Histogram(unit, boundaries); | 185 var result = new Histogram(unit, boundaries); |
187 result.maxNumSampleValues = 1000; | 186 result.maxNumSampleValues = 1000; |
188 | 187 |
189 // TODO(eakuefner): Propagate diagnosticMaps? | 188 // TODO(eakuefner): Propagate diagnosticMaps? |
190 for (var sample of samples) | 189 for (var sample of samples) |
191 result.add(sample); | 190 result.addSample(sample); |
192 | 191 |
193 return result; | 192 return result; |
194 } | 193 } |
195 | 194 |
196 get numValues() { | 195 get numValues() { |
197 return tr.b.Statistics.sum(this.allBins, function(e) { | 196 return tr.b.Statistics.sum(this.allBins, function(e) { |
198 return e.count; | 197 return e.count; |
199 }); | 198 }); |
200 } | 199 } |
201 | 200 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 272 } |
274 | 273 |
275 getBinForValue(value) { | 274 getBinForValue(value) { |
276 // Don't use subtraction to avoid arithmetic overflow. | 275 // Don't use subtraction to avoid arithmetic overflow. |
277 var binIndex = tr.b.findHighIndexInSortedArray( | 276 var binIndex = tr.b.findHighIndexInSortedArray( |
278 this.allBins, b => value < b.range.max ? -1 : 1); | 277 this.allBins, b => value < b.range.max ? -1 : 1); |
279 return this.allBins[binIndex] || this.overflowBin; | 278 return this.allBins[binIndex] || this.overflowBin; |
280 } | 279 } |
281 | 280 |
282 /** | 281 /** |
283 * @param {*} value | 282 * @param {number|*} value |
284 * @param {!tr.v.d.DiagnosticMap=} opt_diagnosticMap | 283 * @param {(!Object|!tr.v.d.DiagnosticMap)=} opt_diagnostics |
285 */ | 284 */ |
286 add(value, opt_diagnosticMap) { | 285 addSample(value, opt_diagnostics) { |
287 if ((opt_diagnosticMap !== undefined) && | 286 if (opt_diagnostics && |
288 !(opt_diagnosticMap instanceof tr.v.d.DiagnosticMap)) | 287 !(opt_diagnostics instanceof tr.v.d.DiagnosticMap)) |
289 throw new Error('Can\'t add a sample with a non-DiagnosticMap'); | 288 opt_diagnostics = tr.v.d.DiagnosticMap.fromObject(opt_diagnostics); |
| 289 |
290 if (typeof(value) !== 'number' || isNaN(value)) { | 290 if (typeof(value) !== 'number' || isNaN(value)) { |
291 this.numNans++; | 291 this.numNans++; |
292 if (opt_diagnosticMap) { | 292 if (opt_diagnostics) { |
293 tr.b.Statistics.uniformlySampleStream(this.nanDiagnosticMaps, | 293 tr.b.Statistics.uniformlySampleStream(this.nanDiagnosticMaps, |
294 this.numNans, opt_diagnosticMap, MAX_DIAGNOSTIC_MAPS); | 294 this.numNans, opt_diagnostics, MAX_DIAGNOSTIC_MAPS); |
295 } | 295 } |
296 } else { | 296 } else { |
| 297 this.running.add(value); |
| 298 |
297 var bin = this.getBinForValue(value); | 299 var bin = this.getBinForValue(value); |
298 bin.add(value, opt_diagnosticMap); | 300 bin.addSample(value); |
299 this.running.add(value); | 301 if (opt_diagnostics) |
| 302 bin.addDiagnosticMap(opt_diagnostics); |
300 if (bin.count > this.maxCount_) | 303 if (bin.count > this.maxCount_) |
301 this.maxCount_ = bin.count; | 304 this.maxCount_ = bin.count; |
302 } | 305 } |
303 | 306 |
304 tr.b.Statistics.uniformlySampleStream(this.sampleValues_, | 307 tr.b.Statistics.uniformlySampleStream(this.sampleValues_, |
305 this.numValues + this.numNans, value, this.maxNumSampleValues); | 308 this.numValues + this.numNans, value, this.maxNumSampleValues); |
306 } | 309 } |
307 | 310 |
308 sampleValuesInto(samples) { | 311 sampleValuesInto(samples) { |
309 for (var sampleValue of this.sampleValues) | 312 for (var sampleValue of this.sampleValues) |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 tr.v.Unit.byName.count.unitName, | 738 tr.v.Unit.byName.count.unitName, |
736 HistogramBinBoundaries.createExponential(1, 1e3, 20)); | 739 HistogramBinBoundaries.createExponential(1, 1e3, 20)); |
737 | 740 |
738 return { | 741 return { |
739 Significance: Significance, | 742 Significance: Significance, |
740 Histogram: Histogram, | 743 Histogram: Histogram, |
741 HistogramBinBoundaries: HistogramBinBoundaries, | 744 HistogramBinBoundaries: HistogramBinBoundaries, |
742 }; | 745 }; |
743 }); | 746 }); |
744 </script> | 747 </script> |
OLD | NEW |