Add generic "event of interest" enumerated histogram.
This change aims to simplify the addition of events we may
want to track in the field, more specifically hard-to-reproduce
bugs. Before this change, this requires creating a new histogram
and registering it via histograms.xml, which is not in the Chrome OS
repositories. With this change, a new event just requires claiming
an event name (such as ModemManagerCommandSendFailure) in
metrics_library.cc, and running "metrics_client -v <event name>"
or calling SendCrosEventToUMA(event_name).
I can make up a bug for this. Or not.
BUG=none
TEST=compiled
Change-Id: I9c56b58310f0d22e77624edee7fe6149abd60a49
Reviewed-on: https://gerrit.chromium.org/gerrit/45322
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
diff --git a/metrics/metrics_library.cc b/metrics/metrics_library.cc
index fe48122..a2227ac 100644
--- a/metrics/metrics_library.cc
+++ b/metrics/metrics_library.cc
@@ -24,6 +24,8 @@
static const char kUMAEventsPath[] = "/var/log/metrics/uma-events";
static const char kConsentFile[] = "/home/chronos/Consent To Send Stats";
static const int32_t kBufferSize = 1024;
+static const char kCrosEventHistogramName[] = "Platform.CrOSEvent";
+static const int kCrosEventHistogramMax = 100;
time_t MetricsLibrary::cached_enabled_time_ = 0;
bool MetricsLibrary::cached_enabled_ = false;
@@ -306,3 +308,19 @@
void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) {
policy_provider_.reset(provider);
}
+
+bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) {
+ int n;
+ /* Add new events here.
+ *
+ * Whoever adds the second event (if anybody) please be so kind to change
+ * this to a map lookup. (Or at least change "second" above to "third",
+ * etc.)
+ */
+ if (event.compare("ModemManagerCommandSendFailure") == 0) {
+ n = 0;
+ } else {
+ return false;
+ }
+ return SendEnumToUMA(kCrosEventHistogramName, n, kCrosEventHistogramMax);
+}