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

Side by Side Diff: base/test/histogram_tester.h

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Prefer base histogram_tester. ChromeHistogramTester with RunMessageLoop for NaCl Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 BASE_TEST_HISTOGRAM_TESTER_H_
6 #define CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ 6 #define BASE_TEST_HISTOGRAM_TESTER_H_
7 7
8 #include "base/memory/linked_ptr.h" 8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_base.h" 14 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/histogram_samples.h"
12 15
13 // UMAHistogramHelper provides a simple interface for examining UMA histograms. 16 namespace base {
14 // Tests can use this interface to verify that UMA data is getting logged as 17
15 // intended. 18 class HistogramSamples;
16 class UMAHistogramHelper { 19
20 // HistogramTester provides a simple interface for examining histograms, UMA
21 // or otherwise. Tests can use this interface to verify that Histograms data is
Ilya Sherman 2014/07/15 03:56:34 nit: "Histograms" -> "histograms"
Mike Lerman 2014/07/16 17:29:02 Done.
22 // getting logged as intended.
23 // Note that if the test lies within /chrome, please use the
24 // |ChromeHistogramTester| class.
Ilya Sherman 2014/07/15 03:56:34 nit: Please omit this sentence -- it's actually be
Mike Lerman 2014/07/16 17:29:02 Done.
25 class HistogramTester {
17 public: 26 public:
18 // UMAHistogramHelper should be created before the execution of the test case. 27 // The constructor will call StatisticsRecorder::Initialize() for you. Also,
19 UMAHistogramHelper(); 28 // this takes a snapshot of all current histograms counts.
29 HistogramTester();
30 ~HistogramTester();
20 31
21 ~UMAHistogramHelper(); 32 // Fetch the values to be tested when the test uses multiple threads. Call
22 33 // this after the test code has been executed but before performing the
23 // Parameters should be string literals of all histograms to snapshot. 34 // necessary assertions. This may be called multiple times.
24 // Call this before executing the test code. This method can be called 35 virtual void FetchTestingSnapshot();
Ilya Sherman 2014/07/15 03:56:35 It looks like this method can be omitted from the
Mike Lerman 2014/07/16 17:29:03 Done.
25 // multiple times. The existing snapshots are preserved, except when one of
26 // the |histogram_names| was previously passed as a parameter, then a new
27 // snapshot will replace the existing one.
28 void PrepareSnapshot(const char* const histogram_names[],
29 size_t num_histograms);
30
31 // Each child process may have its own histogram data, make sure this data
32 // gets accumulated into the browser process before we examine the histograms.
33 void Fetch();
34 36
35 // We know the exact number of samples in a bucket, and that no other bucket 37 // We know the exact number of samples in a bucket, and that no other bucket
36 // should have samples. If |PrepareSnapshot| was called for the histogram 38 // should have samples. If |PrepareSnapshot| was called for the histogram
37 // named |name| then the |expected_count| is the diff from the snapshot. 39 // named |name| then the |expected_count| is the diff from the snapshot.
Ilya Sherman 2014/07/15 03:56:34 Please update this comment -- PrepareSnapshot() is
Mike Lerman 2014/07/16 17:29:02 Done.
38 void ExpectUniqueSample(const std::string& name, 40 void ExpectUniqueSample(const std::string& name,
39 base::HistogramBase::Sample sample, 41 base::HistogramBase::Sample sample,
40 base::HistogramBase::Count expected_count); 42 base::HistogramBase::Count expected_count);
41 43
42 // We know the exact number of samples in a bucket, but other buckets may 44 // We know the exact number of samples in a bucket, but other buckets may
43 // have samples as well. If |PrepareSnapshot| was called for histogram named 45 // have samples as well. If |PrepareSnapshot| was called for histogram named
44 // |name| then the |expected_count| is the diff from the snapshot. 46 // |name| then the |expected_count| is the diff from the snapshot.
45 void ExpectBucketCount(const std::string& name, 47 void ExpectBucketCount(const std::string& name,
46 base::HistogramBase::Sample sample, 48 base::HistogramBase::Sample sample,
47 base::HistogramBase::Count expected_count); 49 base::HistogramBase::Count expected_count);
Ilya Sherman 2014/07/15 03:56:35 nit: Please fix up the alignment of these two line
Mike Lerman 2014/07/16 17:29:03 Done.
48 50
49 // We don't know the values of the samples, but we know how many there are. If 51 // We don't know the values of the samples, but we know how many there are. If
50 // |PrepareSnapshot| was called for |name| histogram, then the 52 // |PrepareSnapshot| was called for |name| histogram, then the
51 // |count| is the diff from the snapshot. 53 // |count| is the diff from the snapshot.
52 void ExpectTotalCount(const std::string& name, 54 void ExpectTotalCount(const std::string& name,
53 base::HistogramBase::Count count); 55 base::HistogramBase::Count count);
54 56
57 // Directly access the base snapshot taken for a particular histogram.
58 scoped_ptr<HistogramSamples> GetBaseHistogramSamples(
Ilya Sherman 2014/07/15 03:56:35 nit: What does the word "base" mean in this contex
Mike Lerman 2014/07/16 17:29:03 Nothing useful. Name and comment changed.
59 const std::string& histogram_name);
Ilya Sherman 2014/07/15 03:56:34 Is this method still useful, or can all clients of
Mike Lerman 2014/07/16 17:29:02 I had hoped so, but there is at least one test tha
60
55 private: 61 private:
56 void FetchCallback();
57
58 void CheckBucketCount(const std::string& name, 62 void CheckBucketCount(const std::string& name,
59 base::HistogramBase::Sample sample, 63 base::HistogramBase::Sample sample,
60 base::Histogram::Count expected_count, 64 base::Histogram::Count expected_count,
61 base::HistogramSamples& samples); 65 base::HistogramSamples& samples);
62 66
63 void CheckTotalCount(const std::string& name, 67 void CheckTotalCount(const std::string& name,
64 base::Histogram::Count expected_count, 68 base::Histogram::Count expected_count,
65 base::HistogramSamples& samples); 69 base::HistogramSamples& samples);
Ilya Sherman 2014/07/15 03:56:35 Please document these two methods.
Mike Lerman 2014/07/16 17:29:02 Done.
66 70
67 DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper); 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*> base_snapshot_;
Ilya Sherman 2014/07/15 03:56:34 nit: WDYT of "initial_snapshot_" rather than "base
Mike Lerman 2014/07/16 17:29:02 There's only one snapshot, so it doesn't really ne
68 75
69 // The map from histogram names to their snapshots 76 DISALLOW_COPY_AND_ASSIGN(HistogramTester);
70 std::map<std::string, linked_ptr<base::HistogramSamples> >
71 histogram_snapshots;
72 }; 77 };
73 78
74 #endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_ 79 } // namespace base
80
81 #endif // BASE_TEST_HISTOGRAM_TESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698