Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b7dce1f authored by Darin Petkov's avatar Darin Petkov
Browse files

Add support for linear/enumeration histograms.

parent c2526a12
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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;
@@ -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;
  }
@@ -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;
}
+17 −0
Original line number Diff line number Diff line
@@ -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);
}
+11 −0
Original line number Diff line number Diff line
@@ -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);
};