Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1678)

Side by Side Diff: base/metrics/histogram.h

Issue 6577013: Crash when we notice a corruption of the histogram range-vector... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const; 404 virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const;
405 405
406 //---------------------------------------------------------------------------- 406 //----------------------------------------------------------------------------
407 // Accessors for factory constuction, serialization and testing. 407 // Accessors for factory constuction, serialization and testing.
408 //---------------------------------------------------------------------------- 408 //----------------------------------------------------------------------------
409 virtual ClassType histogram_type() const; 409 virtual ClassType histogram_type() const;
410 const std::string& histogram_name() const { return histogram_name_; } 410 const std::string& histogram_name() const { return histogram_name_; }
411 Sample declared_min() const { return declared_min_; } 411 Sample declared_min() const { return declared_min_; }
412 Sample declared_max() const { return declared_max_; } 412 Sample declared_max() const { return declared_max_; }
413 virtual Sample ranges(size_t i) const; 413 virtual Sample ranges(size_t i) const;
414 Sample range_checksum() const { return range_checksum_; } 414 uint32 range_checksum() const { return range_checksum_; }
415 virtual size_t bucket_count() const; 415 virtual size_t bucket_count() const;
416 // Snapshot the current complete set of sample data. 416 // Snapshot the current complete set of sample data.
417 // Override with atomic/locked snapshot if needed. 417 // Override with atomic/locked snapshot if needed.
418 virtual void SnapshotSample(SampleSet* sample) const; 418 virtual void SnapshotSample(SampleSet* sample) const;
419 419
420 virtual bool HasConstructorArguments(Sample minimum, Sample maximum, 420 virtual bool HasConstructorArguments(Sample minimum, Sample maximum,
421 size_t bucket_count); 421 size_t bucket_count);
422 422
423 virtual bool HasConstructorTimeDeltaArguments(TimeDelta minimum, 423 virtual bool HasConstructorTimeDeltaArguments(TimeDelta minimum,
424 TimeDelta maximum, 424 TimeDelta maximum,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 void SetBucketRange(size_t i, Sample value); 466 void SetBucketRange(size_t i, Sample value);
467 467
468 // Validate that ranges_ was created sensibly (top and bottom range 468 // Validate that ranges_ was created sensibly (top and bottom range
469 // values relate properly to the declared_min_ and declared_max_).. 469 // values relate properly to the declared_min_ and declared_max_)..
470 bool ValidateBucketRanges() const; 470 bool ValidateBucketRanges() const;
471 471
472 private: 472 private:
473 // Allow tests to corrupt our innards for testing purposes. 473 // Allow tests to corrupt our innards for testing purposes.
474 FRIEND_TEST(HistogramTest, CorruptBucketBounds); 474 FRIEND_TEST(HistogramTest, CorruptBucketBounds);
475 FRIEND_TEST(HistogramTest, CorruptSampleCounts); 475 FRIEND_TEST(HistogramTest, CorruptSampleCounts);
476 FRIEND_TEST(HistogramTest, Crc32SampleHash);
477 FRIEND_TEST(HistogramTest, Crc32TableTest);
476 478
477 // Post constructor initialization. 479 // Post constructor initialization.
478 void Initialize(); 480 void Initialize();
479 481
480 // Return true iff the range_checksum_ matches current ranges_ vector. 482 // Return true iff the range_checksum_ matches current ranges_ vector.
481 bool HasValidRangeChecksum() const; 483 bool HasValidRangeChecksum() const;
482 484
483 Sample CalculateRangeChecksum() const; 485 uint32 CalculateRangeChecksum() const;
486
487 // Checksum function for accumulating range values into a checksum.
488 static uint32 Crc32(uint32 sum, Sample range);
484 489
485 //---------------------------------------------------------------------------- 490 //----------------------------------------------------------------------------
486 // Helpers for emitting Ascii graphic. Each method appends data to output. 491 // Helpers for emitting Ascii graphic. Each method appends data to output.
487 492
488 // Find out how large the (graphically) the largest bucket will appear to be. 493 // Find out how large the (graphically) the largest bucket will appear to be.
489 double GetPeakBucketSize(const SampleSet& snapshot) const; 494 double GetPeakBucketSize(const SampleSet& snapshot) const;
490 495
491 // Write a common header message describing this histogram. 496 // Write a common header message describing this histogram.
492 void WriteAsciiHeader(const SampleSet& snapshot, 497 void WriteAsciiHeader(const SampleSet& snapshot,
493 Count sample_count, std::string* output) const; 498 Count sample_count, std::string* output) const;
494 499
495 // Write information about previous, current, and next buckets. 500 // Write information about previous, current, and next buckets.
496 // Information such as cumulative percentage, etc. 501 // Information such as cumulative percentage, etc.
497 void WriteAsciiBucketContext(const int64 past, const Count current, 502 void WriteAsciiBucketContext(const int64 past, const Count current,
498 const int64 remaining, const size_t i, 503 const int64 remaining, const size_t i,
499 std::string* output) const; 504 std::string* output) const;
500 505
501 // Write textual description of the bucket contents (relative to histogram). 506 // Write textual description of the bucket contents (relative to histogram).
502 // Output is the count in the buckets, as well as the percentage. 507 // Output is the count in the buckets, as well as the percentage.
503 void WriteAsciiBucketValue(Count current, double scaled_sum, 508 void WriteAsciiBucketValue(Count current, double scaled_sum,
504 std::string* output) const; 509 std::string* output) const;
505 510
506 // Produce actual graph (set of blank vs non blank char's) for a bucket. 511 // Produce actual graph (set of blank vs non blank char's) for a bucket.
507 void WriteAsciiBucketGraph(double current_size, double max_size, 512 void WriteAsciiBucketGraph(double current_size, double max_size,
508 std::string* output) const; 513 std::string* output) const;
509 514
510 //---------------------------------------------------------------------------- 515 //----------------------------------------------------------------------------
516 // Table for generating Crc32 values.
517 static const uint32 kCrcTable[256];
518 //----------------------------------------------------------------------------
511 // Invariant values set at/near construction time 519 // Invariant values set at/near construction time
512 520
513 // ASCII version of original name given to the constructor. All identically 521 // ASCII version of original name given to the constructor. All identically
514 // named instances will be coalesced cross-project. 522 // named instances will be coalesced cross-project.
515 const std::string histogram_name_; 523 const std::string histogram_name_;
516 Sample declared_min_; // Less than this goes into counts_[0] 524 Sample declared_min_; // Less than this goes into counts_[0]
517 Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1]. 525 Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1].
518 size_t bucket_count_; // Dimension of counts_[]. 526 size_t bucket_count_; // Dimension of counts_[].
519 527
520 // Flag the histogram for recording by UMA via metric_services.h. 528 // Flag the histogram for recording by UMA via metric_services.h.
521 Flags flags_; 529 Flags flags_;
522 530
523 // For each index, show the least value that can be stored in the 531 // For each index, show the least value that can be stored in the
524 // corresponding bucket. We also append one extra element in this array, 532 // corresponding bucket. We also append one extra element in this array,
525 // containing kSampleType_MAX, to make calculations easy. 533 // containing kSampleType_MAX, to make calculations easy.
526 // The dimension of ranges_ is bucket_count + 1. 534 // The dimension of ranges_ is bucket_count + 1.
527 Ranges ranges_; 535 Ranges ranges_;
528 536
529 // For redundancy, we store the sum of all the sample ranges when ranges are 537 // For redundancy, we store a checksum of all the sample ranges when ranges
530 // generated. If ever there is ever a difference, then the histogram must 538 // are generated. If ever there is ever a difference, then the histogram must
531 // have been corrupted. 539 // have been corrupted.
532 Sample range_checksum_; 540 uint32 range_checksum_;
533 541
534 // Finally, provide the state that changes with the addition of each new 542 // Finally, provide the state that changes with the addition of each new
535 // sample. 543 // sample.
536 SampleSet sample_; 544 SampleSet sample_;
537 545
538 DISALLOW_COPY_AND_ASSIGN(Histogram); 546 DISALLOW_COPY_AND_ASSIGN(Histogram);
539 }; 547 };
540 548
541 //------------------------------------------------------------------------------ 549 //------------------------------------------------------------------------------
542 550
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 699
692 // Dump all known histograms to log. 700 // Dump all known histograms to log.
693 static bool dump_on_exit_; 701 static bool dump_on_exit_;
694 702
695 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 703 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
696 }; 704 };
697 705
698 } // namespace base 706 } // namespace base
699 707
700 #endif // BASE_METRICS_HISTOGRAM_H_ 708 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698