diff options
| author | chenzizhan <[email protected]> | 2024-07-12 18:37:40 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2024-07-12 18:37:40 +0800 |
| commit | 6b3dcefab5b4049a3f40be9faab6a05c79a8bb5b (patch) | |
| tree | 97dadc0663c837671776729aa7a75ca0001d8752 | |
| parent | dcc5329f090d4d3e1f2b1ea6c09393c0397fc111 (diff) | |
renames
32 files changed, 260 insertions, 500 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 06c35b7..80c6cd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,14 +98,14 @@ include_directories(${PROJECT_SOURCE_DIR}/vendors) include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/include/fieldstat)
include_directories(${PROJECT_SOURCE_DIR}/src/metrics)
-include_directories(${PROJECT_SOURCE_DIR}/src/tags)
+include_directories(${PROJECT_SOURCE_DIR}/src/cells)
include_directories(${PROJECT_SOURCE_DIR}/src/utils)
file(GLOB SRC
"src/*.c"
"src/metrics/*.c"
- "src/tags/*.c"
+ "src/cells/*.c"
"src/exporter/*.c"
"src/utils/*.c"
"vendors/cjson/*.c"
diff --git a/include/fieldstat/fieldstat new.h b/include/fieldstat/fieldstat new.h deleted file mode 100644 index f9dcfda..0000000 --- a/include/fieldstat/fieldstat new.h +++ /dev/null @@ -1,240 +0,0 @@ -#pragma once -#include <stdio.h> -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stddef.h> -#include <stdbool.h> - -#define FS_OK 0 -#define FS_ERR_TOO_MANY_CELLS -1 -#define FS_ERR_NULL_HANDLER -2 -#define FS_ERR_INVALID_CUBE_ID -3 -#define FS_ERR_INVALID_METRIC_ID -4 -#define FS_ERR_INVALID_TAG -5 -#define FS_ERR_INVALID_PARAM -6 -#define FS_ERR_INVALID_KEY -7 - -enum metric_type -{ - METRIC_TYPE_COUNTER, - METRIC_TYPE_HLL, - METRIC_TYPE_HISTOGRAM, -}; - -enum field_type -{ - TAG_INTEGER, - TAG_DOUBLE, - TAG_CSTRING, -}; - -enum sampling_mode { - SAMPLING_MODE_COMPREHENSIVE, - SAMPLING_MODE_TOPK, - SAMPLING_MODE_SPREADSKETCH, -}; - -struct field { - const char *key; - enum field_type type; - union{ - long long value_longlong; - double value_double; - const char *value_str; - }; -}; - -struct fieldstat; -struct fieldstat *fieldstat_new(); -void fieldstat_free(struct fieldstat *instance); -// copy only registered cubes and metrics, not including cells. Used to new a instance of the same schema. -struct fieldstat *fieldstat_fork(const struct fieldstat *instance); - -/* - * let the configuration of target be the same as master, no matter what the configuration of target is. - * the configurations will be kept as much as possible, like cells in the same cube will be kept, but the cells in different cubes will be deleted. - * @ return FS_OK or FS_ERR_NULL_HANDLER -*/ -int fieldstat_calibrate(const struct fieldstat *master, struct fieldstat *replica); -/* - * @brief add an cube to this instance. Cube represents an template with a user-defined set of cells and metrics. - * @param cube_dimensions: tags that are shared by all cells in this cube. This is the key of the cube. Can be NULL. Must be unique. Shared_tags are ordered, which means that {"TAG_KEY": "123", "TAG_KEY2": "456"} and {"TAG_KEY2": "456", "TAG_KEY": "123"} are map to different cube. - * @param n_dimension: number of field in dimension. - * @param mode: sampling mode. Refer to enum sampling_mode. - * @param max_n_cell: max number of samplings(cells) in each cube. When mode is TOPK, max_n_cell > 0, while in COMPREHENSIVE mode, max_n_cell can be 0, meaning that there is no limit. - * @return cube id, if success; otherwise, return FS_ERR_NULL_HANDLER, or FS_ERR_INVALID_PARAM when (max_n_cell == 0 && mode == TOPK). return FS_ERR_INVALID_KEY when the cube_dimensions is not unique. -*/ -int fieldstat_create_cube(struct fieldstat *instance, const struct field *cube_dimensions, size_t n_dimension, enum sampling_mode mode, size_t max_n_cell); - -/* - @brief Change the topk cube primary metric id. When fieldstat_counter_add or fieldstat_counter_set are called on the primary metric, the topk record of such cell will be updated. - the default primary metric id is 0. - @return FS_OK, FS_ERR_NULL_HANDLER or FS_ERR_INVALID_CUBE_ID. - FS_ERR_INVALID_METRIC_ID when the metric is not registered to instance. - FS_ERR_INVALID_PARAM when the cube is not a topk sampling cube, or the metric is not a counter. - -*/ -int fieldstat_cube_set_primary_metric(struct fieldstat *instance, int cube_id, int metric_id); - -/* - * @brief Delete the cube of cube_id. All the cells and metrics are deleted. The cube_id may be reused by other new cubes. Increase the corresponding cube_version by 1. - * @return FS_OK, FS_ERR_NULL_HANDLER or FS_ERR_INVALID_CUBE_ID -*/ -int fieldstat_destroy_cube(struct fieldstat *instance, int cube_id); - -/* - * @brief add a metric to the cube of cube_id. One metric may be associated with different cells. - * @param metric_name: name of the metric. Cannot be NULL. Must be unique. - * @return metric id>=0 if success. If failed, return FS_ERR_NULL_HANDLER, FS_ERR_INVALID_KEY(when metric_name is not unique in this cube) -*/ -int fieldstat_register_counter(struct fieldstat *instance, int cube_id, const char *metric_name); - -/* - * @brief refer to fieldstat_register_counter. - * @param precision: the bigger, the larger memory consumption, while accuracy improved. Must be in [4, 18]. - * @return metric id if success. If failed, return FS_ERR_NULL_HANDLER, FS_ERR_INVALID_KEY(when metric_name is not unique in this cube), or FS_ERR_INVALID_PARAM(if precision not in range) -*/ -int fieldstat_register_hll(struct fieldstat *instance, int cube_id, const char *metric_name, unsigned char precision); - -/* - * @brief refer to fieldstat_register_counter. - * @param lowest_trackable_value: the lowest value that can be tracked (distinguishable from 0) by the histogram. Must be >= 1. - * @param highest_trackable_value: the highest value to be tracked by the histogram. Must be >= 2 * lowest_trackable_value. - * @param significant_figures: the precision of the histogram. Must be in [1, 5]. - * @return metric id if success. If failed, return FS_ERR_NULL_HANDLER, FS_ERR_INVALID_KEY(when metric_name is not unique in this cube), or FS_ERR_INVALID_PARAM(if any of the 3 params are out of range) -*/ -int fieldstat_register_hist(struct fieldstat *instance, int cube_id, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures); - -/* - * @brief let the value of counter metric of cell_id increase by `increment`. - * @param cube_id: cube id, previously returned by fieldstat_create_cube. - * @param metric_id: metric id, previously returned by fieldstat_register_counter. - * @param increment: increment of the counter metric. Can be negative. - * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail. - * FS_ERR_INVALID_PARAM when cube is topk, metric is primary metric, and increment is negative. - * FS_ERR_TOO_MANY_CELLS when the cube is full. - * In comprehensive mode, a full cube cannot be added any more cells. - * In topk mode, every increment matters, so even the cube is full, the cell can also replace the least frequent cell. -*/ -int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long increment); - -/* - * @brief let the value of counter metric equal to value. Other annotations refer to fieldstat_counter_incrby. - * @return Refer to fieldstat_counter_incrby. What's more, be cautious to call this function if the metric is a primary metric of a topk cube, - * in such case, FS_ERR_INVALID_PARAM will be the output when the value is set to a smaller one(increment is negative). -*/ -int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value); - -/* - * @brief add a key to the hll metric of cell_id. HLL approximates the number of distinct elements in a set of `key`s. - * @param key: key of the hll metric. Cannot be NULL. - * @param key_len: strlen(key). - * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail. - * Since topk only support counter, FS_ERR_INVALID_PARAM is returned when the cube is topk. -*/ -int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const char *key, size_t key_len); -int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct field *item, size_t item_len); - - -/* - * @brief Add a value to the histogram metric of cell_id. Histogram will record the distribution of the values. - The value bigger than highest_trackable_value will be set to highest_trackable_value. The value less than lowest_trackable_value will be tried to record, and, if succeed, remains in the record as -inf(most of the time) or 0(if value == 0) - * @param value: value of the histogram metric. - * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail. - * FS_ERR_INVALID_PARAM when value is less than 0, or the cube is topk. -*/ -int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value); - -/* - * @brief Delete all the cells, also the content of every metrics. The cube and metrics are not deleted. Increase cell_version by 1. - Note that the cell record won't be deleted at once, they just seem to be deleted. The cell record will be deleted when they are not used since the last reset and until the next reset. -*/ -void fieldstat_reset(struct fieldstat *instance); - -/* - @brief Merge the instance. The registered cubes and metrics are merged even if there are no cells added. - @return 0 if success. return FS_ERR_INVALID_PARAM when the registered cubes or metrics between dest and src of the same keys has different types or configurations(like different primary metric). -*/ -int fieldstat_merge(struct fieldstat *instance, const struct fieldstat *src); - -/* -------------------------------------------------------------------------- */ -/* query */ -/* -------------------------------------------------------------------------- */ - -struct field_list -{ - struct field *field; - size_t n_field; -}; - -/* - * @brief Get all the registered cubes. - * @param cube_ids: the cube ids. The caller should free it. Use it like: int *cube_ids; fieldstat_get_cubes(instance, &cube_ids, &n_cube); for (int i = 0; i < n_cube; i++) { printf("%d\n", cube_ids[i]); } free(cube_ids); - * @param n_cube: Length of cube_ids. -*/ -void fieldstat_get_cubes(const struct fieldstat *instance, int **cube_ids, int *n_cube); - -/* - * @brief Get all the registered metrics by fieldstat_register_counter, fieldstat_register_hll, fieldstat_register_hist. -*/ -void fieldstat_cube_get_metrics(const struct fieldstat *instance, int cube_id, int **metric_id_out, size_t *n_metric); - -void fieldstat_get_metric_in_cell(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int **metric_id_out, size_t *n_metric_out); - -// query the name of the metric, return NULL if metric_id is invalid. -const char *fieldstat_get_metric_name(const struct fieldstat *instance, int cube_id, int metric_id); - -// query the type of the metric. return (enum metric_type)-1 if metric_id is invalid. -enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int cube_id, int metric_id); - -/* - get the cell_dimensions added to cube when calling fieldstat_counter_incrby, fieldstat_counter_set, fieldstat_hll_add, fieldstat_hist_record. -*/ -void fieldstat_cube_get_cells(const struct fieldstat *instance, int cube_id, struct field_list **cell_dimensions, size_t *n_cell); - -/* - get the field of fieldstat_create_cube. User free them by calling fieldstat_tag_list_arr_free(struct field_list *, 1) - return NULL when ID is invalid. -*/ -struct field_list *fieldstat_cube_get_tags(const struct fieldstat *instance, int cube_id); - -/* - return a cube id corresponding to `cube_dimensions`. FS_ERR_INVALID_KEY is returned if the cube is not found. -*/ -int fieldstat_find_cube(const struct fieldstat *instance, const struct field *cube_dimensions, size_t n_dimensions); - -/* - get the cell numbers in a cube. Return FS_ERR_INVALID_CUBE_ID if cube_id is invalid. -*/ -int fieldstat_get_used_sampling(const struct fieldstat *instance, int cube_id); - -/* - * @brief Get the value of a metric of a cell. - * @param cube_id: cube id, previously returned by fieldstat_get_cubes. - * @param metric_id: metric id, previously returned by fieldstat_get_max_metric_id. - * @param cell_dimensions: previously returned by fieldstat_get_cells_used_by_metric. - * @param value_out: the value of the metric. If the cell is not found, *value_out is set to 0. - * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail. -*/ -int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long *value); - -/* - @brief Get an approximate count of the number of distinct elements in the cell. Other information refer to fieldstat_counter_get. - @return >= 0 if success. FS_ERR_INVALID_PARAM if precision is invalid. -*/ -int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double *value); -long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double percentile); -long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long value); - -// get the base 64 encoded string of the serialized blob of a cell -void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct field_list *cell_dimensions, char **blob, size_t *blob_size); - -void fieldstat_tag_list_arr_free(struct field_list *tag_list, size_t n_cell); - - -#ifdef __cplusplus -} -#endif
\ No newline at end of file diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h index c121a48..dc3db94 100644 --- a/include/fieldstat/fieldstat.h +++ b/include/fieldstat/fieldstat.h @@ -26,15 +26,15 @@ enum metric_type enum field_type { - TAG_INTEGER, // TODO: rename - TAG_DOUBLE, - TAG_CSTRING, + FIELD_VALUE_INTEGER, + FIELD_VALUE_DOUBLE, + FIELD_VALUE_CSTRING, }; enum sampling_mode { SAMPLING_MODE_COMPREHENSIVE, SAMPLING_MODE_TOPK, - SAMPLING_MODE_SPREADSKETCH, // TODO: rename TOP_CARDINALITY // todo: 问问gpt cardinality,unique.... + SAMPLING_MODE_TOP_CARDINALITY, }; struct field { @@ -106,7 +106,7 @@ int fieldstat_register_hll(struct fieldstat *instance, int cube_id, const char * * @param significant_figures: the precision of the histogram. Must be in [1, 5]. * @return metric id if success. If failed, return FS_ERR_NULL_HANDLER, FS_ERR_INVALID_KEY(when metric_name is not unique in this cube), or FS_ERR_INVALID_PARAM(if any of the 3 params are out of range) */ -int fieldstat_register_hist(struct fieldstat *instance, int cube_id, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures); +int fieldstat_register_histogram(struct fieldstat *instance, int cube_id, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures); /* * @brief let the value of counter metric of cell_id increase by `increment`. @@ -146,7 +146,7 @@ int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail. * FS_ERR_INVALID_PARAM when value is less than 0, or the cube is topk. */ -int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value); // todo: 重命名,hist,不管符号冲突问题了 +int fieldstat_histogram_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value); /* * @brief Delete all the cells, also the content of every metrics. The cube and metrics are not deleted. Increase cell_version by 1. @@ -178,7 +178,7 @@ struct field_list void fieldstat_get_cubes(const struct fieldstat *instance, int **cube_ids, int *n_cube); /* - * @brief Get all the registered metrics by fieldstat_register_counter, fieldstat_register_hll, fieldstat_register_hist. + * @brief Get all the registered metrics by fieldstat_register_counter, fieldstat_register_hll, fieldstat_register_histogram. */ void fieldstat_cube_get_metrics(const struct fieldstat *instance, int cube_id, int **metric_id_out, size_t *n_metric); @@ -191,7 +191,7 @@ const char *fieldstat_get_metric_name(const struct fieldstat *instance, int cube enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int cube_id, int metric_id); /* - get the cell_dimensions added to cube when calling fieldstat_counter_incrby, fieldstat_counter_set, fieldstat_hll_add, fieldstat_hist_record. + get the cell_dimensions added to cube when calling fieldstat_counter_incrby, fieldstat_counter_set, fieldstat_hll_add, fieldstat_histogram_record. */ void fieldstat_cube_get_cells(const struct fieldstat *instance, int cube_id, struct field_list **cell_dimensions, size_t *n_cell); @@ -226,8 +226,8 @@ int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, const s @return >= 0 if success. FS_ERR_INVALID_PARAM if precision is invalid. */ int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double *value); -long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double percentile); -long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long value); +long long fieldstat_histogram_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double percentile); +long long fieldstat_histogram_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long value); // get the base 64 encoded string of the serialized blob of a cell void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct field_list *cell_dimensions, char **blob, size_t *blob_size); diff --git a/readme_fieldstat.md b/readme_fieldstat.md index cc17426..42c6680 100644 --- a/readme_fieldstat.md +++ b/readme_fieldstat.md @@ -42,7 +42,7 @@ Download fieldstat4 rpm from https://repo.geedge.net/pulp/content/ and install r struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, YOUR_SHARED_TAG, YOUR_SHARED_TAG_LENGTH, SAMPLING_MODE_TOPK, MAX_CELL_NUMBER); int metric_counter_id = fieldstat_register_counter(instance, cube_id, "any metric name", 0/1); -int metric_histogram_id = fieldstat_register_histogram(instance, cube_id, "any metric name", THE_MINIMUM_NUMBER_TO_RECORD, THE_MAXIMUM_NUMBER_TO_RECORD, PRECISION); +int metric_histogram_id = fieldstat_register_histogramogram(instance, cube_id, "any metric name", THE_MINIMUM_NUMBER_TO_RECORD, THE_MAXIMUM_NUMBER_TO_RECORD, PRECISION); int metric_hll_id = fieldstat_register_hll(instance, cube_id, "any metric name", PRECISION); int cell_id = fieldstat_cube_add(instance, cube_id, YOUR_TAG, YOUR_TAG_LENGTH, THE_PRIMARY_METRIC); if (cell_id != -1) { diff --git a/readme_fieldstat_easy.md b/readme_fieldstat_easy.md index 14f0927..c6f39cd 100644 --- a/readme_fieldstat_easy.md +++ b/readme_fieldstat_easy.md @@ -172,7 +172,7 @@ const int N_THREADS = 3; struct field global_tags[1]; struct field tmptag; tmptag.key = "app id"; -tmptag.type = TAG_INTEGER; +tmptag.type = FIELD_VALUE_INTEGER; tmptag.value_longlong = 1; global_tags[0] = tmptag; diff --git a/src/tags/tag_map.c b/src/cells/hash_table.c index 6dad5e1..8394565 100644 --- a/src/tags/tag_map.c +++ b/src/cells/hash_table.c @@ -1,4 +1,4 @@ -#include "tag_map.h" +#include "hash_table.h" #include <stdio.h> #include <assert.h> diff --git a/src/tags/tag_map.h b/src/cells/hash_table.h index 59fc8e8..59fc8e8 100644 --- a/src/tags/tag_map.h +++ b/src/cells/hash_table.h diff --git a/src/tags/heavy_keeper.c b/src/cells/heavy_keeper.c index c257e1d..b606a67 100644 --- a/src/tags/heavy_keeper.c +++ b/src/cells/heavy_keeper.c @@ -583,7 +583,7 @@ int heavy_keeper_add(struct heavy_keeper *heavy_keeper, const char *key, size_t struct sorted_set *summary = heavy_keeper->top_K_heap; - long long old_cnt = sorted_set_get_score(summary, key, key_len); // todo: 改成 score + long long old_cnt = sorted_set_get_score(summary, key, key_len); bool not_in_sorted_set = (old_cnt == NOT_FIND); long long maxv = 0; uint64_t fp = cal_hash_val_with_seed(key, key_len, FP_HASH_KEY); diff --git a/src/tags/heavy_keeper.h b/src/cells/heavy_keeper.h index 3b09598..3b09598 100644 --- a/src/tags/heavy_keeper.h +++ b/src/cells/heavy_keeper.h diff --git a/src/tags/spread_sketch.c b/src/cells/spread_sketch.c index 0d39d16..e79815b 100644 --- a/src/tags/spread_sketch.c +++ b/src/cells/spread_sketch.c @@ -52,6 +52,7 @@ struct spread_sketch { uint32_t *min_level_per_row; // TODO: 先看看性能吧, 之后再写。用来记录每行最小的level,从而跳过行数。对于64位的level,维持一个计数,额外使用64 r的空间,当一个最小位数的level 计数到0时,更新最小level。 // TODO: 对比heavy keeper,不仅仅是跳过的问题,heavykeeper 无论什么情况,在输入0的时候都不会走sketch 更新。 + // 或者简单记录用掉的bucket 数量也挺好。 }; static void *default_new_fn(void *arg) { diff --git a/src/tags/spread_sketch.h b/src/cells/spread_sketch.h index 9717238..9717238 100644 --- a/src/tags/spread_sketch.h +++ b/src/cells/spread_sketch.h @@ -13,7 +13,7 @@ #include "metric_manifest.h" #include "metric.h" #include "heavy_keeper.h" -#include "tag_map.h" +#include "hash_table.h" #include "spread_sketch.h" #define DEFAULT_N_METRIC 32 @@ -42,8 +42,8 @@ struct cell { struct cube { enum sampling_mode sampling_mode; union { - struct heavy_keeper *heavykeeper; // todo: 这两个改了 - struct hash_table *table; // todo: + struct heavy_keeper *heavykeeper; + struct hash_table *table; struct spread_sketch *spread_sketch; }; size_t max_n_cell; @@ -54,7 +54,7 @@ struct cube { int primary_metric_id; char *serialized_dimensions; // the key of cube is serialized cube dimensions - size_t serialized_dimensions_len; // todo: 重命名 + size_t serialized_dimensions_len; int id; UT_hash_handle hh; }; @@ -68,13 +68,13 @@ static struct field *field_array_duplicate(const struct field *fields_src, size_ ret[i].type = fields_src[i].type; switch (fields_src[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: ret[i].value_longlong = fields_src[i].value_longlong; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: ret[i].value_str = strdup(fields_src[i].value_str); break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: ret[i].value_double = fields_src[i].value_double; break; default: @@ -90,7 +90,7 @@ static void fieldstat_free_tag_array(struct field *fields, size_t n_tags) for (size_t i = 0; i < n_tags; i++) { struct field *field = &fields[i]; free((char *)field->key); - if (field->type == TAG_CSTRING) { + if (field->type == FIELD_VALUE_CSTRING) { free((char *)field->value_str); } } @@ -164,16 +164,16 @@ static int field_array_to_key_safe(const struct field fields[], size_t n_tags, c key_len = strlen(field->key); switch(field->type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: val_len = sizeof(long long); val_position = (void *)&field->value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: val_len = sizeof(double); val_position = (void *)&field->value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: val_len = strlen(field->value_str); val_position = (void *)field->value_str; break; @@ -221,16 +221,16 @@ static void field_array_to_key_endeavor(const struct field fields[], size_t n_ta key_len = strlen(field->key); switch(field->type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: val_len = sizeof(long long); val_position = (void *)&field->value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: val_len = sizeof(double); val_position = (void *)&field->value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: val_len = strlen(field->value_str); val_position = (void *)field->value_str; break; @@ -484,7 +484,7 @@ void cell_free(struct cell *pthis) { free(pthis->slots); for (size_t i = 0; i < pthis->cell_dimensions.n_field; i++) { free((char *)pthis->cell_dimensions.field[i].key); - if (pthis->cell_dimensions.field[i].type == TAG_CSTRING) { + if (pthis->cell_dimensions.field[i].type == FIELD_VALUE_CSTRING) { free((char *)pthis->cell_dimensions.field[i].value_str); } } @@ -592,7 +592,7 @@ struct cube *cube_new(const struct field *dimensions, size_t n_dimensions, enum cube->table = hash_table_new(max_n_cell); hash_table_set_exdata_schema(cube->table, exdata_new_i, exdata_free_i, exdata_merge_i, exdata_reset_i, exdata_copy_i); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: cube->spread_sketch = spread_sketch_new(max_n_cell); spread_sketch_set_exdata_schema(cube->spread_sketch, exdata_new_i, exdata_free_i, exdata_merge_i, exdata_reset_i, exdata_copy_i); break; @@ -613,7 +613,7 @@ void cube_free(struct cube *cube) { case SAMPLING_MODE_COMPREHENSIVE: hash_table_free(cube->table); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: spread_sketch_free(cube->spread_sketch); break; default: @@ -642,7 +642,7 @@ void cube_reset(struct cube *cube) { case SAMPLING_MODE_COMPREHENSIVE: hash_table_reset(cube->table); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: spread_sketch_reset(cube->spread_sketch); break; default: @@ -658,7 +658,7 @@ int cube_set_primary_metric(struct cube *cube, int metric_id) { } if (cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->sampling_mode == SAMPLING_MODE_TOPK && manifest->type != METRIC_TYPE_COUNTER) || - (cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH && manifest->type != METRIC_TYPE_HLL)) { + (cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY && manifest->type != METRIC_TYPE_HLL)) { return FS_ERR_INVALID_PARAM; } cube->primary_metric_id = metric_id; @@ -761,9 +761,8 @@ struct cell *get_cell_in_spread_sketch_cube(struct cube *cube, const struct fiel args.n_dimensions = n_dimension; struct cell *cell_data = NULL; - assert(cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH); + assert(cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY); - // todo: spread sketch 现在支持dummy 的方式是让他们也走sketch,可以用“满行”来减少这种计算,但确实加入level 低的内容,会走相同的流程,不像heavy keeper 一样就简单的查哈希表。 if (cube->primary_metric_id != metric_id) { cell_data = spread_sketch_get0_exdata(cube->spread_sketch, key, key_len); if (cell_data == NULL) { @@ -894,7 +893,7 @@ int cube_histogram_record(struct cube *cube, int metric_id, const struct field * case SAMPLING_MODE_TOPK: { cell_data = get_cell_in_topk_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} - case SAMPLING_MODE_SPREADSKETCH: { + case SAMPLING_MODE_TOP_CARDINALITY: { cell_data = get_cell_in_spread_sketch_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} default: @@ -923,7 +922,7 @@ int cube_hll_add(struct cube *cube, int metric_id, const struct field *dimension } uint64_t hash = 0; // just any value, if we do not need to update the primary metric of spread sketch cube, hash value is not used - if (cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH && cube->primary_metric_id == metric_id) { + if (cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY && cube->primary_metric_id == metric_id) { hash = XXH3_64bits(key, key_len); } struct cell *cell_data = NULL; @@ -934,7 +933,7 @@ int cube_hll_add(struct cube *cube, int metric_id, const struct field *dimension case SAMPLING_MODE_TOPK: { cell_data = get_cell_in_topk_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} - case SAMPLING_MODE_SPREADSKETCH: { + case SAMPLING_MODE_TOP_CARDINALITY: { cell_data = get_cell_in_spread_sketch_cube(cube, dimensions, n_dimensions, hash, metric_id); break;} default: @@ -956,7 +955,7 @@ uint64_t field_array_to_hash(const struct field *field, size_t n_dimensions) { for (int i = 0; i < n_dimensions; i++) { XXH3_64bits_update(&state, field[i].key, strlen(field[i].key)); - if (field[i].type != TAG_CSTRING) { + if (field[i].type != FIELD_VALUE_CSTRING) { XXH3_64bits_update(&state, &field[i].value_longlong, sizeof(long long)); } else { XXH3_64bits_update(&state, field[i].value_str, strlen(field[i].value_str)); @@ -975,7 +974,7 @@ int cube_hll_add_field(struct cube *cube, int metric_id, const struct field *dim } uint64_t hash = 0; // just any value, if we do not need to update the primary metric of spread sketch cube, hash value is not used - if (cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH && cube->primary_metric_id == metric_id) { + if (cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY && cube->primary_metric_id == metric_id) { hash = field_array_to_hash(tags_key, n_tag_key); } struct cell *cell_data = NULL; @@ -986,7 +985,7 @@ int cube_hll_add_field(struct cube *cube, int metric_id, const struct field *dim case SAMPLING_MODE_TOPK: { cell_data = get_cell_in_topk_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} - case SAMPLING_MODE_SPREADSKETCH: { + case SAMPLING_MODE_TOP_CARDINALITY: { cell_data = get_cell_in_spread_sketch_cube(cube, dimensions, n_dimensions, hash, metric_id); break;} default: @@ -1008,7 +1007,7 @@ int cube_hll_add_field(struct cube *cube, int metric_id, const struct field *dim int cube_counter_incrby(struct cube *cube, int metric_id, const struct field *dimensions, size_t n_dimensions, long long increment) { assert(cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->sampling_mode == SAMPLING_MODE_TOPK && (cube->primary_metric_id != metric_id || increment >= 0)) || - (cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH && cube->primary_metric_id != metric_id) + (cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY && cube->primary_metric_id != metric_id) ); const struct metric_manifest *manifest = metric_manifest_manager_get_by_id(cube->manifest_manager, metric_id); @@ -1024,7 +1023,7 @@ int cube_counter_incrby(struct cube *cube, int metric_id, const struct field *di case SAMPLING_MODE_TOPK: { cell_data = get_cell_in_topk_cube(cube, dimensions, n_dimensions, increment, metric_id); break;} - case SAMPLING_MODE_SPREADSKETCH: { + case SAMPLING_MODE_TOP_CARDINALITY: { cell_data = get_cell_in_spread_sketch_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} default: @@ -1058,7 +1057,7 @@ int cube_counter_set(struct cube *cube, int metric_id, const struct field *dimen case SAMPLING_MODE_TOPK: { cell_data = get_cell_in_topk_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} - case SAMPLING_MODE_SPREADSKETCH: { + case SAMPLING_MODE_TOP_CARDINALITY: { cell_data = get_cell_in_spread_sketch_cube(cube, dimensions, n_dimensions, 0, metric_id); break;} default: @@ -1087,7 +1086,7 @@ struct cube *cube_copy(const struct cube *cube) case SAMPLING_MODE_COMPREHENSIVE: cube_dup->table = hash_table_copy(cube->table); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: cube_dup->spread_sketch = spread_sketch_copy(cube->spread_sketch); break; default: @@ -1131,7 +1130,7 @@ int cube_merge(struct cube *dest, const struct cube *src) case SAMPLING_MODE_COMPREHENSIVE: hash_table_merge(dest->table, src->table); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: spread_sketch_merge(dest->spread_sketch, src->spread_sketch); break; default: @@ -1156,7 +1155,7 @@ struct cube *cube_fork(const struct cube *cube) { ret->table = hash_table_new(cube->max_n_cell); hash_table_set_exdata_schema(ret->table, exdata_new_i, exdata_free_i, exdata_merge_i, exdata_reset_i, exdata_copy_i); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: ret->spread_sketch = spread_sketch_new(cube->max_n_cell); spread_sketch_set_exdata_schema(ret->spread_sketch, exdata_new_i, exdata_free_i, exdata_merge_i, exdata_reset_i, exdata_copy_i); break; @@ -1196,7 +1195,7 @@ void cube_get_cells(const struct cube *cube, struct field_list **cell_dimensions case SAMPLING_MODE_TOPK: n_cell_tmp = heavy_keeper_get_count(cube->heavykeeper); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: n_cell_tmp = spread_sketch_get_count(cube->spread_sketch); break; default: @@ -1217,7 +1216,7 @@ void cube_get_cells(const struct cube *cube, struct field_list **cell_dimensions case SAMPLING_MODE_TOPK: heavy_keeper_list(cube->heavykeeper, (void **)cell_datas, n_cell_tmp); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: spread_sketch_list(cube->spread_sketch, (void **)cell_datas, n_cell_tmp); break; default: @@ -1225,7 +1224,7 @@ void cube_get_cells(const struct cube *cube, struct field_list **cell_dimensions } // spread sketch often stores more than max_n_cell. So sort out the top max_n_cell cells. - if (cube->sampling_mode == SAMPLING_MODE_SPREADSKETCH && n_cell_tmp > cube->max_n_cell) { + if (cube->sampling_mode == SAMPLING_MODE_TOP_CARDINALITY && n_cell_tmp > cube->max_n_cell) { struct tmp_sorted_data_spread_sketch_cell *tmp_sorted_data = (struct tmp_sorted_data_spread_sketch_cell *)malloc(sizeof(struct tmp_sorted_data_spread_sketch_cell) * n_cell_tmp); for (int i = 0; i < n_cell_tmp; i++) { tmp_sorted_data[i].data = cell_datas[i]; @@ -1274,7 +1273,7 @@ const struct cell *get_cell_by_tag_list(const struct cube *cube, const struct fi case SAMPLING_MODE_COMPREHENSIVE: ret = hash_table_get0_exdata(cube->table, tag_in_string, tag_len); break; - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: ret = spread_sketch_get0_exdata(cube->spread_sketch, tag_in_string, tag_len); break; default: @@ -1383,7 +1382,7 @@ int cube_get_cell_count(const struct cube *cube) { return hash_table_get_count(cube->table); case SAMPLING_MODE_TOPK: return heavy_keeper_get_count(cube->heavykeeper); - case SAMPLING_MODE_SPREADSKETCH: + case SAMPLING_MODE_TOP_CARDINALITY: return spread_sketch_get_count(cube->spread_sketch); default: assert(0); diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index 3fecf40..bbe6fd3 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -116,7 +116,7 @@ struct couple_export_table { void kv_pair_free(struct export_kv_pair *pair) { - if (pair->type == TAG_CSTRING) { + if (pair->type == FIELD_VALUE_CSTRING) { free((char *)pair->value_str); } free((char *)pair->key); @@ -128,13 +128,13 @@ void kv_pair_fill_with_tags(struct export_kv_pair *dest, const struct field *src dest->key = strdup(src->key); dest->type = src->type; switch (src->type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: dest->value_longlong = src->value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: dest->value_double = src->value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: dest->value_str = strdup(src->value_str); break; default: @@ -229,17 +229,17 @@ bool fieldstat_tag_list_cmp(const struct field_list *a, const struct field_list } switch (a->field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: if (a->field[i].value_longlong != b->field[i].value_longlong) { return false; } break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: if (a->field[i].value_double != b->field[i].value_double) { return false; } break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: if (strcmp(a->field[i].value_str, b->field[i].value_str) != 0) { return false; } @@ -262,13 +262,13 @@ struct field_list *my_copy_fs_tag_list(const struct field_list *src) dest->field[i].type = src->field[i].type; switch (src->field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: dest->field[i].value_longlong = src->field[i].value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: dest->field[i].value_double = src->field[i].value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: dest->field[i].value_str = strdup(src->field[i].value_str); break; default: @@ -342,7 +342,7 @@ void write_delta_to_json(struct fieldstat_json_exporter *exporter, struct cellwi tag_json = "\a\t\a"; // just a dummy string } for (int j = 0; j < tag_field_pair->n_metric; j++) { - if (tag_field_pair->metric_pairs[j]->type != TAG_INTEGER) { // only counter type need to write delta + if (tag_field_pair->metric_pairs[j]->type != FIELD_VALUE_INTEGER) { // only counter type need to write delta continue; } const char *metric_name = tag_field_pair->metric_pairs[j]->key; @@ -535,7 +535,7 @@ struct export_kv_pair *cell_query_with_iter(const struct cell_iter *iter, int me } ret = malloc(sizeof(struct export_kv_pair)); ret->key = strdup(fieldstat_get_metric_name(iter->instance, cube_id, metric_id)); - ret->type = TAG_INTEGER; + ret->type = FIELD_VALUE_INTEGER; ret->value_longlong = value; return ret; } @@ -548,7 +548,7 @@ struct export_kv_pair *cell_query_with_iter(const struct cell_iter *iter, int me } ret = malloc(sizeof(struct export_kv_pair)); ret->key = strdup(fieldstat_get_metric_name(iter->instance, cube_id, metric_id)); - ret->type = TAG_CSTRING; + ret->type = FIELD_VALUE_CSTRING; ret->value_str = value; return ret; } @@ -560,13 +560,13 @@ void kv_pair_write_to_json(const struct export_kv_pair *pairs, struct json_write { switch (pairs->type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: json_writer_longlong_field(writer, pairs->key, pairs->value_longlong); break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: json_writer_double_field(writer, pairs->key, pairs->value_double); break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: json_writer_str_field(writer, pairs->key, pairs->value_str, strlen(pairs->value_str)); break; default: @@ -588,13 +588,13 @@ void tag_list_append_to_tag_object(const struct field_list *tag_list, struct jso pairs.type = tag_list->field[i].type; switch (pairs.type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: pairs.value_longlong = tag_list->field[i].value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: pairs.value_double = tag_list->field[i].value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: pairs.value_str = (char *)tag_list->field[i].value_str; break; default: @@ -627,7 +627,7 @@ void kv_pair_free_list(struct export_kv_pair *pairs, size_t len) { for (int i = 0; i < len; i++) { struct export_kv_pair *pair = &pairs[i]; - if (pair->type == TAG_CSTRING) { + if (pair->type == FIELD_VALUE_CSTRING) { free(pair->value_str); } free(pair->key); @@ -992,13 +992,13 @@ void fieldstat_json_exporter_set_global_tag(struct fieldstat_json_exporter *expo field->type = tag_list[i].type; switch (field->type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: field->value_longlong = tag_list[i].value_longlong; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: field->value_str = strdup(tag_list[i].value_str); break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: field->value_double = tag_list[i].value_double; break; diff --git a/src/exporter/fieldstat_exporter.py b/src/exporter/fieldstat_exporter.py index c9eb523..aad7969 100644 --- a/src/exporter/fieldstat_exporter.py +++ b/src/exporter/fieldstat_exporter.py @@ -25,11 +25,11 @@ class FieldstatAPI: libfieldstat.fieldstat_histogram_free.argtypes = [ctypes.c_void_p] - libfieldstat.fieldstat_histogram_value_at_percentile.argtypes = [ctypes.c_void_p, ctypes.c_double] - libfieldstat.fieldstat_histogram_value_at_percentile.restype = ctypes.c_longlong + libfieldstat.fieldstat_histogram_value_at_percentile_api.argtypes = [ctypes.c_void_p, ctypes.c_double] + libfieldstat.fieldstat_histogram_value_at_percentile_api.restype = ctypes.c_longlong - libfieldstat.fieldstat_histogram_count_le_value.argtypes = [ctypes.c_void_p, ctypes.c_longlong] - libfieldstat.fieldstat_histogram_count_le_value.restype = ctypes.c_longlong + libfieldstat.fieldstat_histogram_count_le_value_api.argtypes = [ctypes.c_void_p, ctypes.c_longlong] + libfieldstat.fieldstat_histogram_count_le_value_api.restype = ctypes.c_longlong libfieldstat.fieldstat_histogram_value_total_count.argtypes = [ctypes.c_void_p] libfieldstat.fieldstat_histogram_value_total_count.restype = ctypes.c_longlong @@ -134,7 +134,7 @@ class PrometheusExporter: metrics = "" for i in self.hist_bins: - value = FieldstatAPI.libfieldstat.fieldstat_histogram_count_le_value(c_hist, int(i)) + value = FieldstatAPI.libfieldstat.fieldstat_histogram_count_le_value_api(c_hist, int(i)) metric = name + "_bucket" + "{" + tags + ",le=\"{:.2f}\"".format(i) + "}" + ' ' + str(value) + '\n' metrics += metric self.n_lines += 1 @@ -144,7 +144,7 @@ class PrometheusExporter: def __build_summary_format(self, name, tags, c_hist): metrics = "" for i in self.hist_bins: - value = FieldstatAPI.libfieldstat.fieldstat_histogram_value_at_percentile(c_hist, float(i * 100)) + value = FieldstatAPI.libfieldstat.fieldstat_histogram_value_at_percentile_api(c_hist, float(i * 100)) metric = name + "{" + tags + ",quantile=\"{:.2f}%\"".format(i * 100) + "}" + ' ' + str(value) + '\n' metrics += metric self.n_lines += 1 @@ -365,10 +365,10 @@ class HistogramTable: row_values = [] for i in self.bins: if self.format == "summary": - value = FieldstatAPI.libfieldstat.fieldstat_histogram_value_at_percentile(c_hist, float(i * 100)) + value = FieldstatAPI.libfieldstat.fieldstat_histogram_value_at_percentile_api(c_hist, float(i * 100)) row_values.append(str(value)) if self.format == "histogram": - value = FieldstatAPI.libfieldstat.fieldstat_histogram_count_le_value(c_hist, int(i)) + value = FieldstatAPI.libfieldstat.fieldstat_histogram_count_le_value_api(c_hist, int(i)) row_values.append(str(value)) shared_values = self.__get_row_shared_values(c_hist) row_values += shared_values diff --git a/src/fieldstat.c b/src/fieldstat.c index 0e2fb81..12c482b 100644 --- a/src/fieldstat.c +++ b/src/fieldstat.c @@ -69,7 +69,7 @@ void fieldstat_free_tag_array(struct field *fields, size_t n_tags) for (size_t i = 0; i < n_tags; i++) { struct field *field = &fields[i]; free((char *)field->key); - if (field->type == TAG_CSTRING) { + if (field->type == FIELD_VALUE_CSTRING) { free((char *)field->value_str); } } @@ -142,7 +142,7 @@ int fieldstat_register_hll(struct fieldstat *instance, int cube_id, const char * } // cppcheck-suppress [constParameterPointer, unmatchedSuppression] -int fieldstat_register_hist(struct fieldstat *instance, int cube_id, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) +int fieldstat_register_histogram(struct fieldstat *instance, int cube_id, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) { struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id); if (cube == NULL) { @@ -200,7 +200,7 @@ int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_ } // cppcheck-suppress [constParameterPointer, unmatchedSuppression] -int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value) +int fieldstat_histogram_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value) { struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id); if (cube == NULL) { @@ -277,7 +277,7 @@ int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, const struc return ret; } -long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double percentile) +long long fieldstat_histogram_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, double percentile) { const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id); if (cube == NULL) { @@ -292,7 +292,7 @@ long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, i return value; } -long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long value) +long long fieldstat_histogram_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *cell_dimensions, int metric_id, long long value) { const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id); if (cube == NULL) { diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c index ef1a921..00a569a 100644 --- a/src/fieldstat_easy.c +++ b/src/fieldstat_easy.c @@ -218,17 +218,17 @@ int fieldstat_easy_register_histogram(struct fieldstat_easy *fse, const char *na pthread_spin_lock(&fse->fsu[i].lock); } - int ret = fieldstat_register_hist(fse->fsu[0].active, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); // try to register + int ret = fieldstat_register_histogram(fse->fsu[0].active, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); // try to register if (ret < 0) { for (int i = 0; i < fse->max_thread_num; i++) { pthread_spin_unlock(&fse->fsu[i].lock); } return ret; } - fieldstat_register_hist(fse->fsu[0].read_only, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); + fieldstat_register_histogram(fse->fsu[0].read_only, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); for (int i = 1; i < fse->max_thread_num; i++) { - fieldstat_register_hist(fse->fsu[i].active, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); - fieldstat_register_hist(fse->fsu[i].read_only, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); + fieldstat_register_histogram(fse->fsu[i].active, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); + fieldstat_register_histogram(fse->fsu[i].read_only, 0, name, lowest_trackable_value, highest_trackable_value, significant_figures); } for (int i = 0; i < fse->max_thread_num; i++) { @@ -354,7 +354,7 @@ int fieldstat_easy_histogram_record(struct fieldstat_easy *fse, int thread_id, i } pthread_spin_lock(&fse->fsu[thread_id].lock); - int ret = fieldstat_hist_record(fse->fsu[thread_id].active, 0, metric_id, dimensions, n_dimensions, value); + int ret = fieldstat_histogram_record(fse->fsu[thread_id].active, 0, metric_id, dimensions, n_dimensions, value); pthread_spin_unlock(&fse->fsu[thread_id].lock); return ret; diff --git a/src/metrics/python_api.c b/src/metrics/python_api.c index 8388a1c..6f25fdf 100644 --- a/src/metrics/python_api.c +++ b/src/metrics/python_api.c @@ -16,12 +16,12 @@ void *fieldstat_histogram_base64_decode(char *buf) return hdr; } -long long fieldstat_histogram_value_at_percentile(void* h, double percentile) +long long fieldstat_histogram_value_at_percentile_api(void* h, double percentile) { return hdr_value_at_percentile((const struct hdr_histogram *)h, percentile); } -long long fieldstat_histogram_count_le_value(void* h, long long value) +long long fieldstat_histogram_count_le_value_api(void* h, long long value) { return hdr_count_le_value((const struct hdr_histogram *)h, value); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ced6420..a6c1403 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(DEBUG_FLAGS "-O3") include_directories(${PROJECT_SOURCE_DIR}/test)
include_directories(${PROJECT_SOURCE_DIR}/test/deps)
include_directories(${PROJECT_SOURCE_DIR}/src)
-include_directories(${PROJECT_SOURCE_DIR}/src/tags)
+include_directories(${PROJECT_SOURCE_DIR}/src/cells)
include_directories(${PROJECT_SOURCE_DIR}/src/metrics)
include_directories(${PROJECT_SOURCE_DIR}/include/fieldstat)
diff --git a/test/profiling/CMakeLists.txt b/test/profiling/CMakeLists.txt index 5c8e99c..f06242f 100644 --- a/test/profiling/CMakeLists.txt +++ b/test/profiling/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src/utils) file(GLOB SRC
"${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/metrics/*.c"
- "${PROJECT_SOURCE_DIR}/src/tags/*.c"
+ "${PROJECT_SOURCE_DIR}/src/cells/*.c"
"${PROJECT_SOURCE_DIR}/src/exporter/*.c"
"${PROJECT_SOURCE_DIR}/src/utils/*.c"
"${PROJECT_SOURCE_DIR}/vendors/cjson/*.c"
diff --git a/test/profiling/main.c b/test/profiling/main.c index 5838f20..3af2b1a 100644 --- a/test/profiling/main.c +++ b/test/profiling/main.c @@ -11,23 +11,23 @@ // #define ADD_OPER_NUM 1 #define MAX_STRING_KEY_LEN 10 -const struct field TEST_TAG_INT = {"INT key_", TAG_INTEGER, {.value_longlong = 100}}; +const struct field TEST_TAG_INT = {"INT key_", FIELD_VALUE_INTEGER, {.value_longlong = 100}}; int main () { printf("Start profiling...\n"); clock_t start, end; // struct field TAG[4] = { - // {"INT key_", TAG_INTEGER, {.value_longlong = 100}}, - // {"STRING key_", TAG_CSTRING, {.value_str = "10012312312312"}}, - // {"STRING key_", TAG_CSTRING, {.value_str = "100adsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}}, - // {"FLOAT key_", TAG_INTEGER, {.value_double = 100.0}}, + // {"INT key_", FIELD_VALUE_INTEGER, {.value_longlong = 100}}, + // {"STRING key_", FIELD_VALUE_CSTRING, {.value_str = "10012312312312"}}, + // {"STRING key_", FIELD_VALUE_CSTRING, {.value_str = "100adsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}}, + // {"FLOAT key_", FIELD_VALUE_INTEGER, {.value_double = 100.0}}, // }; struct field TAG[4] = { - {"object_id", TAG_INTEGER, {.value_longlong = 20}}, - {"item_id", TAG_INTEGER, {.value_longlong = 16916397}}, - {"chart_id", TAG_INTEGER, {.value_longlong = 1}}, - {"version", TAG_INTEGER, {.value_longlong = 1}}, + {"object_id", FIELD_VALUE_INTEGER, {.value_longlong = 20}}, + {"item_id", FIELD_VALUE_INTEGER, {.value_longlong = 16916397}}, + {"chart_id", FIELD_VALUE_INTEGER, {.value_longlong = 1}}, + {"version", FIELD_VALUE_INTEGER, {.value_longlong = 1}}, }; struct fieldstat *instance = fieldstat_new(); diff --git a/test/test_easy_fs.cpp b/test/test_easy_fs.cpp index e723828..790f0fd 100644 --- a/test/test_easy_fs.cpp +++ b/test/test_easy_fs.cpp @@ -123,7 +123,7 @@ TEST(test_easy_fieldstat, output_to_file) cJSON_Delete(root); // 4th interval: new data, output again - fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_TAG_DOUBLE, 1, 10086); + fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_FIELD_VALUE_DOUBLE, 1, 10086); sleep(2); printf("4th interval\n"); root = read_file(); @@ -183,7 +183,7 @@ TEST(test_easy_fieldstat, output_interval_ok) struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, NULL, 0); fieldstat_easy_register_histogram(fse, "metric histogram", 1, 10000, 3); // a pretty time consuming metric fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_INT, 1, 1); - fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_DOUBLE, 1, 10); + fieldstat_easy_histogram_record(fse, 0, 0, &TEST_FIELD_VALUE_DOUBLE, 1, 10); fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_STRING, 1, 110); fieldstat_easy_enable_auto_output(fse, FILENAME, 1); @@ -200,7 +200,7 @@ TEST(test_easy_fieldstat, ensure_data_racing_of_two_output_and_of_incyby) struct field global_tags[1]; struct field tmptag; tmptag.key = "app id"; - tmptag.type = TAG_INTEGER; + tmptag.type = FIELD_VALUE_INTEGER; tmptag.value_longlong = 1; global_tags[0] = tmptag; diff --git a/test/test_empty_tags.cpp b/test/test_empty_tags.cpp index 1d1484a..967f8c0 100644 --- a/test/test_empty_tags.cpp +++ b/test/test_empty_tags.cpp @@ -97,7 +97,7 @@ TEST(test_empty_tag, merge_topk) TEST(test_empty_tag, merge_spreadsketch) { struct fieldstat *instance_src = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance_src, NULL, 0, SAMPLING_MODE_SPREADSKETCH, 1); + int cube_id = fieldstat_create_cube(instance_src, NULL, 0, SAMPLING_MODE_TOP_CARDINALITY, 1); int metric_id = fieldstat_register_hll(instance_src, cube_id, "metric", 4); fieldstat_hll_add(instance_src, cube_id, metric_id, NULL, 0, "1", 1); struct fieldstat *instance_dst = fieldstat_new(); diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index 54ea3df..8e96e04 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -23,22 +23,22 @@ struct hdr_histogram *g_histogram_standard; #define TEST_TOPK_STANDARD_K 5 #define TEST_METRIC_NUM 2 -const struct field TEST_TAG_GLOBAL1 = {"test_tag_global 1", .type = TAG_INTEGER, {.value_longlong = 1}}; -const struct field TEST_TAG_GLOBAL2 = {"test_tag_global 2", .type = TAG_DOUBLE, {.value_double = 2.2}}; -const struct field TEST_TAG_GLOBAL3 = {"test_tag_global 3", .type = TAG_CSTRING, {.value_str = "string3"}}; +const struct field TEST_TAG_GLOBAL1 = {"test_tag_global 1", .type = FIELD_VALUE_INTEGER, {.value_longlong = 1}}; +const struct field TEST_TAG_GLOBAL2 = {"test_tag_global 2", .type = FIELD_VALUE_DOUBLE, {.value_double = 2.2}}; +const struct field TEST_TAG_GLOBAL3 = {"test_tag_global 3", .type = FIELD_VALUE_CSTRING, {.value_str = "string3"}}; const struct field TEST_TAG_GLOBAL[3] = {TEST_TAG_GLOBAL1, TEST_TAG_GLOBAL2, TEST_TAG_GLOBAL3}; -const struct field TEST_TAG_SHARED1_1 = {"test_tag_shared 1", .type = TAG_INTEGER, {.value_longlong = 3}}; -const struct field TEST_TAG_SHARED1_2 = {"test_tag_shared 2", .type = TAG_DOUBLE, {.value_double = 0.2}}; -const struct field TEST_TAG_SHARED1_3 = {"test_tag_shared 3", .type = TAG_CSTRING, {.value_str = "1string"}}; +const struct field TEST_TAG_SHARED1_1 = {"test_tag_shared 1", .type = FIELD_VALUE_INTEGER, {.value_longlong = 3}}; +const struct field TEST_TAG_SHARED1_2 = {"test_tag_shared 2", .type = FIELD_VALUE_DOUBLE, {.value_double = 0.2}}; +const struct field TEST_TAG_SHARED1_3 = {"test_tag_shared 3", .type = FIELD_VALUE_CSTRING, {.value_str = "1string"}}; const struct field TEST_TAG_SHARED1[3] = {TEST_TAG_SHARED1_1, TEST_TAG_SHARED1_2, TEST_TAG_SHARED1_3}; -const struct field TEST_TAG_SHARED2_1 = {"test_tag_shared 11", .type = TAG_INTEGER, {.value_longlong = 4}}; -const struct field TEST_TAG_SHARED2_2 = {"test_tag_shared 22", .type = TAG_DOUBLE, {.value_double = 0.3}}; -const struct field TEST_TAG_SHARED2_3 = {"test_tag_shared 33", .type = TAG_CSTRING, {.value_str = "2string"}}; +const struct field TEST_TAG_SHARED2_1 = {"test_tag_shared 11", .type = FIELD_VALUE_INTEGER, {.value_longlong = 4}}; +const struct field TEST_TAG_SHARED2_2 = {"test_tag_shared 22", .type = FIELD_VALUE_DOUBLE, {.value_double = 0.3}}; +const struct field TEST_TAG_SHARED2_3 = {"test_tag_shared 33", .type = FIELD_VALUE_CSTRING, {.value_str = "2string"}}; const struct field TEST_TAG_SHARED2[3] = {TEST_TAG_SHARED2_1, TEST_TAG_SHARED2_2, TEST_TAG_SHARED2_3}; -const struct field TEST_TAG_SHARED3_1 = {"test_tag_shared 3", .type = TAG_INTEGER, {.value_longlong = 5}}; +const struct field TEST_TAG_SHARED3_1 = {"test_tag_shared 3", .type = FIELD_VALUE_INTEGER, {.value_longlong = 5}}; const struct field TEST_TAG_SHARED3[1] = {TEST_TAG_SHARED3_1}; void test_check_if_tag_list_is_in_json(cJSON *tag_obj, const Fieldstat_tag_list_wrapper *benchmark) @@ -49,7 +49,7 @@ void test_check_if_tag_list_is_in_json(cJSON *tag_obj, const Fieldstat_tag_list_ if (tag_val->type == cJSON_String) { EXPECT_STREQ(tag_val->valuestring, benchmark->get_tag()[tag_id].value_str); } else { - if (benchmark->get_tag()[tag_id].type == TAG_INTEGER) { + if (benchmark->get_tag()[tag_id].type == FIELD_VALUE_INTEGER) { EXPECT_EQ(tag_val->valueint, benchmark->get_tag()[tag_id].value_longlong); } else { EXPECT_NEAR(tag_val->valuedouble, benchmark->get_tag()[tag_id].value_double, 0.0001); @@ -189,7 +189,7 @@ TEST(export_test, cjson_export_with_fixed_tag_and_many_metrics_on_one_cube_of_co int cube_id = fieldstat_create_cube(instance, TEST_TAG_SHARED1, 3, SAMPLING_MODE_COMPREHENSIVE, tag_list_num); int id_counter = fieldstat_register_counter(instance, cube_id, "counter"); int id_gauge = fieldstat_register_hll(instance, cube_id, "gauge", g_hll_standard->cfg.precision); - int id_histogram = fieldstat_register_hist(instance, cube_id, "histogram", + int id_histogram = fieldstat_register_histogram(instance, cube_id, "histogram", g_histogram_standard->lowest_discernible_value, g_histogram_standard->highest_trackable_value, g_histogram_standard->significant_figures); Fieldstat_tag_list_wrapper *fields[tag_list_num]; @@ -202,7 +202,7 @@ TEST(export_test, cjson_export_with_fixed_tag_and_many_metrics_on_one_cube_of_co fieldstat_counter_incrby(instance, cube_id, id_counter, tag_tmp, tag_count, 1); for (size_t i = 0; i < OPER_NUM; i++){ fieldstat_hll_add(instance, cube_id, id_gauge, tag_tmp, tag_count, g_hll_standard_oper[i].c_str(), g_hll_standard_oper[i].length()); - fieldstat_hist_record(instance, cube_id, id_histogram, tag_tmp, tag_count, g_histogram_standard_oper[i]); + fieldstat_histogram_record(instance, cube_id, id_histogram, tag_tmp, tag_count, g_histogram_standard_oper[i]); } } @@ -289,7 +289,7 @@ extern "C" { TEST(export_test, cjson_export_on_one_cube_of_spreadsketch_sampling) { int K = 10; struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, K); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, K); int metric_id = fieldstat_register_hll(instance, cube_id, "metric", 7); int metric_count = fieldstat_register_counter(instance, cube_id, "oper cnt"); SpreadSketchZipfGenerator flow_generator(1.0, K * 10); @@ -349,7 +349,7 @@ TEST(export_test, only_registered_but_not_added_export_null_with_global_tag) int cube_id = fieldstat_create_cube(instance, TEST_TAG_SHARED1, 3, SAMPLING_MODE_COMPREHENSIVE, 3); fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_register_hll(instance, cube_id, "gauge", g_hll_standard->cfg.precision); - fieldstat_register_hist(instance, cube_id, "histogram", + fieldstat_register_histogram(instance, cube_id, "histogram", g_histogram_standard->lowest_discernible_value, g_histogram_standard->highest_trackable_value, g_histogram_standard->significant_figures); // add global field @@ -367,7 +367,7 @@ TEST(export_test, skip_two_empty_cube_and_export_last_one_with_global_tag) int cube_id_3 = fieldstat_create_cube(instance, TEST_TAG_SHARED3, 1, SAMPLING_MODE_COMPREHENSIVE, 3); (void)fieldstat_register_counter(instance, cube_id_3, "counter"); (void)fieldstat_register_hll(instance, cube_id_3, "gauge", g_hll_standard->cfg.precision); - int id_histogram = fieldstat_register_hist(instance, cube_id_3, "histogram", + int id_histogram = fieldstat_register_histogram(instance, cube_id_3, "histogram", g_histogram_standard->lowest_discernible_value, g_histogram_standard->highest_trackable_value, g_histogram_standard->significant_figures); const int tag_num = 1; @@ -375,7 +375,7 @@ TEST(export_test, skip_two_empty_cube_and_export_last_one_with_global_tag) fill_random_tag(fields, tag_num); const Fieldstat_tag_list_wrapper *the_tag = fields[0]; for (size_t i = 0; i < OPER_NUM; i++){ - fieldstat_hist_record(instance, cube_id_3, id_histogram, the_tag->get_tag(), the_tag->get_tag_count(), g_histogram_standard_oper[i]); + fieldstat_histogram_record(instance, cube_id_3, id_histogram, the_tag->get_tag(), the_tag->get_tag_count(), g_histogram_standard_oper[i]); } // export test @@ -530,10 +530,10 @@ TEST(export_test, enable_delta_and_export_twice_with_new_metric_and_omit_histogr struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, TEST_TAG_SHARED1, 3, SAMPLING_MODE_COMPREHENSIVE, 10); int id_counter = fieldstat_register_counter(instance, cube_id, "counter"); - int id_histogram = fieldstat_register_hist(instance, cube_id, "histogram", + int id_histogram = fieldstat_register_histogram(instance, cube_id, "histogram", g_histogram_standard->lowest_discernible_value, g_histogram_standard->highest_trackable_value, g_histogram_standard->significant_figures); fieldstat_counter_incrby(instance, cube_id, id_counter, &TEST_TAG_INT, 1, 1); - fieldstat_hist_record(instance, cube_id, id_histogram, &TEST_TAG_INT, 1, 123); + fieldstat_histogram_record(instance, cube_id, id_histogram, &TEST_TAG_INT, 1, 123); // export test struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); @@ -612,10 +612,10 @@ TEST(export_test, enable_delta_and_export_three_times_skipping_cube_with_no_coun struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, TEST_TAG_SHARED1, 3, SAMPLING_MODE_COMPREHENSIVE, 10); int id_counter = fieldstat_register_counter(instance, cube_id, "counter"); - int id_histogram = fieldstat_register_hist(instance, cube_id, "histogram", + int id_histogram = fieldstat_register_histogram(instance, cube_id, "histogram", g_histogram_standard->lowest_discernible_value, g_histogram_standard->highest_trackable_value, g_histogram_standard->significant_figures); fieldstat_counter_incrby(instance, cube_id, id_counter, &TEST_TAG_INT, 1, 1); - fieldstat_hist_record(instance, cube_id, id_histogram, &TEST_TAG_STRING, 1, 123); + fieldstat_histogram_record(instance, cube_id, id_histogram, &TEST_TAG_STRING, 1, 123); /* -------------------------- export test, 1st time ------------------------- */ struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); @@ -671,7 +671,7 @@ TEST(export_test, enable_delta_and_export_three_times_skipping_cube_with_no_coun /* -------------------------------- 3rd time -------------------------------- */ // add some new recs fieldstat_counter_incrby(instance, cube_id, id_counter, &TEST_TAG_INT, 1, 10); - fieldstat_hist_record(instance, cube_id, id_histogram, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, cube_id, id_histogram, &TEST_TAG_STRING, 1, 1234); json_string = fieldstat_json_exporter_export(fieldstat_json_exporter, instance, &TEST_TIMEVAL); root_arr = cJSON_Parse(json_string); free(json_string); @@ -727,7 +727,7 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t int cube_id2 = fieldstat_create_cube(instance, TEST_TAG_SHARED3, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int id_counter2 = fieldstat_register_counter(instance, cube_id2, "counter"); fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_TAG_INT, 1, 21); - fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_TAG_DOUBLE, 1, 22); + fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_FIELD_VALUE_DOUBLE, 1, 22); // export test struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); @@ -757,14 +757,14 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 21, 21, root); /* ------------------------------ cube 1 cell 1 ----------------------------- */ root = cJSON_GetArrayItem(root_arr, 3); - tmp_tag_cell = (struct field_list){(struct field *)&TEST_TAG_DOUBLE, 1}; + tmp_tag_cell = (struct field_list){(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 22, 22, root); // new turn fieldstat_counter_incrby(instance, cube_id1, id_counter1, &TEST_TAG_INT, 1, 100); fieldstat_counter_incrby(instance, cube_id1, id_counter1, &TEST_TAG_STRING, 1, 200); fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_TAG_INT, 1, 300); - fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_TAG_DOUBLE, 1, 400); + fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_FIELD_VALUE_DOUBLE, 1, 400); cJSON_Delete(root_arr); @@ -793,7 +793,7 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 321, 300, root); /* ------------------------------ cube 1 cell 1 ----------------------------- */ root = cJSON_GetArrayItem(root_arr, 3); - tmp_tag_cell = (struct field_list){(struct field *)&TEST_TAG_DOUBLE, 1}; + tmp_tag_cell = (struct field_list){(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 422, 400, root); cJSON_Delete(root_arr); @@ -883,8 +883,8 @@ TEST(export_test, delta_with_two_instance_same_config) int cube_id = fieldstat_create_cube(instance, NULL, 0, SAMPLING_MODE_COMPREHENSIVE, 0); int id_counter = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, 0, id_counter, &TEST_TAG_INT, 1, 123); - int id_hist = fieldstat_register_hist(instance, cube_id, "histogram", 1, 1000, 3); - fieldstat_hist_record(instance, cube_id, id_hist, &TEST_TAG_INT, 1, 5); + int id_hist = fieldstat_register_histogram(instance, cube_id, "histogram", 1, 1000, 3); + fieldstat_histogram_record(instance, cube_id, id_hist, &TEST_TAG_INT, 1, 5); struct fieldstat *acc = fieldstat_new(); fieldstat_merge(acc, instance); @@ -923,8 +923,8 @@ TEST(export_test, delta_with_two_instance_one_empty) int cube_id = fieldstat_create_cube(instance, NULL, 0, SAMPLING_MODE_COMPREHENSIVE, 0); int id_counter = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, 0, id_counter, &TEST_TAG_INT, 1, 123); - int id_hist = fieldstat_register_hist(instance, cube_id, "histogram", 1, 1000, 3); - fieldstat_hist_record(instance, 0, id_hist, &TEST_TAG_INT, 1, 5); + int id_hist = fieldstat_register_histogram(instance, cube_id, "histogram", 1, 1000, 3); + fieldstat_histogram_record(instance, 0, id_hist, &TEST_TAG_INT, 1, 5); struct fieldstat *delta = fieldstat_fork(instance); @@ -964,7 +964,7 @@ TEST(export_test, delta_with_two_instance_different_cell) fieldstat_counter_incrby(instance, 0, id_counter, &TEST_TAG_INT, 1, 123); struct fieldstat *delta = fieldstat_fork(instance); - fieldstat_counter_incrby(delta, 0, id_counter, &TEST_TAG_DOUBLE, 1, 1); + fieldstat_counter_incrby(delta, 0, id_counter, &TEST_FIELD_VALUE_DOUBLE, 1, 1); fieldstat_merge(instance, delta); // export test diff --git a/test/test_fuzz_test.cpp b/test/test_fuzz_test.cpp index a97f416..3b91f68 100644 --- a/test/test_fuzz_test.cpp +++ b/test/test_fuzz_test.cpp @@ -347,7 +347,7 @@ TEST(Fuzz_test, many_instance_random_flow_unregister_calibrate_reset_fork_merge_ // init cube for (int i = 0; i < CUBE_NUM; i++) { shared_tags[i] = new Fieldstat_tag_list_wrapper("shared_tag", i); - int cube_id = fieldstat_create_cube(master, shared_tags[i]->get_tag(), shared_tags[i]->get_tag_count(), SAMPLING_MODE_SPREADSKETCH, CELL_MAX); + int cube_id = fieldstat_create_cube(master, shared_tags[i]->get_tag(), shared_tags[i]->get_tag_count(), SAMPLING_MODE_TOP_CARDINALITY, CELL_MAX); EXPECT_EQ(cube_id, i); fieldstat_register_hll(master, cube_id, "hll", 6); } @@ -379,7 +379,7 @@ TEST(Fuzz_test, many_instance_random_flow_unregister_calibrate_reset_fork_merge_ delete shared_tags[cube_id_to_change]; shared_tags[cube_id_to_change] = new_tag; fieldstat_destroy_cube(master, cube_id_to_change); - int cube_id_new = fieldstat_create_cube(master, new_tag->get_tag(), new_tag->get_tag_count(), SAMPLING_MODE_SPREADSKETCH, CELL_MAX); + int cube_id_new = fieldstat_create_cube(master, new_tag->get_tag(), new_tag->get_tag_count(), SAMPLING_MODE_TOP_CARDINALITY, CELL_MAX); fieldstat_register_hll(master, cube_id_new, "hll", 6); EXPECT_EQ(cube_id_new, cube_id_to_change); // should new the cube in the hole leaved by the destroyed cube // calibrate @@ -514,7 +514,7 @@ TEST(Fuzz_test, simple_one_for_perf) // init cube for (int i = 0; i < CUBE_NUM; i++) { shared_tags[i] = new Fieldstat_tag_list_wrapper("shared_tag", i); - int cube_id = fieldstat_create_cube(master, shared_tags[i]->get_tag(), shared_tags[i]->get_tag_count(), SAMPLING_MODE_SPREADSKETCH, CELL_MAX); + int cube_id = fieldstat_create_cube(master, shared_tags[i]->get_tag(), shared_tags[i]->get_tag_count(), SAMPLING_MODE_TOP_CARDINALITY, CELL_MAX); EXPECT_EQ(cube_id, i); fieldstat_register_counter(master, cube_id, "topk"); } diff --git a/test/test_merge.cpp b/test/test_merge.cpp index 80bca32..2fe730e 100644 --- a/test/test_merge.cpp +++ b/test/test_merge.cpp @@ -49,7 +49,7 @@ double merge_test_fieldstat_hll_get(const struct fieldstat *instance, int cube_i TEST(unit_test_merge, cube_shared_tag_mapping_with_new_cube) { struct fieldstat *instance = fieldstat_new(); - (void)fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + (void)fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int cube_id2 = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int metric_id = fieldstat_register_counter(instance,cube_id2,"metric in cube 2"); fieldstat_counter_incrby(instance, cube_id2, metric_id, &TEST_TAG_STRING, 1, 1); @@ -168,7 +168,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 2); // 2nd cell - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 3); // 3rd cell, exceeding the limit 2 + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3rd cell, exceeding the limit 2 fieldstat_merge(instance_dest, instance); @@ -197,7 +197,7 @@ TEST(unit_test_merge, new_too_many_cells_on_multiple_metric_given_source_cube_re int metric_id3 = fieldstat_register_counter(instance, cube_id, "metric name3"); fieldstat_counter_incrby(instance, cube_id, metric_id3, &TEST_TAG_INT, 1, 2); // 2nd cell on metric name3, this is a metric dest dont have - fieldstat_counter_incrby(instance, cube_id, metric_id2, &TEST_TAG_DOUBLE, 1, 3); // 3nd cell on metric name2 + fieldstat_counter_incrby(instance, cube_id, metric_id2, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3nd cell on metric name2 fieldstat_merge(instance_dest, instance); int *metric_ids = NULL; @@ -315,7 +315,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 2); // 2nd cell - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 3); // 3rd cell,bigger than the others, so keep it + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3rd cell,bigger than the others, so keep it fieldstat_merge(instance_dest, instance); @@ -494,7 +494,7 @@ TEST(unit_test_merge, primary_metric_id_different) TEST(unit_test_merge, new_cube_and_metric_to_empty_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - fieldstat_create_cube(instance, &TEST_TAG_INT, 1, SAMPLING_MODE_SPREADSKETCH, 10); + fieldstat_create_cube(instance, &TEST_TAG_INT, 1, SAMPLING_MODE_TOP_CARDINALITY, 10); fieldstat_register_hll(instance, 0, "metric", 6); struct fieldstat *instance_dest = fieldstat_new(); @@ -513,7 +513,7 @@ TEST(unit_test_merge, new_cube_and_metric_to_empty_spreadsketch) { TEST(unit_test_merge, new_cell_on_existing_cube_and_metric_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 10); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 10); int metric_id = fieldstat_register_hll(instance, cube_id, "metric", 6); struct fieldstat *instance_dest = fieldstat_new(); fieldstat_merge(instance_dest, instance); @@ -545,7 +545,7 @@ TEST(unit_test_merge, new_cell_on_existing_cube_and_metric_spreadsketch) { TEST(unit_test_merge, merge_existing_cell_on_existing_cube_and_metric_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 10); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 10); int metric_id = fieldstat_register_hll(instance, cube_id, "metric", 6); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_STRING, 1, "1", 1); struct fieldstat *instance_dest = fieldstat_new(); @@ -569,7 +569,7 @@ TEST(unit_test_merge, merge_existing_cell_on_existing_cube_and_metric_spreadsket TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_and_get_different_cube_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 2); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 2); int metric_id = fieldstat_register_hll(instance, cube_id, "metric", 6); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_STRING, 1, "1", 1); struct fieldstat *instance_dest = fieldstat_new(); @@ -578,9 +578,9 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_INT, 1, "21", 2); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_INT, 1, "22", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "31", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "32", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "33", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "31", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "32", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "33", 2); fieldstat_merge(instance_dest, instance); struct field_list *tag_list = NULL; @@ -589,7 +589,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a EXPECT_EQ(n_cell, 2); EXPECT_NEAR(merge_test_fieldstat_hll_get(instance_dest, 0, 0, &tag_list[0]), 3, 0.3); EXPECT_NEAR(merge_test_fieldstat_hll_get(instance_dest, 0, 0, &tag_list[1]), 2, 0.3); - EXPECT_STREQ(tag_list[0].field[0].key, TEST_TAG_DOUBLE.key); + EXPECT_STREQ(tag_list[0].field[0].key, TEST_FIELD_VALUE_DOUBLE.key); EXPECT_STREQ(tag_list[1].field[0].key, TEST_TAG_INT.key); fieldstat_free(instance); @@ -601,7 +601,7 @@ TEST(unit_test_merge, gen_dest_full_all_src_inserted_given_src_flows_larger_spre int K = 100; SpreadSketchZipfGenerator flow_generator(1.0, K); // exactly the number of cells, so there will be almost all(in case of hash collision happen) cells added successfully struct fieldstat *instance_src = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance_src, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, K); + int cube_id = fieldstat_create_cube(instance_src, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, K); int metric_id = fieldstat_register_hll(instance_src, cube_id, "metric", 6); struct fieldstat *instance_dest = fieldstat_fork(instance_src); const char dest_key[] = "key of dest"; @@ -659,7 +659,7 @@ TEST(unit_test_merge, merge_accuracy_test_gen_dest_full_some_inserted_and_some_m int K = 10; SpreadSketchZipfGenerator flow_generator(1.0, K * 10); struct fieldstat *instance_src = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance_src, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, K); + int cube_id = fieldstat_create_cube(instance_src, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, K); int metric_id = fieldstat_register_hll(instance_src, cube_id, "metric", 6); struct fieldstat *instance_dest = fieldstat_fork(instance_src); diff --git a/test/test_metric_histogram.cpp b/test/test_metric_histogram.cpp index 84244bf..3a28aa3 100644 --- a/test/test_metric_histogram.cpp +++ b/test/test_metric_histogram.cpp @@ -12,7 +12,7 @@ struct fieldstat *test_init_standard_instance_one_cube_one_metric_one_cell_hdr() int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10); EXPECT_EQ(cube_id, 0); - int metric_id = fieldstat_register_hist(instance, cube_id, "czz_test hdr metric", 1, 600000, 3); + int metric_id = fieldstat_register_histogram(instance, cube_id, "czz_test hdr metric", 1, 600000, 3); EXPECT_EQ(metric_id, 0); return instance; @@ -52,13 +52,13 @@ TEST(metric_test_histogram, simple_register_and_query) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hdr(); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); test_assert_standard_instance(instance); - EXPECT_EQ(fieldstat_hist_value_at_percentile(instance, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); - EXPECT_EQ(fieldstat_hist_count_le_value(instance, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); + EXPECT_EQ(fieldstat_histogram_value_at_percentile(instance, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); + EXPECT_EQ(fieldstat_histogram_count_le_value(instance, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); fieldstat_free(instance); } @@ -66,9 +66,9 @@ TEST(metric_test_histogram, simple_register_and_query) TEST(metric_test_histogram, merge) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hdr(); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); struct fieldstat *instance_total = fieldstat_new(); fieldstat_merge(instance_total, instance); @@ -76,8 +76,8 @@ TEST(metric_test_histogram, merge) // query test_assert_standard_instance(instance_total); - EXPECT_EQ(fieldstat_hist_value_at_percentile(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); - EXPECT_EQ(fieldstat_hist_count_le_value(instance, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); + EXPECT_EQ(fieldstat_histogram_value_at_percentile(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); + EXPECT_EQ(fieldstat_histogram_count_le_value(instance, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); fieldstat_free(instance); fieldstat_free(instance_total); @@ -86,19 +86,19 @@ TEST(metric_test_histogram, merge) TEST(metric_test_histogram, merge_twice_with_reset) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hdr(); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 123); struct fieldstat *instance_total = fieldstat_new(); fieldstat_merge(instance_total, instance); fieldstat_reset(instance); - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_STRING, 1, 1234); fieldstat_merge(instance_total, instance); test_assert_standard_instance(instance_total); - EXPECT_EQ(fieldstat_hist_value_at_percentile(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); - EXPECT_EQ(fieldstat_hist_count_le_value(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); + EXPECT_EQ(fieldstat_histogram_value_at_percentile(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 50.0), 1234); + EXPECT_EQ(fieldstat_histogram_count_le_value(instance_total, 0, &TEST_TAG_LIST_STRING, 0, 1000), 1); fieldstat_free(instance); fieldstat_free(instance_total); @@ -109,9 +109,9 @@ TEST(metric_test_histogram, add_with_wrong_cube_id_expecting_fail) struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - int ret = fieldstat_hist_record(instance, cube_id + 1, 0, &TEST_TAG_INT, 1, 1); + int ret = fieldstat_histogram_record(instance, cube_id + 1, 0, &TEST_TAG_INT, 1, 1); EXPECT_EQ(ret, FS_ERR_INVALID_CUBE_ID); - ret = fieldstat_hist_record(instance, -1, 0, &TEST_TAG_INT, 1, 1); + ret = fieldstat_histogram_record(instance, -1, 0, &TEST_TAG_INT, 1, 1); EXPECT_EQ(ret, FS_ERR_INVALID_CUBE_ID); fieldstat_free(instance); @@ -121,11 +121,11 @@ TEST(metric_test_histogram, add_with_wrong_metric_id_expecting_fail) { struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - int metric_id = fieldstat_register_hist(instance, cube_id, "czz_test", 1, 600000, 3); + int metric_id = fieldstat_register_histogram(instance, cube_id, "czz_test", 1, 600000, 3); - int ret = fieldstat_hist_record(instance, cube_id, metric_id + 1, &TEST_TAG_INT, 1, 1); + int ret = fieldstat_histogram_record(instance, cube_id, metric_id + 1, &TEST_TAG_INT, 1, 1); EXPECT_EQ(ret, FS_ERR_INVALID_METRIC_ID); - ret = fieldstat_hist_record(instance, cube_id, -1, &TEST_TAG_INT, 1, 1); + ret = fieldstat_histogram_record(instance, cube_id, -1, &TEST_TAG_INT, 1, 1); EXPECT_EQ(ret, FS_ERR_INVALID_METRIC_ID); fieldstat_free(instance); @@ -170,15 +170,15 @@ TEST(metric_test_histogram, can_add_0value) // histogram only allow min_val > 0, { struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - int metric_id = fieldstat_register_hist(instance, cube_id, "czz_test", 1, 600000, 3); + int metric_id = fieldstat_register_histogram(instance, cube_id, "czz_test", 1, 600000, 3); - int ret = fieldstat_hist_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 0); + int ret = fieldstat_histogram_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 0); EXPECT_EQ(ret, 0); - ret = fieldstat_hist_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 0); + ret = fieldstat_histogram_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 0); EXPECT_EQ(ret, 0); - ret = fieldstat_hist_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 500); + ret = fieldstat_histogram_record(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 500); - EXPECT_EQ(fieldstat_hist_value_at_percentile(instance, cube_id, &TEST_TAG_LIST_INT, metric_id, 60.0), 0); + EXPECT_EQ(fieldstat_histogram_value_at_percentile(instance, cube_id, &TEST_TAG_LIST_INT, metric_id, 60.0), 0); fieldstat_free(instance); } diff --git a/test/test_metric_hll.cpp b/test/test_metric_hll.cpp index 66ef404..c96613c 100644 --- a/test/test_metric_hll.cpp +++ b/test/test_metric_hll.cpp @@ -74,7 +74,7 @@ TEST(metric_test_hll, add_with_tags) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hll(); fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_INT, 1); - fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_DOUBLE, 1); + fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_FIELD_VALUE_DOUBLE, 1); fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_STRING, 1); test_assert_standard_instance(instance); @@ -226,7 +226,7 @@ TEST(metric_test_hll, spread_sketch_add_and_test_accuracy) { struct fieldstat *instance = fieldstat_new(); int K = 10; - fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_SPREADSKETCH, K); + fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_TOP_CARDINALITY, K); fieldstat_register_hll(instance, 0, "testss", 6); int n_flows = 100000; diff --git a/test/test_performance.cpp b/test/test_performance.cpp index 2a8a8e9..3a9ef83 100644 --- a/test/test_performance.cpp +++ b/test/test_performance.cpp @@ -76,10 +76,10 @@ TEST(test_performance, merge_performance_one_instance_comprehensive_hll_empty_de TEST(test_performance, merge_performance_one_instance_comprehensive_histogram_empty_dest) { auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, int n_field) { - fieldstat_hist_record(instance, cube_id, metric_id, fields, n_field, 1234); + fieldstat_histogram_record(instance, cube_id, metric_id, fields, n_field, 1234); }; auto metric_register_func = [](struct fieldstat *instance) { - return fieldstat_register_hist(instance, 0, "histogram metric", 1, 100000, 1); + return fieldstat_register_histogram(instance, 0, "histogram metric", 1, 100000, 1); }; double elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, true); @@ -132,10 +132,10 @@ TEST(test_performance, merge_performance_one_instance_comprehensive_hll_full_des TEST(test_performance, merge_performance_one_instance_comprehensive_histogram_full_dest) { auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, int n_field) { - fieldstat_hist_record(instance, cube_id, metric_id, fields, n_field, 1234); + fieldstat_histogram_record(instance, cube_id, metric_id, fields, n_field, 1234); }; auto metric_register_func = [](struct fieldstat *instance) { - return fieldstat_register_hist(instance, 0, "histogram metric", 1, 100000, 1); + return fieldstat_register_histogram(instance, 0, "histogram metric", 1, 100000, 1); }; double elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, false); @@ -268,7 +268,7 @@ TEST(test_performance, performance_test_add_cells_histogram_record) { struct fieldstat *instance = fieldstat_new(); fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - fieldstat_register_hist(instance, 0, "test", 1, 100000, 3); + fieldstat_register_histogram(instance, 0, "test", 1, 100000, 3); size_t test_num = 100000; long long vals[test_num]; for (size_t i = 0; i < test_num; i++) { @@ -276,7 +276,7 @@ TEST(test_performance, performance_test_add_cells_histogram_record) } clock_t start = clock(); for (size_t i = 0; i < test_num; i++) { - fieldstat_hist_record(instance, 0, 0, &TEST_TAG_INT, 1, vals[i]); + fieldstat_histogram_record(instance, 0, 0, &TEST_TAG_INT, 1, vals[i]); } clock_t end = clock(); double seconds = (double)(end - start) / test_num; @@ -347,7 +347,7 @@ TEST(test_performance, performance_test_add_cells_histogram_record_5tags) { struct fieldstat *instance = fieldstat_new(); fieldstat_create_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - fieldstat_register_hist(instance, 0, "test", 1, 100000, 3); + fieldstat_register_histogram(instance, 0, "test", 1, 100000, 3); size_t test_num = 100000; long long vals[test_num]; for (size_t i = 0; i < test_num; i++) { @@ -357,12 +357,12 @@ TEST(test_performance, performance_test_add_cells_histogram_record_5tags) struct field fields[5]; fields[0] = TEST_TAG_INT; fields[1] = TEST_TAG_STRING; - fields[2] = TEST_TAG_DOUBLE; + fields[2] = TEST_FIELD_VALUE_DOUBLE; fields[3] = TEST_TAG_INT; fields[4] = TEST_TAG_INT; clock_t start = clock(); for (size_t i = 0; i < test_num; i++) { - fieldstat_hist_record(instance, 0, 0, fields, 5, vals[i]); + fieldstat_histogram_record(instance, 0, 0, fields, 5, vals[i]); } clock_t end = clock(); double seconds = (double)(end - start) / test_num; @@ -385,7 +385,7 @@ TEST(test_performance, performance_test_add_cells_hll_add_5tags) struct field fields[5]; fields[0] = TEST_TAG_INT; fields[1] = TEST_TAG_STRING; - fields[2] = TEST_TAG_DOUBLE; + fields[2] = TEST_FIELD_VALUE_DOUBLE; fields[3] = TEST_TAG_INT; fields[4] = TEST_TAG_INT; clock_t start = clock(); diff --git a/test/test_register_and_reset.cpp b/test/test_register_and_reset.cpp index 36902e1..79134e1 100644 --- a/test/test_register_and_reset.cpp +++ b/test/test_register_and_reset.cpp @@ -51,12 +51,12 @@ TEST(test_register, delete_topk_cube_with_cells_and_metrics) TEST(test_register, delete_spreadsketch_cube_with_cells_and_metrics) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 10); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 10); int metric_id1 = fieldstat_register_counter(instance, cube_id, "counter"); int metric_primary = fieldstat_register_hll(instance, cube_id, "hll_primary", 5); fieldstat_cube_set_primary_metric(instance, cube_id, metric_primary); fieldstat_counter_incrby(instance, cube_id, metric_id1, &TEST_TAG_INT, 1, 1); - fieldstat_hll_add_field(instance, cube_id, metric_primary, &TEST_TAG_INT, 1, &TEST_TAG_DOUBLE, 1); + fieldstat_hll_add_field(instance, cube_id, metric_primary, &TEST_TAG_INT, 1, &TEST_FIELD_VALUE_DOUBLE, 1); fieldstat_destroy_cube(instance, cube_id); struct field_list *tag_list = fieldstat_cube_get_tags(instance, cube_id); @@ -118,7 +118,7 @@ TEST(test_register, reset_and_try_to_query_cell_topk) TEST(test_register, reset_and_try_to_query_cell_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 10); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 10); int metric_id = fieldstat_register_hll(instance, cube_id, "hll", 5); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_INT, 1, "12abc", 5); @@ -140,7 +140,7 @@ TEST(test_register, reset_and_new_cell_comprehensive) int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 2); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_STRING, 1, 1); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); @@ -157,11 +157,11 @@ TEST(test_register, reset_and_new_cell_topk) int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOPK, 1); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 100);//100: bigger value - int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); + int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); fieldstat_reset(instance); - ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); + ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); EXPECT_EQ(ret, FS_OK); fieldstat_free(instance); @@ -170,7 +170,7 @@ TEST(test_register, reset_and_new_cell_topk) TEST(test_register, reset_and_new_cell_spreadsketch) { struct fieldstat *instance = fieldstat_new(); - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, 1); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, 1); int metric_id = fieldstat_register_hll(instance, cube_id, "hll", 5); // spread sketch will store more data than expected cell number 1. So loop for many cells first to trigger the error struct field test_tag_long = TEST_TAG_INT; @@ -178,11 +178,11 @@ TEST(test_register, reset_and_new_cell_spreadsketch) test_tag_long.value_longlong = i; fieldstat_hll_add(instance, cube_id, metric_id, &test_tag_long, 1, "12abc", 5); } - int ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "12abc", 5); + int ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "12abc", 5); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); fieldstat_reset(instance); - ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "12abc", 5); + ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "12abc", 5); EXPECT_EQ(ret, FS_OK); fieldstat_free(instance); @@ -251,7 +251,7 @@ TEST(test_register, ensure_recovery_more_faster_topk) { TEST(test_register, ensure_recovery_more_faster_spreadsketch) { struct fieldstat *instance = fieldstat_new(); int cell_num = 1000; - int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_SPREADSKETCH, cell_num); + int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOP_CARDINALITY, cell_num); int metric_id = fieldstat_register_hll(instance, cube_id, "counter", 6); struct field test_tag_long = TEST_TAG_INT; @@ -385,8 +385,8 @@ TEST(test_register, fork_registered_info_with_cube_and_metric) int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); int metric_id2 = fieldstat_register_counter(instance, cube_id, "counter2"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); - int cube_id_del = fieldstat_create_cube(instance, &TEST_TAG_DOUBLE_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + int cube_id_del = fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); fieldstat_destroy_cube(instance, cube_id_del); struct fieldstat *dup = fieldstat_fork(instance); @@ -405,7 +405,7 @@ TEST(test_register, fork_registered_info_with_cube_and_metric) EXPECT_EQ(n_cell, 0); tag_list = fieldstat_cube_get_tags(dup, cube_ids[1]); - EXPECT_STREQ(tag_list->field[0].key, TEST_TAG_DOUBLE.key); + EXPECT_STREQ(tag_list->field[0].key, TEST_FIELD_VALUE_DOUBLE.key); fieldstat_tag_list_arr_free(tag_list, 1); @@ -424,7 +424,7 @@ TEST(test_register, unregister_cube_on_wrong_instance) struct fieldstat *instance_dst = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - int cube_id2 = fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + int cube_id2 = fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); int metric_id2 = fieldstat_register_counter(instance, cube_id2, "counter2"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); @@ -459,7 +459,7 @@ TEST(test_register, register_many_cells_on_unlimited_sized_cube) struct fieldstat *instance = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 0); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); - struct field test_tag = {"abc", TAG_INTEGER, {.value_longlong = 0}}; + struct field test_tag = {"abc", FIELD_VALUE_INTEGER, {.value_longlong = 0}}; for (int i = 0; i < 10000; i++) { test_tag.value_longlong = i; fieldstat_counter_incrby(instance, cube_id, metric_id, &test_tag, 1, 1); @@ -490,7 +490,7 @@ TEST(test_register, find_cube) { int find_cube_id = fieldstat_find_cube(instance, &TEST_SHARED_TAG, 1); EXPECT_EQ(cube_id, find_cube_id); - int find_cube_id2 = fieldstat_find_cube(instance, &TEST_TAG_DOUBLE, 1); + int find_cube_id2 = fieldstat_find_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1); EXPECT_EQ(find_cube_id2, FS_ERR_INVALID_KEY); fieldstat_free(instance); diff --git a/test/test_write_json_file.cpp b/test/test_write_json_file.cpp index 1c6a969..ff3dedf 100644 --- a/test/test_write_json_file.cpp +++ b/test/test_write_json_file.cpp @@ -28,17 +28,17 @@ extern "C" { struct field cell_tags[2]; global_tags[0].key = "rule_id"; - global_tags[0].type = TAG_INTEGER; + global_tags[0].type = FIELD_VALUE_INTEGER; global_tags[0].value_longlong = 1; global_tags[1].key = "action"; - global_tags[1].type = TAG_CSTRING; + global_tags[1].type = FIELD_VALUE_CSTRING; global_tags[1].value_str = "deny"; cell_tags[0].key = "thread_id"; - cell_tags[0].type = TAG_INTEGER; + cell_tags[0].type = FIELD_VALUE_INTEGER; cell_tags[0].value_longlong = 1; cell_tags[1].key = "hit_rate"; - cell_tags[1].type = TAG_DOUBLE; + cell_tags[1].type = FIELD_VALUE_DOUBLE; cell_tags[1].value_double = 1.1; const char *hist_names[] = {"list_num", "max_wt_ms", "ivt_nx_itv_ms", @@ -62,7 +62,7 @@ static void write_hll(struct fieldstat *instance) { struct field shared_tags[1]; shared_tags[0].key = "rule_id"; - shared_tags[0].type = TAG_INTEGER; + shared_tags[0].type = FIELD_VALUE_INTEGER; shared_tags[0].value_longlong = 1; const char *hll_name[] = {"external_ip", "internal_ip", "acc_ip"}; @@ -89,17 +89,17 @@ void write_histogram(struct fieldstat *instance) { struct field cell_tags[2]; shared_tags[0].key = "rule_id"; - shared_tags[0].type = TAG_INTEGER; + shared_tags[0].type = FIELD_VALUE_INTEGER; shared_tags[0].value_longlong = 1; shared_tags[1].key = "action"; - shared_tags[1].type = TAG_CSTRING; + shared_tags[1].type = FIELD_VALUE_CSTRING; shared_tags[1].value_str = "deny"; cell_tags[0].key = "thread_id"; - cell_tags[0].type = TAG_INTEGER; + cell_tags[0].type = FIELD_VALUE_INTEGER; cell_tags[0].value_longlong = 1; cell_tags[1].key = "hit_rate"; - cell_tags[1].type = TAG_DOUBLE; + cell_tags[1].type = FIELD_VALUE_DOUBLE; cell_tags[1].value_double = 1.1; const char *hist_names[] = {"list_num", "max_wt_ms", "ivt_nx_itv_ms", @@ -112,11 +112,11 @@ void write_histogram(struct fieldstat *instance) { for(unsigned int i = 0; i < sizeof(hist_names)/sizeof(hist_names[0]); i++) { - int hist_id = fieldstat_register_hist(instance, cube_id, hist_names[i], 1, 600000, 3); + int hist_id = fieldstat_register_histogram(instance, cube_id, hist_names[i], 1, 600000, 3); for(int j = 0; j < 100; j++) { - fieldstat_hist_record(instance, cube_id, hist_id, cell_tags, 2, i*100 + j); + fieldstat_histogram_record(instance, cube_id, hist_id, cell_tags, 2, i*100 + j); } } } @@ -127,10 +127,10 @@ void write_histogram(struct fieldstat *instance) { // struct field cell_tags; // global_tags[0].key = "policy_id"; -// global_tags[0].type = TAG_INTEGER; +// global_tags[0].type = FIELD_VALUE_INTEGER; // global_tags[0].value_longlong = 1; // global_tags[1].key = "quanlity"; -// global_tags[1].type = TAG_DOUBLE; +// global_tags[1].type = FIELD_VALUE_DOUBLE; // global_tags[1].value_double = 0.5; // const char *cell_tag_value[] = { @@ -140,7 +140,7 @@ void write_histogram(struct fieldstat *instance) { // "STATISTICS-RULE-METRIC", "OBJECT-STATISTICS-METRIC"}; // cell_tags.key = "send_log"; -// cell_tags.type = TAG_CSTRING; +// cell_tags.type = FIELD_VALUE_CSTRING; // cell_tags.value_str = "true"; // struct fieldstat_easy *fse = fieldstat_easy_new(N_THREAD, NULL, global_tags, 2); @@ -168,10 +168,10 @@ void fieldstat_easy_to_file(struct fieldstat_easy *fse, const char *file_path) void write_table(struct fieldstat *instance) { struct field shared_tags[2]; shared_tags[0].key = "policy_id"; - shared_tags[0].type = TAG_INTEGER; + shared_tags[0].type = FIELD_VALUE_INTEGER; shared_tags[0].value_longlong = 1; shared_tags[1].key = "quanlity"; - shared_tags[1].type = TAG_DOUBLE; + shared_tags[1].type = FIELD_VALUE_DOUBLE; shared_tags[1].value_double = 0.5; const char *cell_tag_value[] = { @@ -182,7 +182,7 @@ void write_table(struct fieldstat *instance) { struct field cell_tags; cell_tags.key = "send_log"; - cell_tags.type = TAG_CSTRING; + cell_tags.type = FIELD_VALUE_CSTRING; cell_tags.value_str = "true"; int cube_id = fieldstat_create_cube(instance, shared_tags, 2, diff --git a/test/utils.cpp b/test/utils.cpp index eb14f6f..4e41d8f 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -45,13 +45,13 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct field_list * tag_list_c.field[i].type = tag_list->field[i].type; switch (tag_list->field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: tag_list_c.field[i].value_longlong = tag_list->field[i].value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: tag_list_c.field[i].value_double = tag_list->field[i].value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: tag_list_c.field[i].value_str = strdup(tag_list->field[i].value_str); break; default: @@ -65,7 +65,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const char * key, int val tag_list_c.field = (struct field *)malloc(sizeof(struct field)); tag_list_c.n_field = 1; tag_list_c.field[0].key = strdup(key); - tag_list_c.field[0].type = TAG_INTEGER; + tag_list_c.field[0].type = FIELD_VALUE_INTEGER; tag_list_c.field[0].value_longlong = value; } @@ -74,7 +74,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const char * key, const c tag_list_c.field = (struct field *)malloc(sizeof(struct field)); tag_list_c.n_field = 1; tag_list_c.field[0].key = strdup(key); - tag_list_c.field[0].type = TAG_CSTRING; + tag_list_c.field[0].type = FIELD_VALUE_CSTRING; tag_list_c.field[0].value_str = strdup(value); } @@ -82,7 +82,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const char * key, const c Fieldstat_tag_list_wrapper::~Fieldstat_tag_list_wrapper() { for (size_t i = 0; i < tag_list_c.n_field; i++) { free((char *)tag_list_c.field[i].key); - if (tag_list_c.field[i].type == TAG_CSTRING) { + if (tag_list_c.field[i].type == FIELD_VALUE_CSTRING) { free((char *)tag_list_c.field[i].value_str); } } @@ -100,17 +100,17 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(std::uniform_int_distribu int rand_ret = rand() % 3; if (rand_ret == 0) { - tag_list_c.field[i].type = TAG_INTEGER; + tag_list_c.field[i].type = FIELD_VALUE_INTEGER; tag_list_c.field[i].value_longlong = static_cast<long long>(dist(rng)); } else if (rand_ret == 1) { - tag_list_c.field[i].type = TAG_DOUBLE; + tag_list_c.field[i].type = FIELD_VALUE_DOUBLE; tag_list_c.field[i].value_double = static_cast<double>(dist(rng)) + 0.5; } else { - tag_list_c.field[i].type = TAG_CSTRING; + tag_list_c.field[i].type = FIELD_VALUE_CSTRING; tag_list_c.field[i].value_str = strdup(gen_rand_string(10).c_str()); } } @@ -132,13 +132,13 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const Fieldstat_tag_list_ tag_list_c.field[i].type = tag_list->field[i].type; switch (tag_list->field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: tag_list_c.field[i].value_longlong = tag_list->field[i].value_longlong; break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: tag_list_c.field[i].value_double = tag_list->field[i].value_double; break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: tag_list_c.field[i].value_str = strdup(tag_list->field[i].value_str); break; default: @@ -171,13 +171,13 @@ void Fieldstat_tag_list_wrapper::print_tag_list() const printf("tag_list_c.field[%zu].type: %d\n", i, (int)tag_list_c.field[i].type); switch (tag_list_c.field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: printf("tag_list_c.field[%zu].value_longlong: %lld\n", i, tag_list_c.field[i].value_longlong); break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: printf("tag_list_c.field[%zu].value_double: %lf\n", i, tag_list_c.field[i].value_double); break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: printf("tag_list_c.field[%zu].value_str: %s\n", i, tag_list_c.field[i].value_str); break; default: @@ -196,13 +196,13 @@ string Fieldstat_tag_list_wrapper::to_string() const str += ":"; switch (tag_list_c.field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: str += std::to_string(tag_list_c.field[i].value_longlong); break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: str += std::to_string(tag_list_c.field[i].value_double); break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: str += tag_list_c.field[i].value_str; break; default: @@ -227,17 +227,17 @@ bool Fieldstat_tag_list_wrapper::operator==(const Fieldstat_tag_list_wrapper &ta return false; } switch (tag_list_c.field[i].type) { - case TAG_INTEGER: + case FIELD_VALUE_INTEGER: if (tag_list_c.field[i].value_longlong != tag_list->field[i].value_longlong) { return false; } break; - case TAG_DOUBLE: + case FIELD_VALUE_DOUBLE: if (tag_list_c.field[i].value_double != tag_list->field[i].value_double) { return false; } break; - case TAG_CSTRING: + case FIELD_VALUE_CSTRING: if (strcmp((char *)tag_list_c.field[i].value_str, (char *)tag_list->field[i].value_str) != 0) { return false; } diff --git a/test/utils.hpp b/test/utils.hpp index ce73db0..bfb9414 100644 --- a/test/utils.hpp +++ b/test/utils.hpp @@ -3,16 +3,16 @@ #include <unordered_map> #include "fieldstat.h" -const struct field TEST_TAG_STRING = {"STRING KEY_", TAG_CSTRING, {.value_str = "100.1"}}; +const struct field TEST_TAG_STRING = {"STRING KEY_", FIELD_VALUE_CSTRING, {.value_str = "100.1"}}; const struct field_list TEST_TAG_LIST_STRING = {(struct field *)&TEST_TAG_STRING, 1}; -const struct field TEST_TAG_STRING_collided = {"collided", TAG_CSTRING, {.value_str = "2"}}; -const struct field TEST_TAG_INT = {"INT key_", TAG_INTEGER, {.value_longlong = 100}}; +const struct field TEST_TAG_STRING_collided = {"collided", FIELD_VALUE_CSTRING, {.value_str = "2"}}; +const struct field TEST_TAG_INT = {"INT key_", FIELD_VALUE_INTEGER, {.value_longlong = 100}}; const struct field_list TEST_TAG_LIST_INT = {(struct field *)&TEST_TAG_INT, 1}; -const struct field TEST_TAG_INT_collided = {"collided", TAG_INTEGER, {.value_longlong = 2}}; -const struct field TEST_TAG_DOUBLE = {"DOUBLE key_", TAG_DOUBLE, {.value_double = 100.1}}; -const struct field_list TEST_TAG_LIST_DOUBLE = {(struct field *)&TEST_TAG_DOUBLE, 1}; -const struct field TEST_TAG_DOUBLE_collided = {"collided", TAG_DOUBLE, {.value_double = 2.0}}; -const struct field TEST_SHARED_TAG = {"shared", TAG_INTEGER, {.value_longlong = 1}}; +const struct field TEST_TAG_INT_collided = {"collided", FIELD_VALUE_INTEGER, {.value_longlong = 2}}; +const struct field TEST_FIELD_VALUE_DOUBLE = {"DOUBLE key_", FIELD_VALUE_DOUBLE, {.value_double = 100.1}}; +const struct field_list TEST_TAG_LIST_DOUBLE = {(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; +const struct field TEST_FIELD_VALUE_DOUBLE_collided = {"collided", FIELD_VALUE_DOUBLE, {.value_double = 2.0}}; +const struct field TEST_SHARED_TAG = {"shared", FIELD_VALUE_INTEGER, {.value_longlong = 1}}; const struct timeval TEST_TIMEVAL = {100, 10000}; const long long TEST_TIMEVAL_LONG = 100010; // 100s * 1000 + 10000us / 1000 = 100010ms |
