Add support for user actions to the metrics library and the metrics clients.
BUG=10696
TEST=unit tests, tested on the device through metrics_client and inspecting
the uma-events file.
Change-Id: Ie39dd8b5ab968c328993076369a4ba14cb7fcd81
Review URL: http://codereview.chromium.org/6094010
diff --git a/metrics/metrics_client.cc b/metrics/metrics_client.cc
index ce22e98..5aedd8b 100644
--- a/metrics/metrics_client.cc
+++ b/metrics/metrics_client.cc
@@ -11,6 +11,7 @@
fprintf(stderr,
"Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n"
" metrics_client [-ab] -e name sample max\n"
+ " metrics_client -u action\n"
" metrics_client [-cg]\n"
"\n"
" default: send metric with integer values to Chrome only\n"
@@ -20,7 +21,8 @@
" -c: return exit status 0 if user consents to stats, 1 otherwise\n"
" -e: send linear/enumeration histogram data\n"
" -g: return exit status 0 if machine in guest mode, 1 otherwise\n"
- " -t: convert sample from double seconds to int milliseconds\n");
+ " -t: convert sample from double seconds to int milliseconds\n"
+ " -u: send a user action to Chrome\n");
exit(1);
}
@@ -59,6 +61,14 @@
return 0;
}
+static int SendUserAction(char* argv[], int action_index) {
+ const char* action = argv[action_index];
+ MetricsLibrary metrics_lib;
+ metrics_lib.Init();
+ metrics_lib.SendUserActionToUMA(action);
+ return 0;
+}
+
static int HasConsent() {
MetricsLibrary metrics_lib;
metrics_lib.Init();
@@ -74,6 +84,7 @@
int main(int argc, char** argv) {
enum Mode {
kModeSendStats,
+ kModeSendUserAction,
kModeHasConsent,
kModeIsGuestMode
} mode = kModeSendStats;
@@ -85,7 +96,7 @@
// Parse arguments
int flag;
- while ((flag = getopt(argc, argv, "abcegt")) != -1) {
+ while ((flag = getopt(argc, argv, "abcegtu")) != -1) {
switch (flag) {
case 'a':
mode = kModeSendStats;
@@ -109,18 +120,23 @@
case 't':
secs_to_msecs = true;
break;
+ case 'u':
+ mode = kModeSendUserAction;
+ break;
default:
print_usage = true;
break;
}
}
- int name_index = optind;
+ int arg_index = optind;
int expected_args = 0;
if (mode == kModeSendStats)
expected_args = send_enum ? 3 : 5;
+ else if (mode == kModeSendUserAction)
+ expected_args = 1;
- if ((name_index + expected_args) != argc) {
+ if ((arg_index + expected_args) != argc) {
ShowUsage();
}
@@ -130,11 +146,13 @@
ShowUsage();
}
return SendStats(argv,
- name_index,
+ arg_index,
send_enum,
secs_to_msecs,
send_to_autotest,
send_to_chrome);
+ case kModeSendUserAction:
+ return SendUserAction(argv, arg_index);
case kModeHasConsent:
return HasConsent();
case kModeIsGuestMode: