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 #ifndef CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ | 5 #ifndef CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ |
6 #define CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ | 6 #define CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ |
7 | 7 |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/metrics/histogram_base.h" | 9 #include "base/metrics/histogram_base.h" |
10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
11 | 11 |
12 // UMAHistogramHelper provides a simple interface for examining UMA histograms. | 12 // UMAHistogramHelper provides a simple interface for examining UMA histograms. |
13 // Tests can use this interface to verify that UMA data is getting logged as | 13 // Tests can use this interface to verify that UMA data is getting logged as |
14 // intended. | 14 // intended. |
15 class UMAHistogramHelper { | 15 class UMAHistogramHelper { |
16 public: | 16 public: |
17 // To be called before the body of the test code. | |
Alexei Svitkine (slow)
2014/06/12 17:09:14
Comment is confusing since you can't generally cal
Mike Lerman
2014/06/12 18:12:16
Done.
| |
17 UMAHistogramHelper(); | 18 UMAHistogramHelper(); |
18 | 19 |
Alexei Svitkine (slow)
2014/06/12 17:09:14
Add a destructor declaration and put its implement
Mike Lerman
2014/06/12 18:12:15
Done.
| |
20 // Parameters should be string literals of all histograms to snapshot. | |
21 // Call this before executing the test code. | |
22 void PrepareSnapshot(const char**, int num_histograms); | |
23 | |
19 // Each child process may have its own histogram data, make sure this data | 24 // Each child process may have its own histogram data, make sure this data |
20 // gets accumulated into the browser process before we examine the histograms. | 25 // gets accumulated into the browser process before we examine the histograms. |
21 void Fetch(); | 26 void Fetch(); |
22 | 27 |
23 // We know the exact number of samples in a bucket, and that no other bucket | 28 // We know the exact number of samples in a bucket, and that no other bucket |
24 // should have samples. | 29 // should have samples. If |PrepareSnapshot| was called for |name| histogram, |
30 // then the |expected_count| is the diff from the snapshot. | |
25 void ExpectUniqueSample(const std::string& name, | 31 void ExpectUniqueSample(const std::string& name, |
26 base::HistogramBase::Sample sample, | 32 base::HistogramBase::Sample sample, |
27 base::HistogramBase::Count expected_count); | 33 base::HistogramBase::Count expected_count); |
28 | 34 |
29 // We know the exact number of samples in a bucket, but other buckets may | 35 // We know the exact number of samples in a bucket, but other buckets may |
30 // have samples as well. | 36 // have samples as well. If |PrepareSnapshot| was called for |name| histogram, |
37 // then the |expected_count| is the diff from the snapshot. | |
31 void ExpectBucketCount(const std::string& name, | 38 void ExpectBucketCount(const std::string& name, |
32 base::HistogramBase::Sample sample, | 39 base::HistogramBase::Sample sample, |
33 base::HistogramBase::Count expected_count); | 40 base::HistogramBase::Count expected_count); |
34 | 41 |
35 // We don't know the values of the samples, but we know how many there are. | 42 // We don't know the values of the samples, but we know how many there are. If |
43 // |PrepareSnapshot| was called for |name| histogram, then the | |
44 // |count| is the diff from the snapshot. | |
36 void ExpectTotalCount(const std::string& name, | 45 void ExpectTotalCount(const std::string& name, |
37 base::HistogramBase::Count count); | 46 base::HistogramBase::Count count); |
38 | 47 |
39 private: | 48 private: |
40 void FetchCallback(); | 49 void FetchCallback(); |
41 | 50 |
42 void CheckBucketCount(const std::string& name, | 51 void CheckBucketCount(const std::string& name, |
43 base::HistogramBase::Sample sample, | 52 base::HistogramBase::Sample sample, |
44 base::Histogram::Count expected_count, | 53 base::Histogram::Count expected_count, |
45 base::HistogramSamples& samples); | 54 base::HistogramSamples& samples); |
46 | 55 |
47 void CheckTotalCount(const std::string& name, | 56 void CheckTotalCount(const std::string& name, |
48 base::Histogram::Count expected_count, | 57 base::Histogram::Count expected_count, |
49 base::HistogramSamples& samples); | 58 base::HistogramSamples& samples); |
50 | 59 |
51 DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper); | 60 DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper); |
61 | |
62 // The map from histogram names to their snapshots | |
63 std::map<std::string, scoped_ptr<base::HistogramSamples> > | |
64 histogram_snapshots; | |
52 }; | 65 }; |
53 | 66 |
54 #endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ | 67 #endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ |
OLD | NEW |