diff options
author | Nathan Bullock <nathanbullock@google.com> | 2015-11-06 14:02:45 -0500 |
---|---|---|
committer | Garret Kelly <gdk@google.com> | 2015-11-06 14:45:49 -0500 |
commit | 4a2a1bb146717ab3f63d1bfd0a226cb78b4bab8b (patch) | |
tree | 72430938c0c47c72a3a9b4e9bd461c0ba5e2109c | |
parent | 45213778d0f4b846b6e32efba902c7c5c184b4cf (diff) | |
download | metricsd-4a2a1bb146717ab3f63d1bfd0a226cb78b4bab8b.tar.gz |
metricsd: add SendBoolToUMA to metrics interface
Bug: 25561571
Change-Id: I698d2408e2f462865f6512b7be17ff0851a1f97c
-rw-r--r-- | include/metrics/metrics_library.h | 4 | ||||
-rw-r--r-- | include/metrics/metrics_library_mock.h | 1 | ||||
-rw-r--r-- | metrics_library.cc | 7 |
3 files changed, 12 insertions, 0 deletions
diff --git a/include/metrics/metrics_library.h b/include/metrics/metrics_library.h index b766194..d2e98c8 100644 --- a/include/metrics/metrics_library.h +++ b/include/metrics/metrics_library.h @@ -34,6 +34,7 @@ class MetricsLibraryInterface { 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() {} @@ -96,6 +97,9 @@ class MetricsLibrary : public MetricsLibraryInterface { // 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/include/metrics/metrics_library_mock.h b/include/metrics/metrics_library_mock.h index 3de87a9..db56f9e 100644 --- a/include/metrics/metrics_library_mock.h +++ b/include/metrics/metrics_library_mock.h @@ -32,6 +32,7 @@ class MetricsLibraryMock : public MetricsLibraryInterface { 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)); diff --git a/metrics_library.cc b/metrics_library.cc index a651b76..735d39f 100644 --- a/metrics_library.cc +++ b/metrics_library.cc @@ -173,6 +173,13 @@ bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample, uma_events_file_.value()); } +bool MetricsLibrary::SendBoolToUMA(const std::string& name, bool sample) { + return metrics::SerializationUtils::WriteMetricToFile( + *metrics::MetricSample::LinearHistogramSample(name, + sample ? 1 : 0, 2).get(), + uma_events_file_.value()); +} + bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::SparseHistogramSample(name, sample).get(), |