Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <errno.h> |
| 6 | #include <sys/file.h> |
| 7 | #include <string.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <cstdlib> |
| 11 | #include <iostream> |
| 12 | |
| 13 | #include "metrics_library.h" |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | // Usage: metrics_client [-ab] metric_name metric_value |
| 18 | int main(int argc, char** argv) { |
| 19 | bool send_to_autotest = false; |
| 20 | bool send_to_chrome = true; |
| 21 | int metric_name_index = 1; |
| 22 | int metric_value_index = 2; |
| 23 | bool print_usage = false; |
| 24 | |
| 25 | if (argc >= 3) { |
| 26 | // Parse arguments |
| 27 | int flag; |
| 28 | while ((flag = getopt(argc, argv, "ab")) != -1) { |
| 29 | switch (flag) { |
| 30 | case 'a': |
| 31 | send_to_autotest = true; |
| 32 | send_to_chrome = false; |
| 33 | break; |
| 34 | case 'b': |
| 35 | send_to_chrome = true; |
| 36 | send_to_autotest = true; |
| 37 | break; |
| 38 | default: |
| 39 | print_usage = true; |
| 40 | break; |
| 41 | } |
| 42 | } |
| 43 | metric_name_index = optind; |
| 44 | metric_value_index = optind + 1; |
| 45 | } else { |
| 46 | print_usage = true; |
| 47 | } |
| 48 | |
| 49 | // Metrics value should be the last argument passed |
| 50 | if ((metric_value_index + 1) != argc) { |
| 51 | print_usage = true; |
| 52 | } |
| 53 | |
| 54 | if (print_usage) { |
| 55 | cerr << "Usage: metrics_client [-ab] name value" << endl; |
| 56 | cerr << endl; |
| 57 | cerr << " default: send metric to chrome only" << endl; |
| 58 | cerr << " -a: send metric to autotest only" << endl; |
| 59 | cerr << " -b: send metric to both chrome and autotest" << endl; |
| 60 | return 1; |
| 61 | } |
| 62 | |
| 63 | // Send metrics |
| 64 | if (send_to_autotest) { |
| 65 | MetricsLibrary::SendToAutotest(argv[metric_name_index], |
| 66 | argv[metric_value_index]); |
| 67 | } |
| 68 | if (send_to_chrome) { |
| 69 | MetricsLibrary::SendToChrome(argv[metric_name_index], |
| 70 | argv[metric_value_index]); |
| 71 | } |
| 72 | return 0; |
| 73 | } |