X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=e63a20e548e0369ae0ec3faa9c2ee10144ba1adb;hp=7d6e8fd6eb23a8cdedd837ca0de6cda5588dcf08;hb=9f8dc5668faf5432dcb1430017bd7a1c383c2453;hpb=867ad628dc6fcd05bd584b605d7093cfc00c3d07 diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 7d6e8fd6..e63a20e5 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -28,10 +28,10 @@ #include "collectd.h" -#include "common.h" -#include "meta_data.h" #include "plugin.h" -#include "utils_avltree.h" +#include "utils/avltree/avltree.h" +#include "utils/common/common.h" +#include "utils/metadata/meta_data.h" #include "utils_cache.h" #include @@ -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; } @@ -201,7 +201,11 @@ static int uc_insert(const data_set_t *ds, const value_list_t *vl, ce->last_time = vl->time; ce->last_update = cdtime(); ce->interval = vl->interval; - ce->state = STATE_OKAY; + ce->state = STATE_UNKNOWN; + + if (vl->meta != NULL) { + ce->meta = meta_data_clone(vl->meta); + } if (c_avl_insert(cache_tree, key_copy, ce) != 0) { sfree(key_copy); @@ -381,7 +385,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. */ @@ -469,8 +473,8 @@ 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 != ds->ds_num) { - ERROR("utils_cache: uc_get_rate: ds[%s] has %zu values, " - "but uc_get_rate_by_name returned %zu.", + 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; @@ -488,7 +492,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 */ @@ -504,8 +508,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; } @@ -537,10 +540,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); } @@ -827,9 +830,7 @@ int uc_inc_hits(const data_set_t *ds, const value_list_t *vl, int step) { * Iterator interface */ uc_iter_t *uc_get_iterator(void) { - uc_iter_t *iter; - - iter = (uc_iter_t *)calloc(1, sizeof(*iter)); + uc_iter_t *iter = calloc(1, sizeof(*iter)); if (iter == NULL) return NULL; @@ -892,13 +893,12 @@ int uc_iterator_get_values(uc_iter_t *iter, value_t **ret_values, if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL) || (ret_num == NULL)) return -1; - *ret_values = calloc(iter->entry->values_num, sizeof(*iter->entry->values_raw)); if (*ret_values == NULL) return -1; for (size_t i = 0; i < iter->entry->values_num; ++i) - *ret_values[i] = iter->entry->values_raw[i]; + (*ret_values)[i] = iter->entry->values_raw[i]; *ret_num = iter->entry->values_num; @@ -913,6 +913,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 */ @@ -990,7 +999,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, @@ -1006,6 +1015,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