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

Side by Side Diff: chrome/test/base/uma_histogram_helper.cc

Issue 309843002: Improve UMA tests; improve no-op reconcilor; new reconcilor test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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 (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 #include "chrome/test/base/uma_histogram_helper.h" 5 #include "chrome/test/base/uma_histogram_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/statistics_recorder.h" 8 #include "base/metrics/statistics_recorder.h"
9 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/histogram_fetcher.h" 11 #include "content/public/browser/histogram_fetcher.h"
12 12
13 UMAHistogramHelper::UMAHistogramHelper() { 13 UMAHistogramHelper::UMAHistogramHelper() {
14 base::StatisticsRecorder::Initialize();
15 }
16
17 UMAHistogramHelper::~UMAHistogramHelper() {
18 }
19
20 void UMAHistogramHelper::PrepareSnapshot(const char* const histogram_names[],
21 size_t num_histograms) {
22 for (size_t i = 0; i < num_histograms; ++i) {
23 std::string histogram_name = histogram_names[i];
24
25 base::HistogramBase* histogram =
26 base::StatisticsRecorder::FindHistogram(histogram_name);
27 // If there is no histogram present, then don't record a snapshot. The logic
28 // in the Expect* methods will act to treat no histogram equivalent to
29 // samples with zeros.
30 if (histogram) {
31 histogram_snapshots[histogram_name] =
32 make_linked_ptr(histogram->SnapshotSamples().release());
33 }
34 }
14 } 35 }
15 36
16 void UMAHistogramHelper::Fetch() { 37 void UMAHistogramHelper::Fetch() {
17 base::Closure callback = base::Bind(&UMAHistogramHelper::FetchCallback, 38 base::Closure callback = base::Bind(&UMAHistogramHelper::FetchCallback,
18 base::Unretained(this)); 39 base::Unretained(this));
19 40
20 content::FetchHistogramsAsynchronously( 41 content::FetchHistogramsAsynchronously(
21 base::MessageLoop::current(), 42 base::MessageLoop::current(),
22 callback, 43 callback,
23 // If this call times out, it means that a child process is not 44 // If this call times out, it means that a child process is not
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 96
76 void UMAHistogramHelper::FetchCallback() { 97 void UMAHistogramHelper::FetchCallback() {
77 base::MessageLoopForUI::current()->Quit(); 98 base::MessageLoopForUI::current()->Quit();
78 } 99 }
79 100
80 void UMAHistogramHelper::CheckBucketCount( 101 void UMAHistogramHelper::CheckBucketCount(
81 const std::string& name, 102 const std::string& name,
82 base::HistogramBase::Sample sample, 103 base::HistogramBase::Sample sample,
83 base::HistogramBase::Count expected_count, 104 base::HistogramBase::Count expected_count,
84 base::HistogramSamples& samples) { 105 base::HistogramSamples& samples) {
85 EXPECT_EQ(expected_count, samples.GetCount(sample)) 106 int actual_count = samples.GetCount(sample);
107 if (histogram_snapshots.count(name))
108 actual_count -= histogram_snapshots[name]->GetCount(sample);
109 EXPECT_EQ(expected_count, actual_count)
86 << "Histogram \"" << name 110 << "Histogram \"" << name
87 << "\" does not have the right number of samples (" << expected_count 111 << "\" does not have the right number of samples (" << expected_count
88 << ") in the expected bucket (" << sample << ")."; 112 << ") in the expected bucket (" << sample << "). It has (" << actual_count
113 << ").";
89 } 114 }
90 115
91 void UMAHistogramHelper::CheckTotalCount( 116 void UMAHistogramHelper::CheckTotalCount(
92 const std::string& name, 117 const std::string& name,
93 base::HistogramBase::Count expected_count, 118 base::HistogramBase::Count expected_count,
94 base::HistogramSamples& samples) { 119 base::HistogramSamples& samples) {
95 EXPECT_EQ(expected_count, samples.TotalCount()) 120 int actual_count = samples.TotalCount();
121 if (histogram_snapshots.count(name))
122 actual_count -= histogram_snapshots[name]->TotalCount();
123 EXPECT_EQ(expected_count, actual_count)
96 << "Histogram \"" << name 124 << "Histogram \"" << name
97 << "\" does not have the right total number of samples (" 125 << "\" does not have the right total number of samples ("
98 << expected_count << ")."; 126 << expected_count << "). It has (" << actual_count << ").";
99 } 127 }
OLDNEW
« no previous file with comments | « chrome/test/base/uma_histogram_helper.h ('k') | components/signin/core/browser/account_reconcilor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698