X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=610c11e51dee4ed3aa481923a625088e2a958122;hp=18aa66b74ad14c6b869b298992d3540c85a34e64;hb=d486225f89ea52d8ed2b4242eba2ad94c409f837;hpb=c144ae4659e129a929afb67706a54604220fef43 diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 18aa66b7..610c11e5 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -76,7 +76,7 @@ struct uc_iter_s { cache_entry_t *entry; }; -static c_avl_tree_t *cache_tree = NULL; +static c_avl_tree_t *cache_tree; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; static int cache_compare(const cache_entry_t *a, const cache_entry_t *b) { @@ -154,7 +154,7 @@ static int uc_insert(const data_set_t *ds, const value_list_t *vl, ce = cache_alloc(ds->ds_num); if (ce == NULL) { sfree(key_copy); - ERROR("uc_insert: cache_alloc (%zu) failed.", ds->ds_num); + ERROR("uc_insert: cache_alloc (%" PRIsz ") failed.", ds->ds_num); return -1; } @@ -222,8 +222,6 @@ int uc_init(void) { } /* int uc_init */ int uc_check_timeout(void) { - cdtime_t now = cdtime(); - struct { char *key; cdtime_t time; @@ -232,6 +230,7 @@ int uc_check_timeout(void) { size_t expired_num = 0; pthread_mutex_lock(&cache_lock); + cdtime_t now = cdtime(); /* Build a list of entries to be flushed */ c_avl_iterator_t *iter = c_avl_get_iterator(cache_tree); @@ -382,7 +381,7 @@ int uc_update(const data_set_t *ds, const value_list_t *vl) { return -1; } /* switch (ds->ds[i].type) */ - DEBUG("uc_update: %s: ds[%zu] = %lf", name, i, ce->values_gauge[i]); + DEBUG("uc_update: %s: ds[%" PRIsz "] = %lf", name, i, ce->values_gauge[i]); } /* for (i) */ /* Update the history if it exists. */ @@ -423,6 +422,9 @@ int uc_get_rate_by_name(const char *name, gauge_t **ret_values, /* remove missing values from getval */ if (ce->state == STATE_MISSING) { + DEBUG("utils_cache: uc_get_rate_by_name: requested metric \"%s\" is in " + "state \"missing\".", + name); status = -1; } else { ret_num = ce->values_num; @@ -466,9 +468,9 @@ gauge_t *uc_get_rate(const data_set_t *ds, const value_list_t *vl) { /* This is important - the caller has no other way of knowing how many * values are returned. */ - if (ret_num != (size_t)ds->ds_num) { - ERROR("utils_cache: uc_get_rate: ds[%s] has %zu values, " - "but uc_get_rate_by_name returned %zu.", + if (ret_num != ds->ds_num) { + ERROR("utils_cache: uc_get_rate: ds[%s] has %" PRIsz " values, " + "but uc_get_rate_by_name returned %" PRIsz ".", ds->type, ds->ds_num, ret_num); sfree(ret); return NULL; @@ -486,7 +488,7 @@ int uc_get_value_by_name(const char *name, value_t **ret_values, pthread_mutex_lock(&cache_lock); - if (c_avl_get(cache_tree, name, (void *) &ce) == 0) { + if (c_avl_get(cache_tree, name, (void *)&ce) == 0) { assert(ce != NULL); /* remove missing values from getval */ @@ -502,8 +504,7 @@ int uc_get_value_by_name(const char *name, value_t **ret_values, memcpy(ret, ce->values_raw, ret_num * sizeof(value_t)); } } - } - else { + } else { DEBUG("utils_cache: uc_get_value_by_name: No such value: %s", name); status = -1; } @@ -535,10 +536,10 @@ value_t *uc_get_value(const data_set_t *ds, const value_list_t *vl) { /* This is important - the caller has no other way of knowing how many * values are returned. */ - if (ret_num != (size_t) ds->ds_num) { - ERROR("utils_cache: uc_get_value: ds[%s] has %zu values, " - "but uc_get_value_by_name returned %zu.", ds->type, ds->ds_num, - ret_num); + if (ret_num != (size_t)ds->ds_num) { + ERROR("utils_cache: uc_get_value: ds[%s] has %" PRIsz " values, " + "but uc_get_value_by_name returned %" PRIsz ".", + ds->type, ds->ds_num, ret_num); sfree(ret); return (NULL); } @@ -911,6 +912,15 @@ int uc_iterator_get_interval(uc_iter_t *iter, cdtime_t *ret_interval) { return 0; } /* int uc_iterator_get_name */ +int uc_iterator_get_meta(uc_iter_t *iter, meta_data_t **ret_meta) { + if ((iter == NULL) || (iter->entry == NULL) || (ret_meta == NULL)) + return -1; + + *ret_meta = meta_data_clone(iter->entry->meta); + + return 0; +} /* int uc_iterator_get_meta */ + /* * Meta data interface */ @@ -988,7 +998,7 @@ int uc_meta_data_exists(const value_list_t *vl, const value_list_t *vl, const char *key, double value) UC_WRAP(meta_data_add_double) int uc_meta_data_add_boolean( const value_list_t *vl, const char *key, - _Bool value) UC_WRAP(meta_data_add_boolean) + bool value) UC_WRAP(meta_data_add_boolean) int uc_meta_data_get_string(const value_list_t *vl, const char *key, @@ -1004,6 +1014,6 @@ int uc_meta_data_exists(const value_list_t *vl, const char *key, double *value) UC_WRAP(meta_data_get_double) int uc_meta_data_get_boolean( const value_list_t *vl, - const char *key, _Bool *value) + const char *key, bool *value) UC_WRAP(meta_data_get_boolean) #undef UC_WRAP