Exemple #1
0
/**
 * Adds a new timer sample for the timer with a
 * given name.
 * @arg name The name of the timer
 * @arg val The sample to add
 * @return 0 on success.
 */
static int metrics_add_timer_sample(metrics *m, char *name, double val) {
    timer *t;
    int res = hashmap_get(m->timers, name, (void**)&t);

    // New timer
    if (res == -1) {
        t = malloc(sizeof(timer));
        init_timer(m->eps, m->quantiles, m->num_quants, t);
        hashmap_put(m->timers, name, t);
    }

    // Add the sample value
    return timer_add_sample(t, val);
}
Exemple #2
0
static VALUE strstat_timer_add_sample(VALUE self, VALUE rb_sample) {

  double sample;
  timer *i_timer;
  int returned;

  sample = NUM2DBL(rb_sample);
  i_timer = (timer*) strstat_get_struct(self);

  returned = timer_add_sample(i_timer, sample);
  if (returned != 0) {
    rb_raise(rb_eRuntimeError, "add sample returned %d", returned);
  }

  return Qnil;
}
Exemple #3
0
/**
 * Adds a new timer sample for the timer with a
 * given name.
 * @arg name The name of the timer
 * @arg val The sample to add
 * @arg sample_rate The sample rate of val
 * @return 0 on success.
 */
static int metrics_add_timer_sample(metrics *m, char *name, double val, double sample_rate) {
    timer_hist *t;
    histogram_config *conf;
    int res = hashmap_get(m->timers, name, (void**)&t);

    // New timer
    if (res == -1) {
        t = malloc(sizeof(timer_hist));
        init_timer(m->timer_eps, m->quantiles, m->num_quants, &t->tm);
        hashmap_put(m->timers, name, t);

        // Check if we have any histograms configured
        if (m->histograms && !radix_longest_prefix(m->histograms, name, (void**)&conf)) {
            t->conf = conf;
            t->counts = calloc(conf->num_bins, sizeof(unsigned int));
        } else {
            t->conf = NULL;
            t->counts = NULL;
        }
    }

    // Add the histogram value
    if (t->conf) {
        conf = t->conf;
        if (val < conf->min_val)
            t->counts[0]++;
        else if (val >= conf->max_val)
            t->counts[conf->num_bins - 1]++;
        else {
            int idx = ((val - conf->min_val) / conf->bin_width) + 1;
            t->counts[idx]++;
        }
    }

    // Add the sample value
    return timer_add_sample(&t->tm, val, sample_rate);
}