metrics: Add SendBoolToUMA to metrics interface
BUG=none
TEST=FEATURES=test emerge-<BOARD> metrics
Change-Id: Ibe3dfc908a73290293b57267cc351bbd25d91f27
Reviewed-on: https://chromium-review.googlesource.com/302462
Commit-Ready: Nathan Bullock <nathanbullock@google.com>
Tested-by: Nathan Bullock <nathanbullock@google.com>
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
diff --git a/metrics/metrics_library.cc b/metrics/metrics_library.cc
index 2e9d69a..3cb0df6 100644
--- a/metrics/metrics_library.cc
+++ b/metrics/metrics_library.cc
@@ -171,6 +171,13 @@
kUMAEventsPath);
}
+bool MetricsLibrary::SendBoolToUMA(const std::string& name, bool sample) {
+ return metrics::SerializationUtils::WriteMetricToFile(
+ *metrics::MetricSample::LinearHistogramSample(name,
+ sample ? 1 : 0, 2).get(),
+ kUMAEventsPath);
+}
+
bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) {
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::SparseHistogramSample(name, sample).get(),
diff --git a/metrics/metrics_library.h b/metrics/metrics_library.h
index cb6e444..9f06a68 100644
--- a/metrics/metrics_library.h
+++ b/metrics/metrics_library.h
@@ -23,6 +23,7 @@
virtual bool SendToUMA(const std::string& name, int sample,
int min, int max, int nbuckets) = 0;
virtual bool SendEnumToUMA(const std::string& name, int sample, int max) = 0;
+ virtual bool SendBoolToUMA(const std::string& name, bool sample) = 0;
virtual bool SendSparseToUMA(const std::string& name, int sample) = 0;
virtual bool SendUserActionToUMA(const std::string& action) = 0;
virtual ~MetricsLibraryInterface() {}
@@ -79,6 +80,9 @@
// normal, while 100 is high).
bool SendEnumToUMA(const std::string& name, int sample, int max) override;
+ // Specialization of SendEnumToUMA for boolean values.
+ bool SendBoolToUMA(const std::string& name, bool sample) override;
+
// Sends sparse histogram sample to Chrome for transport to UMA. Returns
// true on success.
//
diff --git a/metrics/metrics_library_mock.h b/metrics/metrics_library_mock.h
index 99892bf..48f41cc 100644
--- a/metrics/metrics_library_mock.h
+++ b/metrics/metrics_library_mock.h
@@ -20,6 +20,7 @@
int min, int max, int nbuckets));
MOCK_METHOD3(SendEnumToUMA, bool(const std::string& name, int sample,
int max));
+ MOCK_METHOD2(SendBoolToUMA, bool(const std::string& name, bool sample));
MOCK_METHOD2(SendSparseToUMA, bool(const std::string& name, int sample));
MOCK_METHOD1(SendUserActionToUMA, bool(const std::string& action));