Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_TEST_HISTOGRAM_TESTER_H_ | |
| 6 #define BASE_TEST_HISTOGRAM_TESTER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/metrics/histogram.h" | |
| 14 #include "base/metrics/histogram_base.h" | |
| 15 | |
| 16 namespace base { | |
| 17 | |
| 18 class HistogramSamples; | |
| 19 | |
| 20 // HistogramTester provides a simple interface for examining histograms, UMA | |
| 21 // or otherwise. Tests can use this interface to verify that Histogram data is | |
|
Ilya Sherman
2014/07/16 18:44:46
nit: Uppercase "Histogram" should be lowercase.
Mike Lerman
2014/07/16 19:36:35
Done.
| |
| 22 // getting logged as intended. | |
| 23 class HistogramTester { | |
| 24 public: | |
| 25 // The constructor will call StatisticsRecorder::Initialize() for you. Also, | |
| 26 // this takes a snapshot of all current histograms counts. | |
| 27 HistogramTester(); | |
| 28 ~HistogramTester(); | |
| 29 | |
| 30 // We know the exact number of samples in a bucket, and that no other bucket | |
| 31 // should have samples. Measures the diff from the snapshot taken when this | |
| 32 // object was constructed. | |
| 33 const void ExpectUniqueSample(const std::string& name, | |
|
Ilya Sherman
2014/07/16 18:44:46
"const void" doesn't make a lot of sense as a retu
Mike Lerman
2014/07/16 19:36:36
Ummm. Yes. Awkward.
| |
| 34 base::HistogramBase::Sample sample, | |
| 35 base::HistogramBase::Count expected_count); | |
| 36 | |
| 37 // We know the exact number of samples in a bucket, but other buckets may | |
| 38 // have samples as well. Measures the diff from the snapshot taken when this | |
| 39 // object was constructed. | |
| 40 const void ExpectBucketCount(const std::string& name, | |
| 41 base::HistogramBase::Sample sample, | |
| 42 base::HistogramBase::Count expected_count); | |
| 43 | |
| 44 // We don't know the values of the samples, but we know how many there are. | |
| 45 // This measures the diff from the snapshot taken when this object was | |
| 46 // constructed. | |
| 47 const void ExpectTotalCount(const std::string& name, | |
| 48 base::HistogramBase::Count count); | |
| 49 | |
| 50 // Access a modified HistogramSamples containing only what has been logged | |
| 51 // to the histogram since the creation of this object. | |
| 52 scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( | |
| 53 const std::string& histogram_name); | |
| 54 | |
| 55 private: | |
| 56 // Verifies and asserts that value in the |sample| bucket matches the | |
| 57 // |expected_count|. The bucket's current value is determined from |samples| | |
| 58 // and is modified based on the snapshot stored for histogram |name|. | |
| 59 const void CheckBucketCount(const std::string& name, | |
| 60 base::HistogramBase::Sample sample, | |
| 61 base::Histogram::Count expected_count, | |
| 62 base::HistogramSamples& samples); | |
| 63 | |
| 64 // Verifies that the total number of values recorded for the histogram |name| | |
| 65 // is |expected_count|. This is checked against |samples| minus the snapshot | |
| 66 // that was taken for |name|. | |
| 67 const void CheckTotalCount(const std::string& name, | |
| 68 base::Histogram::Count expected_count, | |
| 69 base::HistogramSamples& samples); | |
| 70 | |
| 71 // Used to determine the histogram changes made during this instance's | |
| 72 // lifecycle. This instance takes ownership of the samples, which are deleted | |
| 73 // when the instance is destroyed. | |
| 74 std::map<std::string, HistogramSamples*> histograms_snapshot_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(HistogramTester); | |
| 77 }; | |
| 78 | |
| 79 } // namespace base | |
| 80 | |
| 81 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ | |
| OLD | NEW |