OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
8 | 8 |
9 // It supports calls to accumulate either time intervals (which are processed | 9 // It supports calls to accumulate either time intervals (which are processed |
10 // as integral number of milliseconds), or arbitrary integral units. | 10 // as integral number of milliseconds), or arbitrary integral units. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 base::TimeDelta maximum, | 138 base::TimeDelta maximum, |
139 uint32_t bucket_count, | 139 uint32_t bucket_count, |
140 int32_t flags); | 140 int32_t flags); |
141 | 141 |
142 // Get a histogram using data in persistent storage. | 142 // Get a histogram using data in persistent storage. |
143 static HistogramBase* PersistentGet(const std::string& name, | 143 static HistogramBase* PersistentGet(const std::string& name, |
144 Sample minimum, | 144 Sample minimum, |
145 Sample maximum, | 145 Sample maximum, |
146 const BucketRanges* ranges, | 146 const BucketRanges* ranges, |
147 HistogramBase::AtomicCount* counts, | 147 HistogramBase::AtomicCount* counts, |
148 HistogramBase::AtomicCount* logged_counts, | |
148 uint32_t counts_size, | 149 uint32_t counts_size, |
149 HistogramSamples::Metadata* meta); | 150 HistogramSamples::Metadata* meta, |
151 HistogramSamples::Metadata* logged_meta); | |
150 | 152 |
151 static void InitializeBucketRanges(Sample minimum, | 153 static void InitializeBucketRanges(Sample minimum, |
152 Sample maximum, | 154 Sample maximum, |
153 BucketRanges* ranges); | 155 BucketRanges* ranges); |
154 | 156 |
155 // This constant if for FindCorruption. Since snapshots of histograms are | 157 // This constant if for FindCorruption. Since snapshots of histograms are |
156 // taken asynchronously relative to sampling, and our counting code currently | 158 // taken asynchronously relative to sampling, and our counting code currently |
157 // does not prevent race conditions, it is pretty likely that we'll catch a | 159 // does not prevent race conditions, it is pretty likely that we'll catch a |
158 // redundant count that doesn't match the sample count. We allow for a | 160 // redundant count that doesn't match the sample count. We allow for a |
159 // certain amount of slop before flagging this as an inconsistency. Even with | 161 // certain amount of slop before flagging this as an inconsistency. Even with |
160 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), | 162 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), |
161 // so we'll eventually get the data, if it was not the result of a corruption. | 163 // so we'll eventually get the data, if it was not the result of a corruption. |
162 static const int kCommonRaceBasedCountMismatch; | 164 static const int kCommonRaceBasedCountMismatch; |
163 | 165 |
164 // Check to see if bucket ranges, counts and tallies in the snapshot are | 166 // Check to see if bucket ranges, counts and tallies in the snapshot are |
165 // consistent with the bucket ranges and checksums in our histogram. This can | 167 // consistent with the bucket ranges and checksums in our histogram. This can |
166 // produce a false-alarm if a race occurred in the reading of the data during | 168 // produce a false-alarm if a race occurred in the reading of the data during |
167 // a SnapShot process, but should otherwise be false at all times (unless we | 169 // a SnapShot process, but should otherwise be false at all times (unless we |
168 // have memory over-writes, or DRAM failures). | 170 // have memory over-writes, or DRAM failures). |
Alexei Svitkine (slow)
2016/02/17 16:21:12
Nit: While here, can you point to the enum of flag
bcwhite
2016/02/17 17:58:20
Done.
| |
169 int FindCorruption(const HistogramSamples& samples) const override; | 171 unsigned FindCorruption(const HistogramSamples& samples) const override; |
170 | 172 |
171 //---------------------------------------------------------------------------- | 173 //---------------------------------------------------------------------------- |
172 // Accessors for factory construction, serialization and testing. | 174 // Accessors for factory construction, serialization and testing. |
173 //---------------------------------------------------------------------------- | 175 //---------------------------------------------------------------------------- |
174 Sample declared_min() const { return declared_min_; } | 176 Sample declared_min() const { return declared_min_; } |
175 Sample declared_max() const { return declared_max_; } | 177 Sample declared_max() const { return declared_max_; } |
176 virtual Sample ranges(uint32_t i) const; | 178 virtual Sample ranges(uint32_t i) const; |
177 virtual uint32_t bucket_count() const; | 179 virtual uint32_t bucket_count() const; |
178 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } | 180 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } |
179 | 181 |
(...skipping 10 matching lines...) Expand all Loading... | |
190 | 192 |
191 // HistogramBase implementation: | 193 // HistogramBase implementation: |
192 uint64_t name_hash() const override; | 194 uint64_t name_hash() const override; |
193 HistogramType GetHistogramType() const override; | 195 HistogramType GetHistogramType() const override; |
194 bool HasConstructionArguments(Sample expected_minimum, | 196 bool HasConstructionArguments(Sample expected_minimum, |
195 Sample expected_maximum, | 197 Sample expected_maximum, |
196 uint32_t expected_bucket_count) const override; | 198 uint32_t expected_bucket_count) const override; |
197 void Add(Sample value) override; | 199 void Add(Sample value) override; |
198 void AddCount(Sample value, int count) override; | 200 void AddCount(Sample value, int count) override; |
199 scoped_ptr<HistogramSamples> SnapshotSamples() const override; | 201 scoped_ptr<HistogramSamples> SnapshotSamples() const override; |
202 scoped_ptr<HistogramSamples> SnapshotDelta() override; | |
200 void AddSamples(const HistogramSamples& samples) override; | 203 void AddSamples(const HistogramSamples& samples) override; |
201 bool AddSamplesFromPickle(base::PickleIterator* iter) override; | 204 bool AddSamplesFromPickle(base::PickleIterator* iter) override; |
202 void WriteHTMLGraph(std::string* output) const override; | 205 void WriteHTMLGraph(std::string* output) const override; |
203 void WriteAscii(std::string* output) const override; | 206 void WriteAscii(std::string* output) const override; |
204 | 207 |
205 protected: | 208 protected: |
206 // This class, defined entirely within the .cc file, contains all the | 209 // This class, defined entirely within the .cc file, contains all the |
207 // common logic for building a Histogram and can be overridden by more | 210 // common logic for building a Histogram and can be overridden by more |
208 // specific types to alter details of how the creation is done. It is | 211 // specific types to alter details of how the creation is done. It is |
209 // defined as an embedded class (rather than an anonymous one) so it | 212 // defined as an embedded class (rather than an anonymous one) so it |
(...skipping 11 matching lines...) Expand all Loading... | |
221 // vector but "shared" histograms use memory regions allocated from a | 224 // vector but "shared" histograms use memory regions allocated from a |
222 // special memory segment that is passed in here. It is assumed that | 225 // special memory segment that is passed in here. It is assumed that |
223 // the life of this memory is managed externally and exceeds the lifetime | 226 // the life of this memory is managed externally and exceeds the lifetime |
224 // of this object. Practically, this memory is never released until the | 227 // of this object. Practically, this memory is never released until the |
225 // process exits and the OS cleans it up. | 228 // process exits and the OS cleans it up. |
226 Histogram(const std::string& name, | 229 Histogram(const std::string& name, |
227 Sample minimum, | 230 Sample minimum, |
228 Sample maximum, | 231 Sample maximum, |
229 const BucketRanges* ranges, | 232 const BucketRanges* ranges, |
230 HistogramBase::AtomicCount* counts, | 233 HistogramBase::AtomicCount* counts, |
234 HistogramBase::AtomicCount* logged_counts, | |
231 uint32_t counts_size, | 235 uint32_t counts_size, |
232 HistogramSamples::Metadata* meta); | 236 HistogramSamples::Metadata* meta, |
237 HistogramSamples::Metadata* logged_meta); | |
233 | 238 |
234 ~Histogram() override; | 239 ~Histogram() override; |
235 | 240 |
236 // HistogramBase implementation: | 241 // HistogramBase implementation: |
237 bool SerializeInfoImpl(base::Pickle* pickle) const override; | 242 bool SerializeInfoImpl(base::Pickle* pickle) const override; |
238 | 243 |
239 // Method to override to skip the display of the i'th bucket if it's empty. | 244 // Method to override to skip the display of the i'th bucket if it's empty. |
240 virtual bool PrintEmptyBucket(uint32_t index) const; | 245 virtual bool PrintEmptyBucket(uint32_t index) const; |
241 | 246 |
242 // Get normalized size, relative to the ranges(i). | 247 // Get normalized size, relative to the ranges(i). |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 // Does not own this object. Should get from StatisticsRecorder. | 301 // Does not own this object. Should get from StatisticsRecorder. |
297 const BucketRanges* bucket_ranges_; | 302 const BucketRanges* bucket_ranges_; |
298 | 303 |
299 Sample declared_min_; // Less than this goes into the first bucket. | 304 Sample declared_min_; // Less than this goes into the first bucket. |
300 Sample declared_max_; // Over this goes into the last bucket. | 305 Sample declared_max_; // Over this goes into the last bucket. |
301 | 306 |
302 // Finally, provide the state that changes with the addition of each new | 307 // Finally, provide the state that changes with the addition of each new |
303 // sample. | 308 // sample. |
304 scoped_ptr<SampleVector> samples_; | 309 scoped_ptr<SampleVector> samples_; |
305 | 310 |
311 // Also keep a previous uploaded state for calculating deltas. | |
312 scoped_ptr<HistogramSamples> logged_samples_; | |
313 | |
306 DISALLOW_COPY_AND_ASSIGN(Histogram); | 314 DISALLOW_COPY_AND_ASSIGN(Histogram); |
307 }; | 315 }; |
308 | 316 |
309 //------------------------------------------------------------------------------ | 317 //------------------------------------------------------------------------------ |
310 | 318 |
311 // LinearHistogram is a more traditional histogram, with evenly spaced | 319 // LinearHistogram is a more traditional histogram, with evenly spaced |
312 // buckets. | 320 // buckets. |
313 class BASE_EXPORT LinearHistogram : public Histogram { | 321 class BASE_EXPORT LinearHistogram : public Histogram { |
314 public: | 322 public: |
315 ~LinearHistogram() override; | 323 ~LinearHistogram() override; |
(...skipping 24 matching lines...) Expand all Loading... | |
340 TimeDelta maximum, | 348 TimeDelta maximum, |
341 uint32_t bucket_count, | 349 uint32_t bucket_count, |
342 int32_t flags); | 350 int32_t flags); |
343 | 351 |
344 // Get a histogram using data in persistent storage. | 352 // Get a histogram using data in persistent storage. |
345 static HistogramBase* PersistentGet(const std::string& name, | 353 static HistogramBase* PersistentGet(const std::string& name, |
346 Sample minimum, | 354 Sample minimum, |
347 Sample maximum, | 355 Sample maximum, |
348 const BucketRanges* ranges, | 356 const BucketRanges* ranges, |
349 HistogramBase::AtomicCount* counts, | 357 HistogramBase::AtomicCount* counts, |
358 HistogramBase::AtomicCount* logged_counts, | |
350 uint32_t counts_size, | 359 uint32_t counts_size, |
351 HistogramSamples::Metadata* meta); | 360 HistogramSamples::Metadata* meta, |
361 HistogramSamples::Metadata* logged_meta); | |
352 | 362 |
353 struct DescriptionPair { | 363 struct DescriptionPair { |
354 Sample sample; | 364 Sample sample; |
355 const char* description; // Null means end of a list of pairs. | 365 const char* description; // Null means end of a list of pairs. |
356 }; | 366 }; |
357 | 367 |
358 // Create a LinearHistogram and store a list of number/text values for use in | 368 // Create a LinearHistogram and store a list of number/text values for use in |
359 // writing the histogram graph. | 369 // writing the histogram graph. |
360 // |descriptions| can be NULL, which means no special descriptions to set. If | 370 // |descriptions| can be NULL, which means no special descriptions to set. If |
361 // it's not NULL, the last element in the array must has a NULL in its | 371 // it's not NULL, the last element in the array must has a NULL in its |
(...skipping 19 matching lines...) Expand all Loading... | |
381 LinearHistogram(const std::string& name, | 391 LinearHistogram(const std::string& name, |
382 Sample minimum, | 392 Sample minimum, |
383 Sample maximum, | 393 Sample maximum, |
384 const BucketRanges* ranges); | 394 const BucketRanges* ranges); |
385 | 395 |
386 LinearHistogram(const std::string& name, | 396 LinearHistogram(const std::string& name, |
387 Sample minimum, | 397 Sample minimum, |
388 Sample maximum, | 398 Sample maximum, |
389 const BucketRanges* ranges, | 399 const BucketRanges* ranges, |
390 HistogramBase::AtomicCount* counts, | 400 HistogramBase::AtomicCount* counts, |
401 HistogramBase::AtomicCount* logged_counts, | |
391 uint32_t counts_size, | 402 uint32_t counts_size, |
392 HistogramSamples::Metadata* meta); | 403 HistogramSamples::Metadata* meta, |
404 HistogramSamples::Metadata* logged_meta); | |
393 | 405 |
394 double GetBucketSize(Count current, uint32_t i) const override; | 406 double GetBucketSize(Count current, uint32_t i) const override; |
395 | 407 |
396 // If we have a description for a bucket, then return that. Otherwise | 408 // If we have a description for a bucket, then return that. Otherwise |
397 // let parent class provide a (numeric) description. | 409 // let parent class provide a (numeric) description. |
398 const std::string GetAsciiBucketRange(uint32_t i) const override; | 410 const std::string GetAsciiBucketRange(uint32_t i) const override; |
399 | 411 |
400 // Skip printing of name for numeric range if we have a name (and if this is | 412 // Skip printing of name for numeric range if we have a name (and if this is |
401 // an empty bucket). | 413 // an empty bucket). |
402 bool PrintEmptyBucket(uint32_t index) const override; | 414 bool PrintEmptyBucket(uint32_t index) const override; |
(...skipping 21 matching lines...) Expand all Loading... | |
424 | 436 |
425 // Overload of the above function that takes a const char* |name| param, | 437 // Overload of the above function that takes a const char* |name| param, |
426 // to avoid code bloat from the std::string constructor being inlined into | 438 // to avoid code bloat from the std::string constructor being inlined into |
427 // call sites. | 439 // call sites. |
428 static HistogramBase* FactoryGet(const char* name, int32_t flags); | 440 static HistogramBase* FactoryGet(const char* name, int32_t flags); |
429 | 441 |
430 // Get a histogram using data in persistent storage. | 442 // Get a histogram using data in persistent storage. |
431 static HistogramBase* PersistentGet(const std::string& name, | 443 static HistogramBase* PersistentGet(const std::string& name, |
432 const BucketRanges* ranges, | 444 const BucketRanges* ranges, |
433 HistogramBase::AtomicCount* counts, | 445 HistogramBase::AtomicCount* counts, |
434 HistogramSamples::Metadata* meta); | 446 HistogramBase::AtomicCount* logged_counts, |
447 HistogramSamples::Metadata* meta, | |
448 HistogramSamples::Metadata* logged_meta); | |
435 | 449 |
436 HistogramType GetHistogramType() const override; | 450 HistogramType GetHistogramType() const override; |
437 | 451 |
438 protected: | 452 protected: |
439 class Factory; | 453 class Factory; |
440 | 454 |
441 private: | 455 private: |
442 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 456 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
443 BooleanHistogram(const std::string& name, | 457 BooleanHistogram(const std::string& name, |
444 const BucketRanges* ranges, | 458 const BucketRanges* ranges, |
445 HistogramBase::AtomicCount* counts, | 459 HistogramBase::AtomicCount* counts, |
446 HistogramSamples::Metadata* meta); | 460 HistogramBase::AtomicCount* logged_counts, |
461 HistogramSamples::Metadata* meta, | |
462 HistogramSamples::Metadata* logged_meta); | |
447 | 463 |
448 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( | 464 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( |
449 base::PickleIterator* iter); | 465 base::PickleIterator* iter); |
450 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 466 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
451 | 467 |
452 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 468 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
453 }; | 469 }; |
454 | 470 |
455 //------------------------------------------------------------------------------ | 471 //------------------------------------------------------------------------------ |
456 | 472 |
(...skipping 12 matching lines...) Expand all Loading... | |
469 // to avoid code bloat from the std::string constructor being inlined into | 485 // to avoid code bloat from the std::string constructor being inlined into |
470 // call sites. | 486 // call sites. |
471 static HistogramBase* FactoryGet(const char* name, | 487 static HistogramBase* FactoryGet(const char* name, |
472 const std::vector<Sample>& custom_ranges, | 488 const std::vector<Sample>& custom_ranges, |
473 int32_t flags); | 489 int32_t flags); |
474 | 490 |
475 // Get a histogram using data in persistent storage. | 491 // Get a histogram using data in persistent storage. |
476 static HistogramBase* PersistentGet(const std::string& name, | 492 static HistogramBase* PersistentGet(const std::string& name, |
477 const BucketRanges* ranges, | 493 const BucketRanges* ranges, |
478 HistogramBase::AtomicCount* counts, | 494 HistogramBase::AtomicCount* counts, |
495 HistogramBase::AtomicCount* logged_counts, | |
479 uint32_t counts_size, | 496 uint32_t counts_size, |
480 HistogramSamples::Metadata* meta); | 497 HistogramSamples::Metadata* meta, |
498 HistogramSamples::Metadata* logged_meta); | |
481 | 499 |
482 // Overridden from Histogram: | 500 // Overridden from Histogram: |
483 HistogramType GetHistogramType() const override; | 501 HistogramType GetHistogramType() const override; |
484 | 502 |
485 // Helper method for transforming an array of valid enumeration values | 503 // Helper method for transforming an array of valid enumeration values |
486 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. | 504 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. |
487 // This function ensures that a guard bucket exists right after any | 505 // This function ensures that a guard bucket exists right after any |
488 // valid sample value (unless the next higher sample is also a valid value), | 506 // valid sample value (unless the next higher sample is also a valid value), |
489 // so that invalid samples never fall into the same bucket as valid samples. | 507 // so that invalid samples never fall into the same bucket as valid samples. |
490 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 508 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
491 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 509 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
492 uint32_t num_values); | 510 uint32_t num_values); |
493 protected: | 511 protected: |
494 class Factory; | 512 class Factory; |
495 | 513 |
496 CustomHistogram(const std::string& name, | 514 CustomHistogram(const std::string& name, |
497 const BucketRanges* ranges); | 515 const BucketRanges* ranges); |
498 | 516 |
499 CustomHistogram(const std::string& name, | 517 CustomHistogram(const std::string& name, |
500 const BucketRanges* ranges, | 518 const BucketRanges* ranges, |
501 HistogramBase::AtomicCount* counts, | 519 HistogramBase::AtomicCount* counts, |
520 HistogramBase::AtomicCount* logged_counts, | |
502 uint32_t counts_size, | 521 uint32_t counts_size, |
503 HistogramSamples::Metadata* meta); | 522 HistogramSamples::Metadata* meta, |
523 HistogramSamples::Metadata* logged_meta); | |
504 | 524 |
505 // HistogramBase implementation: | 525 // HistogramBase implementation: |
506 bool SerializeInfoImpl(base::Pickle* pickle) const override; | 526 bool SerializeInfoImpl(base::Pickle* pickle) const override; |
507 | 527 |
508 double GetBucketSize(Count current, uint32_t i) const override; | 528 double GetBucketSize(Count current, uint32_t i) const override; |
509 | 529 |
510 private: | 530 private: |
511 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( | 531 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( |
512 base::PickleIterator* iter); | 532 base::PickleIterator* iter); |
513 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 533 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
514 | 534 |
515 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 535 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
516 | 536 |
517 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 537 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
518 }; | 538 }; |
519 | 539 |
520 } // namespace base | 540 } // namespace base |
521 | 541 |
522 #endif // BASE_METRICS_HISTOGRAM_H_ | 542 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |