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

Unified Diff: chrome/browser/extensions/api/metrics_private/metrics_apitest.cc

Issue 213433003: Add Sparse Histogram Support to metricsPrivate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Feedback Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/metrics_private/metrics_apitest.cc
diff --git a/chrome/browser/extensions/api/metrics_private/metrics_apitest.cc b/chrome/browser/extensions/api/metrics_private/metrics_apitest.cc
index f910a35279edd9860388eae837e309b56e313b30..f04cbdaed834ed0672925379c63c2ed4e4b2d03b 100644
--- a/chrome/browser/extensions/api/metrics_private/metrics_apitest.cc
+++ b/chrome/browser/extensions/api/metrics_private/metrics_apitest.cc
@@ -38,6 +38,9 @@ struct RecordedHistogram {
{"test.h.1", base::HISTOGRAM, 1, 100, 50, 1}, // custom
{"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50, 1}, // custom
{"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102, 2}, // percentage
+ {"test.sparse.1", base::SPARSE_HISTOGRAM, 0, 0, 0, 1},
+ {"test.sparse.2", base::SPARSE_HISTOGRAM, 0, 0, 0, 2},
+ {"test.sparse.3", base::SPARSE_HISTOGRAM, 0, 0, 0, 6},
{"test.time", base::HISTOGRAM, 1, 10000, 50, 1},
{"test.medium.time", base::HISTOGRAM, 1, 180000, 50, 1},
{"test.long.time", base::HISTOGRAM, 1, 3600000, 50, 1},
@@ -47,6 +50,22 @@ struct RecordedHistogram {
{"test.bucketchange.linear", base::LINEAR_HISTOGRAM, 1, 100, 10, 2},
{"test.bucketchange.log", base::HISTOGRAM, 1, 100, 10, 2}, };
+// Represents a bucket in a sparse histogram.
+struct Bucket {
+ int histogram_value;
+ int count;
+};
+
+// We expect the following sparse histograms.
+struct SparseHistogram {
+ const char* name;
+ int bucket_count;
+ Bucket buckets[10];
+} g_sparse_histograms[] = {
+ {"test.sparse.1", 1, {{42, 1}}},
+ {"test.sparse.2", 1, {{24, 2}}},
+ {"test.sparse.3", 3, {{1, 1}, {2, 2}, {3, 3}}}};
+
// This class observes and collects user action notifications that are sent
// by the tests, so that they can be examined afterwards for correctness.
class UserActionObserver {
@@ -99,6 +118,20 @@ void UserActionObserver::ValidateUserActions(const RecordedUserAction* recorded,
}
}
+void ValidateSparseHistogramSamples(
+ const char* name,
Ilya Sherman 2014/03/27 00:08:16 nit: Please pass this as a const std::string&, rat
robliao 2014/03/27 00:21:53 Done.
+ const base::HistogramSamples* samples) {
Ilya Sherman 2014/03/27 00:08:16 nit: Please pass by const-ref rather than const-po
robliao 2014/03/27 00:21:53 This is why it was scoped_ptr<...>&. That was pref
+ for (int i = 0; i < arraysize(g_sparse_histograms); ++i) {
+ const SparseHistogram& sparse_histogram = g_sparse_histograms[i];
+ if (std::string(name) == sparse_histogram.name) {
+ for (int j = 0; j < sparse_histogram.bucket_count; ++j) {
+ const Bucket& bucket = sparse_histogram.buckets[j];
+ EXPECT_EQ(bucket.count, samples->GetCount(bucket.histogram_value));
+ }
+ }
+ }
+}
+
void ValidateHistograms(const RecordedHistogram* recorded,
int count) {
base::StatisticsRecorder::Histograms histograms;
@@ -113,15 +146,19 @@ void ValidateHistograms(const RecordedHistogram* recorded,
size_t j = 0;
for (j = 0; j < histograms.size(); ++j) {
base::HistogramBase* histogram(histograms[j]);
-
if (r.name == histogram->histogram_name()) {
- EXPECT_EQ(r.type, histogram->GetHistogramType());
- EXPECT_TRUE(
- histogram->HasConstructionArguments(r.min, r.max, r.buckets));
scoped_ptr<base::HistogramSamples> snapshot =
histogram->SnapshotSamples();
base::HistogramBase::Count sample_count = snapshot->TotalCount();
- EXPECT_EQ(sample_count, r.count);
+ EXPECT_EQ(r.count, sample_count);
+
+ EXPECT_EQ(r.type, histogram->GetHistogramType());
+ if (r.type == base::SPARSE_HISTOGRAM) {
+ ValidateSparseHistogramSamples(r.name, snapshot.get());
+ } else {
+ EXPECT_TRUE(
+ histogram->HasConstructionArguments(r.min, r.max, r.buckets));
+ }
break;
}
}

Powered by Google App Engine
This is Rietveld 408576698