Chromium Code Reviews| 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 // UMAHistogramHelper should be created before the execution of the test case. | |
| 17 UMAHistogramHelper(); | 18 UMAHistogramHelper(); |
| 18 | 19 |
| 20 ~UMAHistogramHelper(); | |
| 21 | |
| 22 // Parameters should be string literals of all histograms to snapshot. | |
| 23 // Call this before executing the test code. | |
| 24 void PrepareSnapshot(const char* histogram_names[], int num_histograms); | |
|
Ilya Sherman
2014/06/13 19:58:12
nit: "int" -> "size_t"
Ilya Sherman
2014/06/13 19:58:12
Actually, is this function needed at all? Why not
Ilya Sherman
2014/06/13 19:58:12
nit: "const char*" -> "const char* const"
Mike Lerman
2014/06/16 14:59:13
Done.
Mike Lerman
2014/06/16 14:59:14
Efficiency's sake? There can be dozens if not hund
Mike Lerman
2014/06/16 14:59:14
Done.
Ilya Sherman
2014/06/16 18:11:29
I'm not convinced that the small bit of efficiency
| |
| 25 | |
| 19 // Each child process may have its own histogram data, make sure this data | 26 // 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. | 27 // gets accumulated into the browser process before we examine the histograms. |
| 21 void Fetch(); | 28 void Fetch(); |
| 22 | 29 |
| 23 // We know the exact number of samples in a bucket, and that no other bucket | 30 // We know the exact number of samples in a bucket, and that no other bucket |
| 24 // should have samples. | 31 // should have samples. If |PrepareSnapshot| was called for |name| histogram, |
|
Ilya Sherman
2014/06/13 19:58:12
nit: "for |name| histogram" -> "for the histogram
Mike Lerman
2014/06/16 14:59:14
Done.
| |
| 32 // then the |expected_count| is the diff from the snapshot. | |
|
Ilya Sherman
2014/06/13 19:58:12
Is it worth documenting what happens if PrepareSna
Mike Lerman
2014/06/16 14:59:14
Yes. I wrote wordy text, but would almost rather r
| |
| 25 void ExpectUniqueSample(const std::string& name, | 33 void ExpectUniqueSample(const std::string& name, |
| 26 base::HistogramBase::Sample sample, | 34 base::HistogramBase::Sample sample, |
| 27 base::HistogramBase::Count expected_count); | 35 base::HistogramBase::Count expected_count); |
| 28 | 36 |
| 29 // We know the exact number of samples in a bucket, but other buckets may | 37 // We know the exact number of samples in a bucket, but other buckets may |
| 30 // have samples as well. | 38 // have samples as well. If |PrepareSnapshot| was called for |name| histogram, |
| 39 // then the |expected_count| is the diff from the snapshot. | |
| 31 void ExpectBucketCount(const std::string& name, | 40 void ExpectBucketCount(const std::string& name, |
| 32 base::HistogramBase::Sample sample, | 41 base::HistogramBase::Sample sample, |
| 33 base::HistogramBase::Count expected_count); | 42 base::HistogramBase::Count expected_count); |
| 34 | 43 |
| 35 // We don't know the values of the samples, but we know how many there are. | 44 // We don't know the values of the samples, but we know how many there are. If |
| 45 // |PrepareSnapshot| was called for |name| histogram, then the | |
| 46 // |count| is the diff from the snapshot. | |
| 36 void ExpectTotalCount(const std::string& name, | 47 void ExpectTotalCount(const std::string& name, |
| 37 base::HistogramBase::Count count); | 48 base::HistogramBase::Count count); |
| 38 | 49 |
| 39 private: | 50 private: |
| 40 void FetchCallback(); | 51 void FetchCallback(); |
| 41 | 52 |
| 42 void CheckBucketCount(const std::string& name, | 53 void CheckBucketCount(const std::string& name, |
| 43 base::HistogramBase::Sample sample, | 54 base::HistogramBase::Sample sample, |
| 44 base::Histogram::Count expected_count, | 55 base::Histogram::Count expected_count, |
| 45 base::HistogramSamples& samples); | 56 base::HistogramSamples& samples); |
| 46 | 57 |
| 47 void CheckTotalCount(const std::string& name, | 58 void CheckTotalCount(const std::string& name, |
| 48 base::Histogram::Count expected_count, | 59 base::Histogram::Count expected_count, |
| 49 base::HistogramSamples& samples); | 60 base::HistogramSamples& samples); |
| 50 | 61 |
| 51 DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper); | 62 DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper); |
| 63 | |
| 64 // The map from histogram names to their snapshots | |
| 65 std::map<std::string, scoped_ptr<base::HistogramSamples> > | |
|
Ilya Sherman
2014/06/13 19:58:12
Hmm, I'm like 99% sure that scoped_ptrs aren't saf
Mike Lerman
2014/06/16 14:59:14
Good to know. I'll go with a linked_ptr. Since I'm
| |
| 66 histogram_snapshots; | |
| 52 }; | 67 }; |
| 53 | 68 |
| 54 #endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ | 69 #endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ |
| OLD | NEW |