2010-04-14 20:32:20 +00:00
|
|
|
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2010-04-15 23:40:23 +00:00
|
|
|
#include <cstdio>
|
2010-04-14 20:32:20 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include "metrics_library.h"
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
bool send_to_autotest = false;
|
|
|
|
bool send_to_chrome = true;
|
2010-04-21 22:45:10 +00:00
|
|
|
bool send_enum = false;
|
2010-04-15 23:40:23 +00:00
|
|
|
bool secs_to_msecs = false;
|
2010-04-21 21:24:04 +00:00
|
|
|
int name_index = 1;
|
2010-04-14 20:32:20 +00:00
|
|
|
bool print_usage = false;
|
|
|
|
|
|
|
|
if (argc >= 3) {
|
|
|
|
// Parse arguments
|
|
|
|
int flag;
|
2010-04-21 22:45:10 +00:00
|
|
|
while ((flag = getopt(argc, argv, "abet")) != -1) {
|
2010-04-14 20:32:20 +00:00
|
|
|
switch (flag) {
|
|
|
|
case 'a':
|
|
|
|
send_to_autotest = true;
|
|
|
|
send_to_chrome = false;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
send_to_chrome = true;
|
|
|
|
send_to_autotest = true;
|
|
|
|
break;
|
2010-04-21 22:45:10 +00:00
|
|
|
case 'e':
|
|
|
|
send_enum = true;
|
|
|
|
break;
|
2010-04-15 23:40:23 +00:00
|
|
|
case 't':
|
|
|
|
secs_to_msecs = true;
|
|
|
|
break;
|
2010-04-14 20:32:20 +00:00
|
|
|
default:
|
|
|
|
print_usage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-21 21:24:04 +00:00
|
|
|
name_index = optind;
|
2010-04-14 20:32:20 +00:00
|
|
|
} else {
|
|
|
|
print_usage = true;
|
|
|
|
}
|
|
|
|
|
2010-04-21 22:45:10 +00:00
|
|
|
int num_args = send_enum ? 3 : 5;
|
|
|
|
if ((name_index + num_args) != argc ||
|
|
|
|
(send_enum && secs_to_msecs)) {
|
2010-04-14 20:32:20 +00:00
|
|
|
print_usage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_usage) {
|
2010-04-15 23:40:23 +00:00
|
|
|
fprintf(stderr,
|
2010-04-21 22:45:10 +00:00
|
|
|
"Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n"
|
|
|
|
" metrics_client [-ab] -e name sample max\n"
|
2010-04-15 23:40:23 +00:00
|
|
|
"\n"
|
2010-04-21 21:24:04 +00:00
|
|
|
" default: send metric with integer values to Chrome only\n"
|
2010-04-21 22:45:10 +00:00
|
|
|
" |min| > 0, |min| <= sample < |max|\n"
|
|
|
|
" -a: send metric (name/sample) to Autotest only\n"
|
|
|
|
" -b: send metric to both Chrome and Autotest\n"
|
|
|
|
" -e: send linear/enumeration histogram data\n"
|
2010-04-21 21:24:04 +00:00
|
|
|
" -t: convert sample from double seconds to int milliseconds\n");
|
2010-04-14 20:32:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-21 21:24:04 +00:00
|
|
|
const char* name = argv[name_index];
|
|
|
|
int sample;
|
2010-04-15 23:40:23 +00:00
|
|
|
if (secs_to_msecs) {
|
2010-04-21 21:24:04 +00:00
|
|
|
sample = static_cast<int>(atof(argv[name_index + 1]) * 1000.0);
|
2010-04-15 23:40:23 +00:00
|
|
|
} else {
|
2010-04-21 21:24:04 +00:00
|
|
|
sample = atoi(argv[name_index + 1]);
|
2010-04-15 23:40:23 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 20:32:20 +00:00
|
|
|
// Send metrics
|
|
|
|
if (send_to_autotest) {
|
2010-04-21 21:24:04 +00:00
|
|
|
MetricsLibrary::SendToAutotest(name, sample);
|
2010-04-14 20:32:20 +00:00
|
|
|
}
|
2010-04-21 22:45:10 +00:00
|
|
|
|
2010-04-14 20:32:20 +00:00
|
|
|
if (send_to_chrome) {
|
2010-05-12 22:26:16 +00:00
|
|
|
MetricsLibrary metrics_lib;
|
|
|
|
metrics_lib.Init();
|
2010-04-21 22:45:10 +00:00
|
|
|
if (send_enum) {
|
|
|
|
int max = atoi(argv[name_index + 2]);
|
2010-05-12 22:26:16 +00:00
|
|
|
metrics_lib.SendEnumToUMA(name, sample, max);
|
2010-04-21 22:45:10 +00:00
|
|
|
} else {
|
|
|
|
int min = atoi(argv[name_index + 2]);
|
|
|
|
int max = atoi(argv[name_index + 3]);
|
|
|
|
int nbuckets = atoi(argv[name_index + 4]);
|
2010-05-12 22:26:16 +00:00
|
|
|
metrics_lib.SendToUMA(name, sample, min, max, nbuckets);
|
2010-04-21 22:45:10 +00:00
|
|
|
}
|
2010-04-14 20:32:20 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|