OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cstdio> | 5 #include <cstdio> |
6 #include <cstdlib> | 6 #include <cstdlib> |
7 | 7 |
8 #include "metrics_library.h" | 8 #include "metrics_library.h" |
9 | 9 |
10 // Usage: metrics_client [-ab] metric_name metric_value | |
11 int main(int argc, char** argv) { | 10 int main(int argc, char** argv) { |
12 bool send_to_autotest = false; | 11 bool send_to_autotest = false; |
13 bool send_to_chrome = true; | 12 bool send_to_chrome = true; |
14 bool secs_to_msecs = false; | 13 bool secs_to_msecs = false; |
15 int metric_name_index = 1; | 14 int name_index = 1; |
16 int metric_value_index = 2; | |
17 bool print_usage = false; | 15 bool print_usage = false; |
18 | 16 |
19 if (argc >= 3) { | 17 if (argc >= 3) { |
20 // Parse arguments | 18 // Parse arguments |
21 int flag; | 19 int flag; |
22 while ((flag = getopt(argc, argv, "abt")) != -1) { | 20 while ((flag = getopt(argc, argv, "abt")) != -1) { |
23 switch (flag) { | 21 switch (flag) { |
24 case 'a': | 22 case 'a': |
25 send_to_autotest = true; | 23 send_to_autotest = true; |
26 send_to_chrome = false; | 24 send_to_chrome = false; |
27 break; | 25 break; |
28 case 'b': | 26 case 'b': |
29 send_to_chrome = true; | 27 send_to_chrome = true; |
30 send_to_autotest = true; | 28 send_to_autotest = true; |
31 break; | 29 break; |
32 case 't': | 30 case 't': |
33 secs_to_msecs = true; | 31 secs_to_msecs = true; |
34 break; | 32 break; |
35 default: | 33 default: |
36 print_usage = true; | 34 print_usage = true; |
37 break; | 35 break; |
38 } | 36 } |
39 } | 37 } |
40 metric_name_index = optind; | 38 name_index = optind; |
41 metric_value_index = optind + 1; | |
42 } else { | 39 } else { |
43 print_usage = true; | 40 print_usage = true; |
44 } | 41 } |
45 | 42 |
46 // Metrics value should be the last argument passed | 43 if ((name_index + 5) != argc) { |
47 if ((metric_value_index + 1) != argc) { | |
48 print_usage = true; | 44 print_usage = true; |
49 } | 45 } |
50 | 46 |
51 if (print_usage) { | 47 if (print_usage) { |
52 fprintf(stderr, | 48 fprintf(stderr, |
53 "Usage: metrics_client [-abt] name value\n" | 49 "Usage: metrics_client [-abt] name sample min max nbuckets\n" |
54 "\n" | 50 "\n" |
55 " default: send metric with integer value to chrome only\n" | 51 " default: send metric with integer values to Chrome only\n" |
56 " -a: send metric to autotest only\n" | 52 " -a: send metric to autotest only (min/max/nbuckets ignored)\n" |
57 " -b: send metric to both chrome and autotest\n" | 53 " -b: send metric to both chrome and autotest\n" |
58 " -t: convert value from float seconds to int milliseconds\n"); | 54 " -t: convert sample from double seconds to int milliseconds\n"); |
59 return 1; | 55 return 1; |
60 } | 56 } |
61 | 57 |
62 const char* name = argv[metric_name_index]; | 58 const char* name = argv[name_index]; |
63 int value; | 59 int sample; |
64 if (secs_to_msecs) { | 60 if (secs_to_msecs) { |
65 float secs = strtof(argv[metric_value_index], NULL); | 61 sample = static_cast<int>(atof(argv[name_index + 1]) * 1000.0); |
66 value = static_cast<int>(secs * 1000.0f); | |
67 } else { | 62 } else { |
68 value = atoi(argv[metric_value_index]); | 63 sample = atoi(argv[name_index + 1]); |
69 } | 64 } |
| 65 int min = atoi(argv[name_index + 2]); |
| 66 int max = atoi(argv[name_index + 3]); |
| 67 int nbuckets = atoi(argv[name_index + 4]); |
70 | 68 |
71 // Send metrics | 69 // Send metrics |
72 if (send_to_autotest) { | 70 if (send_to_autotest) { |
73 MetricsLibrary::SendToAutotest(name, value); | 71 MetricsLibrary::SendToAutotest(name, sample); |
74 } | 72 } |
75 if (send_to_chrome) { | 73 if (send_to_chrome) { |
76 MetricsLibrary::SendToChrome(name, value); | 74 MetricsLibrary::SendToChrome(name, sample, min, max, nbuckets); |
77 } | 75 } |
78 return 0; | 76 return 0; |
79 } | 77 } |
OLD | NEW |