Ejemplo n.º 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
 * @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);
}
Ejemplo n.º 2
0
void * radix_longest_prefix_value(radix_tree *t, char *key)
{
    void *value = NULL;
    radix_longest_prefix(t, key, &value);
    return value;
}