2010-04-14 22:32:20 +02: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-16 01:40:23 +02:00
|
|
|
#include <cstdio>
|
2010-04-14 22:32:20 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include "metrics_library.h"
|
|
|
|
|
|
|
|
// Usage: metrics_client [-ab] metric_name metric_value
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
bool send_to_autotest = false;
|
|
|
|
bool send_to_chrome = true;
|
2010-04-16 01:40:23 +02:00
|
|
|
bool secs_to_msecs = false;
|
2010-04-14 22:32:20 +02:00
|
|
|
int metric_name_index = 1;
|
|
|
|
int metric_value_index = 2;
|
|
|
|
bool print_usage = false;
|
|
|
|
|
|
|
|
if (argc >= 3) {
|
|
|
|
// Parse arguments
|
|
|
|
int flag;
|
2010-04-16 01:40:23 +02:00
|
|
|
while ((flag = getopt(argc, argv, "abt")) != -1) {
|
2010-04-14 22:32:20 +02: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-16 01:40:23 +02:00
|
|
|
case 't':
|
|
|
|
secs_to_msecs = true;
|
|
|
|
break;
|
2010-04-14 22:32:20 +02:00
|
|
|
default:
|
|
|
|
print_usage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
metric_name_index = optind;
|
|
|
|
metric_value_index = optind + 1;
|
|
|
|
} else {
|
|
|
|
print_usage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metrics value should be the last argument passed
|
|
|
|
if ((metric_value_index + 1) != argc) {
|
|
|
|
print_usage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_usage) {
|
2010-04-16 01:40:23 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: metrics_client [-abt] name value\n"
|
|
|
|
"\n"
|
|
|
|
" default: send metric with integer value to chrome only\n"
|
|
|
|
" -a: send metric to autotest only\n"
|
|
|
|
" -b: send metric to both chrome and autotest\n"
|
|
|
|
" -t: convert value from float seconds to int milliseconds\n");
|
2010-04-14 22:32:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-16 01:40:23 +02:00
|
|
|
const char* name = argv[metric_name_index];
|
|
|
|
int value;
|
|
|
|
if (secs_to_msecs) {
|
|
|
|
float secs = strtof(argv[metric_value_index], NULL);
|
|
|
|
value = static_cast<int>(secs * 1000.0f);
|
|
|
|
} else {
|
|
|
|
value = atoi(argv[metric_value_index]);
|
|
|
|
}
|
|
|
|
|
2010-04-14 22:32:20 +02:00
|
|
|
// Send metrics
|
|
|
|
if (send_to_autotest) {
|
2010-04-16 01:40:23 +02:00
|
|
|
MetricsLibrary::SendToAutotest(name, value);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
if (send_to_chrome) {
|
2010-04-16 01:40:23 +02:00
|
|
|
MetricsLibrary::SendToChrome(name, value);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|