Loading metrics/metrics_client.cc +24 −9 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ int main(int argc, char** argv) { bool send_to_autotest = false; bool send_to_chrome = true; bool send_enum = false; bool secs_to_msecs = false; int name_index = 1; bool print_usage = false; Loading @@ -17,7 +18,7 @@ int main(int argc, char** argv) { if (argc >= 3) { // Parse arguments int flag; while ((flag = getopt(argc, argv, "abt")) != -1) { while ((flag = getopt(argc, argv, "abet")) != -1) { switch (flag) { case 'a': send_to_autotest = true; Loading @@ -27,6 +28,9 @@ int main(int argc, char** argv) { send_to_chrome = true; send_to_autotest = true; break; case 'e': send_enum = true; break; case 't': secs_to_msecs = true; break; Loading @@ -40,17 +44,22 @@ int main(int argc, char** argv) { print_usage = true; } if ((name_index + 5) != argc) { int num_args = send_enum ? 3 : 5; if ((name_index + num_args) != argc || (send_enum && secs_to_msecs)) { print_usage = true; } if (print_usage) { fprintf(stderr, "Usage: metrics_client [-abt] name sample min max nbuckets\n" "Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n" " metrics_client [-ab] -e name sample max\n" "\n" " default: send metric with integer values to Chrome only\n" " -a: send metric to autotest only (min/max/nbuckets ignored)\n" " -b: send metric to both chrome and autotest\n" " |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" " -t: convert sample from double seconds to int milliseconds\n"); return 1; } Loading @@ -62,16 +71,22 @@ int main(int argc, char** argv) { } else { sample = atoi(argv[name_index + 1]); } int min = atoi(argv[name_index + 2]); int max = atoi(argv[name_index + 3]); int nbuckets = atoi(argv[name_index + 4]); // Send metrics if (send_to_autotest) { MetricsLibrary::SendToAutotest(name, sample); } if (send_to_chrome) { if (send_enum) { int max = atoi(argv[name_index + 2]); MetricsLibrary::SendEnumToChrome(name, sample, max); } else { int min = atoi(argv[name_index + 2]); int max = atoi(argv[name_index + 3]); int nbuckets = atoi(argv[name_index + 4]); MetricsLibrary::SendToChrome(name, sample, min, max, nbuckets); } } return 0; } metrics/metrics_library.cc +17 −0 Original line number Diff line number Diff line Loading @@ -150,3 +150,20 @@ bool MetricsLibrary::SendToChrome(const string& name, int sample, // Send the message. return SendMessageToChrome(message_length, message); } //static bool MetricsLibrary::SendEnumToChrome(const std::string& name, int sample, int max) { // Format the message. char message[kBufferSize]; int32_t message_length = FormatChromeMessage(kBufferSize, message, "linearhistogram%c%s %d %d", '\0', name.c_str(), sample, max); if (message_length < 0) return false; // Send the message. return SendMessageToChrome(message_length, message); } metrics/metrics_library.h +11 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,17 @@ class MetricsLibrary { static bool SendToChrome(const std::string& name, int sample, int min, int max, int nbuckets); // Sends linear histogram data to Chrome for transport to UMA and // returns true on success. This method results in the equivalent of // an asynchronous non-blocking RPC to UMA_HISTOGRAM_ENUMERATION // inside Chrome (see base/histogram.h). // // |sample| is the sample value to be recorded (1 <= |sample| < |max|). // |max| is the maximum value of the histogram samples. // 0 is the implicit underflow bucket. // [|max|,infinity) is the implicit overflow bucket. static bool SendEnumToChrome(const std::string& name, int sample, int max); // Sends to Autotest and returns true on success. static bool SendToAutotest(const std::string& name, int value); }; Loading Loading
metrics/metrics_client.cc +24 −9 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ int main(int argc, char** argv) { bool send_to_autotest = false; bool send_to_chrome = true; bool send_enum = false; bool secs_to_msecs = false; int name_index = 1; bool print_usage = false; Loading @@ -17,7 +18,7 @@ int main(int argc, char** argv) { if (argc >= 3) { // Parse arguments int flag; while ((flag = getopt(argc, argv, "abt")) != -1) { while ((flag = getopt(argc, argv, "abet")) != -1) { switch (flag) { case 'a': send_to_autotest = true; Loading @@ -27,6 +28,9 @@ int main(int argc, char** argv) { send_to_chrome = true; send_to_autotest = true; break; case 'e': send_enum = true; break; case 't': secs_to_msecs = true; break; Loading @@ -40,17 +44,22 @@ int main(int argc, char** argv) { print_usage = true; } if ((name_index + 5) != argc) { int num_args = send_enum ? 3 : 5; if ((name_index + num_args) != argc || (send_enum && secs_to_msecs)) { print_usage = true; } if (print_usage) { fprintf(stderr, "Usage: metrics_client [-abt] name sample min max nbuckets\n" "Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n" " metrics_client [-ab] -e name sample max\n" "\n" " default: send metric with integer values to Chrome only\n" " -a: send metric to autotest only (min/max/nbuckets ignored)\n" " -b: send metric to both chrome and autotest\n" " |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" " -t: convert sample from double seconds to int milliseconds\n"); return 1; } Loading @@ -62,16 +71,22 @@ int main(int argc, char** argv) { } else { sample = atoi(argv[name_index + 1]); } int min = atoi(argv[name_index + 2]); int max = atoi(argv[name_index + 3]); int nbuckets = atoi(argv[name_index + 4]); // Send metrics if (send_to_autotest) { MetricsLibrary::SendToAutotest(name, sample); } if (send_to_chrome) { if (send_enum) { int max = atoi(argv[name_index + 2]); MetricsLibrary::SendEnumToChrome(name, sample, max); } else { int min = atoi(argv[name_index + 2]); int max = atoi(argv[name_index + 3]); int nbuckets = atoi(argv[name_index + 4]); MetricsLibrary::SendToChrome(name, sample, min, max, nbuckets); } } return 0; }
metrics/metrics_library.cc +17 −0 Original line number Diff line number Diff line Loading @@ -150,3 +150,20 @@ bool MetricsLibrary::SendToChrome(const string& name, int sample, // Send the message. return SendMessageToChrome(message_length, message); } //static bool MetricsLibrary::SendEnumToChrome(const std::string& name, int sample, int max) { // Format the message. char message[kBufferSize]; int32_t message_length = FormatChromeMessage(kBufferSize, message, "linearhistogram%c%s %d %d", '\0', name.c_str(), sample, max); if (message_length < 0) return false; // Send the message. return SendMessageToChrome(message_length, message); }
metrics/metrics_library.h +11 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,17 @@ class MetricsLibrary { static bool SendToChrome(const std::string& name, int sample, int min, int max, int nbuckets); // Sends linear histogram data to Chrome for transport to UMA and // returns true on success. This method results in the equivalent of // an asynchronous non-blocking RPC to UMA_HISTOGRAM_ENUMERATION // inside Chrome (see base/histogram.h). // // |sample| is the sample value to be recorded (1 <= |sample| < |max|). // |max| is the maximum value of the histogram samples. // 0 is the implicit underflow bucket. // [|max|,infinity) is the implicit overflow bucket. static bool SendEnumToChrome(const std::string& name, int sample, int max); // Sends to Autotest and returns true on success. static bool SendToAutotest(const std::string& name, int value); }; Loading