summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-09 11:41:37 +0800
committerchenzizhan <[email protected]>2024-07-09 11:41:37 +0800
commitaff77f35e9a3d8c5c3a315c431b2da9a4e4da39d (patch)
treef45502850763c509d44c4b73f169d72f0ab84bcc /src
parentde1125112fbbdb63760ffe12871224b201b4e898 (diff)
rename tag->field; tag2key on stack
Diffstat (limited to 'src')
-rw-r--r--src/cube.c300
-rw-r--r--src/cube.h32
-rw-r--r--src/exporter/cjson_exporter.c124
-rw-r--r--src/fieldstat.c82
-rw-r--r--src/fieldstat_easy.c18
-rw-r--r--src/tags/heavy_keeper.c6
6 files changed, 318 insertions, 244 deletions
diff --git a/src/cube.c b/src/cube.c
index 92e999e..dfb0198 100644
--- a/src/cube.c
+++ b/src/cube.c
@@ -18,7 +18,7 @@
#define DEFAULT_N_CUBE 64
struct exdata_new_args {
- const struct fieldstat_tag *tags;
+ const struct field *fields;
size_t n_tags;
};
@@ -34,7 +34,7 @@ struct cell {
struct metric **metrics;
size_t metrics_len;
size_t max_n_metric;
- struct fieldstat_tag_list tags; // cell identifier
+ struct field_list fields; // cell identifier
};
struct cube {
@@ -45,8 +45,8 @@ struct cube {
};
size_t max_n_cell;
- // the key of cube is the combination of shared tags
- struct fieldstat_tag *cube_identifier;
+ // the key of cube is the combination of shared fields
+ struct field *cube_identifier;
size_t n_shared_tags;
int primary_metric_id;
@@ -56,11 +56,11 @@ struct cube {
UT_hash_handle hh;
};
-static struct fieldstat_tag *tag_array_duplicate(const struct fieldstat_tag *tags_src, size_t n_tag)
+static struct field *tag_array_duplicate(const struct field *tags_src, size_t n_field)
{
- struct fieldstat_tag *tags_dst = malloc(sizeof(struct fieldstat_tag) * n_tag);
+ struct field *tags_dst = malloc(sizeof(struct field) * n_field);
- for (size_t i = 0; i < n_tag; i++) {
+ for (size_t i = 0; i < n_field; i++) {
tags_dst[i].key = strdup(tags_src[i].key);
tags_dst[i].type = tags_src[i].type;
switch (tags_src[i].type)
@@ -82,16 +82,16 @@ static struct fieldstat_tag *tag_array_duplicate(const struct fieldstat_tag *tag
return tags_dst;
}
-static void fieldstat_free_tag_array(struct fieldstat_tag *tags, size_t n_tags)
+static void fieldstat_free_tag_array(struct field *fields, size_t n_tags)
{
for (size_t i = 0; i < n_tags; i++) {
- struct fieldstat_tag *tag = &tags[i];
- free((char *)tag->key);
- if (tag->type == TAG_CSTRING) {
- free((char *)tag->value_str);
+ struct field *field = &fields[i];
+ free((char *)field->key);
+ if (field->type == TAG_CSTRING) {
+ free((char *)field->value_str);
}
}
- free(tags);
+ free(fields);
}
void add_cube_to_position(struct cube_manager *instance, struct cube *cube, int id)
@@ -134,22 +134,78 @@ struct cube_manager *cube_manager_new() {
return pthis;
}
-static void tags2key(const struct fieldstat_tag tags[], size_t n_tags, char **out_key, size_t *out_key_size)
+static int tags2key_safe(const struct field fields[], size_t n_tags, char *out_key, size_t out_key_size)
+{
+ if (n_tags == 0) {
+ const char dummy[] = "no fields";
+ size_t len_dummy = sizeof(dummy) - 1;
+ if (out_key_size < len_dummy) {
+ return -1;
+ }
+ memcpy(out_key, dummy, len_dummy);
+ return len_dummy;
+ }
+ int i = 0;
+ size_t used_len = 0;
+ struct field *field = NULL;
+
+ size_t remain_key_size = out_key_size;
+ void *val_position = NULL;
+
+ size_t key_len = 0;
+ size_t val_len = 0;
+
+ for(i = 0; i < (int)n_tags; i++)
+ {
+ field = (struct field *)&fields[i];
+ key_len = strlen(field->key);
+ switch(field->type)
+ {
+ case TAG_INTEGER:
+ val_len = sizeof(long long);
+ val_position = (void *)&field->value_longlong;
+ break;
+ case TAG_DOUBLE:
+ val_len = sizeof(double);
+ val_position = (void *)&field->value_double;
+
+ break;
+ case TAG_CSTRING:
+ val_len = strlen(field->value_str);
+ val_position = (void *)field->value_str;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ used_len = key_len + val_len;
+ while (used_len >= remain_key_size) {
+ return -1;
+ }
+ memcpy(out_key + out_key_size - remain_key_size, field->key, key_len);
+ memcpy(out_key + out_key_size - remain_key_size + key_len, val_position, val_len);
+ remain_key_size -= used_len;
+ }
+
+ return out_key_size - remain_key_size;
+}
+
+static void tags2key_endeavor(const struct field fields[], size_t n_tags, char **out_key, size_t *out_key_size)
{
if (n_tags == 0) {
// use a default dummy key
- *out_key = strdup("no tags");
+ *out_key = strdup("no fields");
*out_key_size = strlen(*out_key);
return;
}
int i = 0;
size_t used_len = 0;
- struct fieldstat_tag *tag = NULL;
+ struct field *field = NULL;
size_t alloced_every_time = 1024;
- char dynamic_mem[1024*4];
- size_t remain_key_size = alloced_every_time;
- size_t total_key_size = alloced_every_time;
+ size_t remain_key_size = 4096 + 1024;
+ size_t total_key_size = 4096 + 1024;
char *dynamic_mem = (char *)malloc(total_key_size);
void *val_position = NULL;
@@ -158,22 +214,22 @@ static void tags2key(const struct fieldstat_tag tags[], size_t n_tags, char **ou
for(i = 0; i < (int)n_tags; i++)
{
- tag = (struct fieldstat_tag *)&tags[i];
- key_len = strlen(tag->key);
- switch(tag->type)
+ field = (struct field *)&fields[i];
+ key_len = strlen(field->key);
+ switch(field->type)
{
case TAG_INTEGER:
val_len = sizeof(long long);
- val_position = (void *)&tag->value_longlong;
+ val_position = (void *)&field->value_longlong;
break;
case TAG_DOUBLE:
val_len = sizeof(double);
- val_position = (void *)&tag->value_double;
+ val_position = (void *)&field->value_double;
break;
case TAG_CSTRING:
- val_len = strlen(tag->value_str);
- val_position = (void *)tag->value_str;
+ val_len = strlen(field->value_str);
+ val_position = (void *)field->value_str;
break;
default:
assert(0);
@@ -186,7 +242,7 @@ static void tags2key(const struct fieldstat_tag tags[], size_t n_tags, char **ou
remain_key_size += alloced_every_time;
dynamic_mem = (char *)realloc(dynamic_mem, total_key_size);
}
- memcpy(dynamic_mem + total_key_size - remain_key_size, tag->key, key_len);
+ memcpy(dynamic_mem + total_key_size - remain_key_size, field->key, key_len);
memcpy(dynamic_mem + total_key_size - remain_key_size + key_len, val_position, val_len);
remain_key_size -= used_len;
}
@@ -241,19 +297,26 @@ void cube_manager_delete(struct cube_manager *pthis, struct cube *cube)
}
}
-int cube_manager_find(const struct cube_manager *pthis, const struct fieldstat_tag *identifier, size_t n_tag)
+int cube_manager_find(const struct cube_manager *pthis, const struct field *identifier, size_t n_field)
{
- char *key;
- size_t key_len;
-
- fields_calculate_keylen;
- // fields_calculate_key_length(identifier, ntag) 用下面的吧
- // fields2key_endeaver / try
- tags2key(identifier, n_tag, &key, &key_len);
+ char key_stack[4096];
+ char *key = key_stack;
+ int key_len = tags2key_safe(identifier, n_field, key, sizeof(key));
+ bool free_key = false;
+ if (key_len < 0) { // very unlikely to happen
+ char *key_heap;
+ size_t key_len_tmp;
+ tags2key_endeavor(identifier, n_field, &key_heap, &key_len_tmp);
+ key = key_heap;
+ key_len = key_len_tmp;
+ free_key = true;
+ }
struct cube *node = NULL;
HASH_FIND(hh, pthis->hash_table, key, key_len, node);
- free(key);
+ if (free_key) {
+ free(key);
+ }
if (node == NULL) {
return -1;
} else {
@@ -389,8 +452,8 @@ struct cell *cell_new(const struct exdata_new_args *args) {
pthis->max_n_metric = DEFAULT_N_METRIC;
pthis->metrics_len = 0;
- pthis->tags.n_tag = args->n_tags;
- pthis->tags.tag = tag_array_duplicate(args->tags, args->n_tags);
+ pthis->fields.n_field = args->n_tags;
+ pthis->fields.field = tag_array_duplicate(args->fields, args->n_tags);
return pthis;
}
@@ -399,13 +462,13 @@ void cell_free(struct cell *pthis) {
metric_free(pthis->metrics[i]);
}
free(pthis->metrics);
- for (size_t i = 0; i < pthis->tags.n_tag; i++) {
- free((char *)pthis->tags.tag[i].key);
- if (pthis->tags.tag[i].type == TAG_CSTRING) {
- free((char *)pthis->tags.tag[i].value_str);
+ for (size_t i = 0; i < pthis->fields.n_field; i++) {
+ free((char *)pthis->fields.field[i].key);
+ if (pthis->fields.field[i].type == TAG_CSTRING) {
+ free((char *)pthis->fields.field[i].value_str);
}
}
- free(pthis->tags.tag);
+ free(pthis->fields.field);
free(pthis);
}
@@ -422,8 +485,8 @@ struct cell *cell_copy(const struct cell *src) {
pthis->metrics[i] = metric_copy(src->metrics[i]);
}
- pthis->tags.n_tag = src->tags.n_tag;
- pthis->tags.tag = tag_array_duplicate(src->tags.tag, src->tags.n_tag);
+ pthis->fields.n_field = src->fields.n_field;
+ pthis->fields.field = tag_array_duplicate(src->fields.field, src->fields.n_field);
return pthis;
}
@@ -474,29 +537,29 @@ void *exdata_copy_i(void *exdata) {
return cell_copy((struct cell *)exdata);
}
-struct cube *cube_info_new(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
+struct cube *cube_info_new(const struct field *shared_tags, size_t n_field, enum sampling_mode mode, size_t max_n_cell)
{
struct cube *cube = calloc(1, sizeof(struct cube));
cube->sampling_mode = mode;
- if (n_tag == 0) {
+ if (n_field == 0) {
cube->cube_identifier = NULL;
} else {
- cube->cube_identifier = tag_array_duplicate(shared_tags, n_tag);
+ cube->cube_identifier = tag_array_duplicate(shared_tags, n_field);
}
- cube->n_shared_tags = n_tag;
+ cube->n_shared_tags = n_field;
cube->max_n_cell = max_n_cell;
- tags2key(shared_tags, n_tag, &cube->key, &cube->key_len);
+ tags2key_endeavor(shared_tags, n_field, &cube->key, &cube->key_len);
cube->id = -1;
return cube;
}
-struct cube *cube_new(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
+struct cube *cube_new(const struct field *shared_tags, size_t n_field, enum sampling_mode mode, size_t max_n_cell)
{
- struct cube *cube = cube_info_new(shared_tags, n_tag, mode, max_n_cell);
+ struct cube *cube = cube_info_new(shared_tags, n_field, mode, max_n_cell);
switch (mode)
{
@@ -548,54 +611,65 @@ void cube_set_primary_metric(struct cube *cube, int metric_id) {
cube->primary_metric_id = metric_id;
}
-struct cell *get_cell(struct cube *cube, const struct fieldstat_tag *tags, size_t n_tag,long long increment, int metric_id) {
- char *tag_in_string;
- size_t tag_len;
- tags2key(tags, n_tag, &tag_in_string, &tag_len);
+struct cell *get_cell(struct cube *cube, const struct field *fields, size_t n_field,long long increment, int metric_id) {
+ char key_stack[4096];
+ char *key = key_stack;
+ int key_len = tags2key_safe(fields, n_field, key, sizeof(key));
+ bool free_key = false;
+ if (key_len < 0) { // very unlikely to happen
+ char *key_heap;
+ size_t key_len_tmp;
+ tags2key_endeavor(fields, n_field, &key_heap, &key_len_tmp);
+ key = key_heap;
+ key_len = key_len_tmp;
+ free_key = true;
+ }
+
struct exdata_new_args args;
- args.tags = tags;
- args.n_tags = n_tag;
+ args.fields = fields;
+ args.n_tags = n_field;
struct cell *cell_data = NULL;
-
switch (cube->sampling_mode) {
case SAMPLING_MODE_TOPK: {
if (cube->primary_metric_id != metric_id) {
- cell_data = heavy_keeper_get0_exdata(cube->topk, tag_in_string, tag_len);
+ cell_data = heavy_keeper_get0_exdata(cube->topk, key, key_len);
if (cell_data == NULL) {
- int tmp_ret = heavy_keeper_add(cube->topk, tag_in_string, tag_len, 0, (void *)&args);
+ int tmp_ret = heavy_keeper_add(cube->topk, key, key_len, 0, (void *)&args);
if (tmp_ret == 1) {
- cell_data = heavy_keeper_get0_exdata(cube->topk, tag_in_string, tag_len);
+ cell_data = heavy_keeper_get0_exdata(cube->topk, key, key_len);
}
}
} else {
// heavy_keeper_add should be called anyway, to let the topk record update.
- int tmp_ret = heavy_keeper_add(cube->topk, tag_in_string, tag_len, increment, (void *)&args);
+ int tmp_ret = heavy_keeper_add(cube->topk, key, key_len, increment, (void *)&args);
if (tmp_ret == 1) {
- cell_data = heavy_keeper_get0_exdata(cube->topk, tag_in_string, tag_len);
+ cell_data = heavy_keeper_get0_exdata(cube->topk, key, key_len);
}
}
break;}
case SAMPLING_MODE_COMPREHENSIVE: {
- cell_data = hash_table_get0_exdata(cube->comprehensive, tag_in_string, tag_len);
+ cell_data = hash_table_get0_exdata(cube->comprehensive, key, key_len);
if (cell_data == NULL) {
- int tmp_ret = hash_table_add(cube->comprehensive, tag_in_string, tag_len, (void *)&args);
+ int tmp_ret = hash_table_add(cube->comprehensive, key, key_len, (void *)&args);
if (tmp_ret == 1) {
- cell_data = hash_table_get0_exdata(cube->comprehensive, tag_in_string, tag_len);
+ cell_data = hash_table_get0_exdata(cube->comprehensive, key, key_len);
}
}
break;}
}
- free(tag_in_string);
+ if (free_key) {
+ free(key);
+ }
return cell_data;
}
-int cube_histogram_record(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long value) {
+int cube_histogram_record(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long value) {
assert(manifest->type == METRIC_TYPE_HISTOGRAM);
assert(cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->primary_metric_id != manifest->id));
- struct cell *cell_data = get_cell(cube, tags, n_tag, 0, manifest->id);
+ struct cell *cell_data = get_cell(cube, fields, n_field, 0, manifest->id);
if (cell_data == NULL) {
return FS_ERR_TOO_MANY_CELLS;
}
@@ -608,11 +682,11 @@ int cube_histogram_record(struct cube *cube, const struct metric_manifest *manif
return FS_OK;
}
-int cube_hll_add(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, const char *key, size_t key_len) {
+int cube_hll_add(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, const char *key, size_t key_len) {
assert(manifest->type == METRIC_TYPE_HLL);
assert(cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->primary_metric_id != manifest->id));
- struct cell *cell_data = get_cell(cube, tags, n_tag, 0, manifest->id);
+ struct cell *cell_data = get_cell(cube, fields, n_field, 0, manifest->id);
if (cell_data == NULL) {
return FS_ERR_TOO_MANY_CELLS;
}
@@ -622,28 +696,28 @@ int cube_hll_add(struct cube *cube, const struct metric_manifest *manifest, cons
return FS_OK;
}
-uint64_t tags2hash(const struct fieldstat_tag *tag, size_t n_tag) {
+uint64_t tags2hash(const struct field *field, size_t n_field) {
XXH3_state_t state = {0};
XXH3_64bits_reset(&state);
- for (int i = 0; i < n_tag; i++) {
- XXH3_64bits_update(&state, tag[i].key, strlen(tag[i].key));
- if (tag[i].type != TAG_CSTRING) {
- XXH3_64bits_update(&state, &tag[i].value_longlong, sizeof(long long));
+ for (int i = 0; i < n_field; i++) {
+ XXH3_64bits_update(&state, field[i].key, strlen(field[i].key));
+ if (field[i].type != TAG_CSTRING) {
+ XXH3_64bits_update(&state, &field[i].value_longlong, sizeof(long long));
} else {
- XXH3_64bits_update(&state, tag[i].value_str, strlen(tag[i].value_str));
+ XXH3_64bits_update(&state, field[i].value_str, strlen(field[i].value_str));
}
}
return XXH3_64bits_digest(&state);
}
-int cube_hll_add_tag(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, const struct fieldstat_tag *tags_key, size_t n_tag_key)
+int cube_hll_add_tag(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, const struct field *tags_key, size_t n_tag_key)
{
assert(manifest->type == METRIC_TYPE_HLL);
assert(cube->sampling_mode != SAMPLING_MODE_TOPK || (cube->primary_metric_id != manifest->id));
- struct cell *cell_data = get_cell(cube, tags, n_tag, 0, manifest->id);
+ struct cell *cell_data = get_cell(cube, fields, n_field, 0, manifest->id);
if (cell_data == NULL) {
return FS_ERR_TOO_MANY_CELLS;
}
@@ -654,11 +728,11 @@ int cube_hll_add_tag(struct cube *cube, const struct metric_manifest *manifest,
return FS_OK;
}
-int cube_counter_incrby(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long increment) {
+int cube_counter_incrby(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long increment) {
assert(manifest->type == METRIC_TYPE_COUNTER);
assert(cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->primary_metric_id != manifest->id || increment >= 0));
- struct cell *cell_data = get_cell(cube, tags, n_tag, increment, manifest->id);
+ struct cell *cell_data = get_cell(cube, fields, n_field, increment, manifest->id);
if (cell_data == NULL) {
return FS_ERR_TOO_MANY_CELLS;
}
@@ -669,11 +743,11 @@ int cube_counter_incrby(struct cube *cube, const struct metric_manifest *manifes
return FS_OK;
}
-int cube_counter_set(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long value) {
+int cube_counter_set(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long value) {
assert(manifest->type == METRIC_TYPE_COUNTER);
assert(cube->sampling_mode == SAMPLING_MODE_COMPREHENSIVE || (cube->primary_metric_id != manifest->id));
- struct cell *cell_data = get_cell(cube, tags, n_tag, 0, manifest->id);
+ struct cell *cell_data = get_cell(cube, fields, n_field, 0, manifest->id);
if (cell_data == NULL) {
return FS_ERR_TOO_MANY_CELLS;
}
@@ -729,7 +803,7 @@ struct cube *cube_fork(const struct cube *cube) {
return ret;
}
-void cube_get_cells(const struct cube *cube, struct fieldstat_tag_list **tag_list, size_t *n_cell)
+void cube_get_cells(const struct cube *cube, struct field_list **tag_list, size_t *n_cell)
{
size_t n_cell_tmp = 0;
switch (cube->sampling_mode) {
@@ -761,30 +835,30 @@ void cube_get_cells(const struct cube *cube, struct fieldstat_tag_list **tag_lis
assert(0);
}
- struct fieldstat_tag_list *tag_list_ret = (struct fieldstat_tag_list *)malloc(sizeof(struct fieldstat_tag_list) * n_cell_tmp);
+ struct field_list *tag_list_ret = (struct field_list *)malloc(sizeof(struct field_list) * n_cell_tmp);
*tag_list = tag_list_ret;
*n_cell = n_cell_tmp;
for (int i = 0; i < n_cell_tmp; i++) {
struct cell *cell_data = cell_datas[i];
- struct fieldstat_tag_list *tag_list_tmp = &tag_list_ret[i];
- tag_list_tmp->n_tag = cell_data->tags.n_tag;
- if (tag_list_tmp->n_tag == 0) {
- tag_list_tmp->tag = NULL;
+ struct field_list *tag_list_tmp = &tag_list_ret[i];
+ tag_list_tmp->n_field = cell_data->fields.n_field;
+ if (tag_list_tmp->n_field == 0) {
+ tag_list_tmp->field = NULL;
continue;
}
- tag_list_tmp->tag = tag_array_duplicate(cell_data->tags.tag, tag_list_tmp->n_tag);
+ tag_list_tmp->field = tag_array_duplicate(cell_data->fields.field, tag_list_tmp->n_field);
}
free(cell_datas);
}
-const struct cell *get_cell_by_tag_list(const struct cube *cube, const struct fieldstat_tag_list *tags)
+const struct cell *get_cell_by_tag_list(const struct cube *cube, const struct field_list *fields)
{
const struct cell *ret = NULL;
char *tag_in_string;
size_t tag_len;
- tags2key(tags->tag, tags->n_tag, &tag_in_string, &tag_len);
+ tags2key_endeavor(fields->field, fields->n_field, &tag_in_string, &tag_len);
switch (cube->sampling_mode)
{
@@ -803,9 +877,9 @@ const struct cell *get_cell_by_tag_list(const struct cube *cube, const struct fi
return ret;
}
-const struct metric *get_metric_by_tag_list(const struct cube *cube, const struct fieldstat_tag_list *tags, int metric_id,int *ret)
+const struct metric *get_metric_by_tag_list(const struct cube *cube, const struct field_list *fields, int metric_id,int *ret)
{
- const struct cell *data = get_cell_by_tag_list(cube, tags);
+ const struct cell *data = get_cell_by_tag_list(cube, fields);
if (data == NULL) {
*ret = FS_ERR_INVALID_TAG;
@@ -821,10 +895,10 @@ const struct metric *get_metric_by_tag_list(const struct cube *cube, const struc
return data->metrics[metric_id];
}
-int cube_counter_get(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, long long *value)
+int cube_counter_get(const struct cube *cube, int metric_id, const struct field_list *fields, long long *value)
{
int ret;
- const struct metric *metric = get_metric_by_tag_list(cube, tags, metric_id, &ret);
+ const struct metric *metric = get_metric_by_tag_list(cube, fields, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
@@ -836,10 +910,10 @@ int cube_counter_get(const struct cube *cube, int metric_id, const struct fields
return FS_OK;
}
-int cube_hll_get(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, double *value)
+int cube_hll_get(const struct cube *cube, int metric_id, const struct field_list *fields, double *value)
{
int ret;
- const struct metric *metric = get_metric_by_tag_list(cube, tags, metric_id, &ret);
+ const struct metric *metric = get_metric_by_tag_list(cube, fields, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
@@ -851,10 +925,10 @@ int cube_hll_get(const struct cube *cube, int metric_id, const struct fieldstat_
return FS_OK;
}
-int cube_histogram_value_at_percentile(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, double percentile, long long *value)
+int cube_histogram_value_at_percentile(const struct cube *cube, int metric_id, const struct field_list *fields, double percentile, long long *value)
{
int ret;
- const struct metric *metric = get_metric_by_tag_list(cube, tags, metric_id, &ret);
+ const struct metric *metric = get_metric_by_tag_list(cube, fields, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
@@ -866,9 +940,9 @@ int cube_histogram_value_at_percentile(const struct cube *cube, int metric_id, c
return FS_OK;
}
-int cube_histogram_count_le_value(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, long long value, long long *count) {
+int cube_histogram_count_le_value(const struct cube *cube, int metric_id, const struct field_list *fields, long long value, long long *count) {
int ret;
- const struct metric *metric = get_metric_by_tag_list(cube, tags, metric_id, &ret);
+ const struct metric *metric = get_metric_by_tag_list(cube, fields, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
@@ -880,9 +954,9 @@ int cube_histogram_count_le_value(const struct cube *cube, int metric_id, const
return FS_OK;
}
-int cube_get_serialization(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, char **blob, size_t *blob_size) {
+int cube_get_serialization(const struct cube *cube, int metric_id, const struct field_list *fields, char **blob, size_t *blob_size) {
int ret;
- const struct metric *metric = get_metric_by_tag_list(cube, tags, metric_id, &ret);
+ const struct metric *metric = get_metric_by_tag_list(cube, fields, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
@@ -905,8 +979,8 @@ int cube_get_cell_count(const struct cube *cube) {
}
}
-void cube_get_cells_used_by_metric(const struct cube *cube, const struct fieldstat_tag_list *tags, int **metric_id_out, size_t *n_metric_out) {
- const struct cell *cell_data = get_cell_by_tag_list(cube, tags);
+void cube_get_cells_used_by_metric(const struct cube *cube, const struct field_list *fields, int **metric_id_out, size_t *n_metric_out) {
+ const struct cell *cell_data = get_cell_by_tag_list(cube, fields);
if (cell_data == NULL) {
*metric_id_out = NULL;
*n_metric_out = 0;
@@ -924,17 +998,17 @@ void cube_get_cells_used_by_metric(const struct cube *cube, const struct fieldst
*n_metric_out = n_metric;
}
-struct fieldstat_tag_list *cube_get_identifier(const struct cube *cube) {
- struct fieldstat_tag_list *tag_list = (struct fieldstat_tag_list *)malloc(sizeof(struct fieldstat_tag_list));
+struct field_list *cube_get_identifier(const struct cube *cube) {
+ struct field_list *tag_list = (struct field_list *)malloc(sizeof(struct field_list));
if (cube->n_shared_tags == 0) {
- tag_list->tag = NULL;
- tag_list->n_tag = 0;
+ tag_list->field = NULL;
+ tag_list->n_field = 0;
return tag_list;
}
- tag_list->tag = tag_array_duplicate(cube->cube_identifier, cube->n_shared_tags);
- tag_list->n_tag = cube->n_shared_tags;
+ tag_list->field = tag_array_duplicate(cube->cube_identifier, cube->n_shared_tags);
+ tag_list->n_field = cube->n_shared_tags;
return tag_list;
diff --git a/src/cube.h b/src/cube.h
index 3a2d20b..1ac4b4d 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -7,43 +7,43 @@ extern "C"
#include <stddef.h>
#include <stdbool.h>
-#include "fieldstat.h" // for tags
+#include "fieldstat.h" // for fields
#include "metric_manifest.h"
struct cube;
struct cube_manager;
-struct cube *cube_new(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell);
+struct cube *cube_new(const struct field *shared_tags, size_t n_field, enum sampling_mode mode, size_t max_n_cell);
void cube_free(struct cube *cube);
void cube_reset(struct cube *cube);
struct cube *cube_copy(const struct cube *cube);
void cube_merge(struct cube *dest, const struct cube *src);
struct cube *cube_fork(const struct cube *cube); // only copy the cube configurations, leave the cells empty
-int cube_histogram_record(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long value);
-int cube_hll_add(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, const char *key, size_t key_len);
-int cube_hll_add_tag(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, const struct fieldstat_tag *tags_key, size_t n_tag_key);
-int cube_counter_incrby(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long increment);
-int cube_counter_set(struct cube *cube, const struct metric_manifest *manifest, const struct fieldstat_tag *tags, size_t n_tag, long long value);
+int cube_histogram_record(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long value);
+int cube_hll_add(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, const char *key, size_t key_len);
+int cube_hll_add_tag(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, const struct field *tags_key, size_t n_tag_key);
+int cube_counter_incrby(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long increment);
+int cube_counter_set(struct cube *cube, const struct metric_manifest *manifest, const struct field *fields, size_t n_field, long long value);
-int cube_counter_get(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, long long *value);
-int cube_hll_get(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, double *value);
-int cube_histogram_value_at_percentile(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, double percentile, long long *value);
-int cube_histogram_count_le_value(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, long long value, long long *count);
-int cube_get_serialization(const struct cube *cube, int metric_id, const struct fieldstat_tag_list *tags, char **blob, size_t *blob_size);
+int cube_counter_get(const struct cube *cube, int metric_id, const struct field_list *fields, long long *value);
+int cube_hll_get(const struct cube *cube, int metric_id, const struct field_list *fields, double *value);
+int cube_histogram_value_at_percentile(const struct cube *cube, int metric_id, const struct field_list *fields, double percentile, long long *value);
+int cube_histogram_count_le_value(const struct cube *cube, int metric_id, const struct field_list *fields, long long value, long long *count);
+int cube_get_serialization(const struct cube *cube, int metric_id, const struct field_list *fields, char **blob, size_t *blob_size);
int cube_get_cell_count(const struct cube *cube);
-void cube_get_cells(const struct cube *cube, struct fieldstat_tag_list **tag_list, size_t *n_cell);
-void cube_get_cells_used_by_metric(const struct cube *cube, const struct fieldstat_tag_list *tags, int **metric_id_out, size_t *n_metric_out);
+void cube_get_cells(const struct cube *cube, struct field_list **tag_list, size_t *n_cell);
+void cube_get_cells_used_by_metric(const struct cube *cube, const struct field_list *fields, int **metric_id_out, size_t *n_metric_out);
void cube_set_primary_metric(struct cube *cube, int metric_id);
-struct fieldstat_tag_list *cube_get_identifier(const struct cube *cube);
+struct field_list *cube_get_identifier(const struct cube *cube);
struct cube *cube_manager_get_cube_by_id(const struct cube_manager *manager, int cube_id);
// the cube will be taken over by the manager, user do not free it.
int cube_manager_add(struct cube_manager *pthis, struct cube *cube);
void cube_manager_delete(struct cube_manager *pthis, struct cube *cube); // the cube will be freed by the manager
-int cube_manager_find(const struct cube_manager *pthis, const struct fieldstat_tag *identifier, size_t n_tag);
+int cube_manager_find(const struct cube_manager *pthis, const struct field *identifier, size_t n_field);
struct cube_manager *cube_manager_new();
void cube_manager_free(struct cube_manager *pthis);
void cube_manager_merge(struct cube_manager *dest, const struct cube_manager *src);
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c
index 643fb0f..9466f01 100644
--- a/src/exporter/cjson_exporter.c
+++ b/src/exporter/cjson_exporter.c
@@ -50,7 +50,7 @@
struct counter_history;
struct export_kv_pair {
char *key;
- enum fs_tag_type type;
+ enum field_type type;
union{
long long value_longlong;
double value_double;
@@ -60,7 +60,7 @@ struct export_kv_pair {
struct fieldstat_json_exporter {
char *name;
- struct fieldstat_tag_list *global_tag_list;
+ struct field_list *global_tag_list;
struct counter_history *history;
long long last_ts;
};
@@ -69,9 +69,9 @@ struct cell_iter {
int *cube_ids;
int n_cube;
int curr_cube_idx;
- struct fieldstat_tag_list *shared_tag;
+ struct field_list *shared_tag;
- struct fieldstat_tag_list *tag_list;
+ struct field_list *tag_list;
size_t n_cell;
size_t curr_cell_idx;
@@ -101,7 +101,7 @@ struct counter_history {
long long ts;
char *exporter_name;
- struct fieldstat_tag_list *global_tag_list;
+ struct field_list *global_tag_list;
};
struct couple_export_table_item {
@@ -123,7 +123,7 @@ void kv_pair_free(struct export_kv_pair *pair) {
free(pair);
}
-void kv_pair_fill_with_tags(struct export_kv_pair *dest, const struct fieldstat_tag *src)
+void kv_pair_fill_with_tags(struct export_kv_pair *dest, const struct field *src)
{
dest->key = strdup(src->key);
dest->type = src->type;
@@ -214,33 +214,33 @@ void counter_history_free(struct counter_history *history)
free(history);
}
-bool fieldstat_tag_list_cmp(const struct fieldstat_tag_list *a, const struct fieldstat_tag_list *b)
+bool fieldstat_tag_list_cmp(const struct field_list *a, const struct field_list *b)
{
- if (a->n_tag != b->n_tag) {
+ if (a->n_field != b->n_field) {
return false;
}
- for (int i = 0; i < a->n_tag; i++) {
- if (strcmp(a->tag[i].key, b->tag[i].key) != 0) {
+ for (int i = 0; i < a->n_field; i++) {
+ if (strcmp(a->field[i].key, b->field[i].key) != 0) {
return false;
}
- if (a->tag[i].type != b->tag[i].type) {
+ if (a->field[i].type != b->field[i].type) {
return false;
}
- switch (a->tag[i].type)
+ switch (a->field[i].type)
{
case TAG_INTEGER:
- if (a->tag[i].value_longlong != b->tag[i].value_longlong) {
+ if (a->field[i].value_longlong != b->field[i].value_longlong) {
return false;
}
break;
case TAG_DOUBLE:
- if (a->tag[i].value_double != b->tag[i].value_double) {
+ if (a->field[i].value_double != b->field[i].value_double) {
return false;
}
break;
case TAG_CSTRING:
- if (strcmp(a->tag[i].value_str, b->tag[i].value_str) != 0) {
+ if (strcmp(a->field[i].value_str, b->field[i].value_str) != 0) {
return false;
}
break;
@@ -252,24 +252,24 @@ bool fieldstat_tag_list_cmp(const struct fieldstat_tag_list *a, const struct fie
return true;
}
-struct fieldstat_tag_list *my_copy_fs_tag_list(const struct fieldstat_tag_list *src)
+struct field_list *my_copy_fs_tag_list(const struct field_list *src)
{
- struct fieldstat_tag_list *dest = malloc(sizeof(struct fieldstat_tag_list));
- dest->n_tag = src->n_tag;
- dest->tag = malloc(sizeof(struct fieldstat_tag) * dest->n_tag);
- for (int i = 0; i < dest->n_tag; i++) {
- dest->tag[i].key = strdup(src->tag[i].key);
- dest->tag[i].type = src->tag[i].type;
- switch (src->tag[i].type)
+ struct field_list *dest = malloc(sizeof(struct field_list));
+ dest->n_field = src->n_field;
+ dest->field = malloc(sizeof(struct field) * dest->n_field);
+ for (int i = 0; i < dest->n_field; i++) {
+ dest->field[i].key = strdup(src->field[i].key);
+ dest->field[i].type = src->field[i].type;
+ switch (src->field[i].type)
{
case TAG_INTEGER:
- dest->tag[i].value_longlong = src->tag[i].value_longlong;
+ dest->field[i].value_longlong = src->field[i].value_longlong;
break;
case TAG_DOUBLE:
- dest->tag[i].value_double = src->tag[i].value_double;
+ dest->field[i].value_double = src->field[i].value_double;
break;
case TAG_CSTRING:
- dest->tag[i].value_str = strdup(src->tag[i].value_str);
+ dest->field[i].value_str = strdup(src->field[i].value_str);
break;
default:
assert(0);
@@ -290,7 +290,7 @@ bool counter_history_check_if_need_to_update(const struct fieldstat_json_exporte
}
const char *cur_exporter_name = exporter->name ? exporter->name : DEFAULT_EXPORTER_NAME;
- const struct fieldstat_tag_list *cur_global_tag_list = exporter->global_tag_list;
+ const struct field_list *cur_global_tag_list = exporter->global_tag_list;
if (strcmp(history->exporter_name, cur_exporter_name) != 0) {
return true;
@@ -302,7 +302,7 @@ bool counter_history_check_if_need_to_update(const struct fieldstat_json_exporte
if (history->global_tag_list == NULL && cur_global_tag_list == NULL) {
return false;
}
- // global tag cant be deleted, so no need to check if cur_global_tag_list == NULL && history->global_tag_list != NULL
+ // global field cant be deleted, so no need to check if cur_global_tag_list == NULL && history->global_tag_list != NULL
if (fieldstat_tag_list_cmp(cur_global_tag_list, history->global_tag_list) == false) {
return true;
}
@@ -313,7 +313,7 @@ bool counter_history_check_if_need_to_update(const struct fieldstat_json_exporte
void counter_history_fill_version_info(struct counter_history *history, struct fieldstat_json_exporter *exporter, const struct fieldstat *instance)
{
const char *cur_exporter_name = exporter->name ? exporter->name : DEFAULT_EXPORTER_NAME;
- const struct fieldstat_tag_list *cur_global_tag_list = exporter->global_tag_list;
+ const struct field_list *cur_global_tag_list = exporter->global_tag_list;
free(history->exporter_name);
history->exporter_name = strdup(cur_exporter_name);
@@ -336,7 +336,7 @@ void fieldstat_json_exporter_update_history(struct fieldstat_json_exporter *expo
void write_delta_to_json(struct fieldstat_json_exporter *exporter, struct cellwise_rec_for_export *tag_field_pair, struct json_writer *field_json)
{
- // for every tag_field_pair, get the tag json string
+ // for every tag_field_pair, get the field json string
const char *tag_json = json_writer_unwrap(tag_field_pair->cjson_tags);
if (tag_json == NULL) {
tag_json = "\a\t\a"; // just a dummy string
@@ -409,13 +409,13 @@ void couple_export_table_free(struct couple_export_table *tbl)
#define NIL_TAG_JSON "\anil"
-// align delta fields to acc fields by matching tag json string, return an array with length n_acc, each of whose element match the corresponding acc element by both tag and index
+// align delta fields to acc fields by matching field json string, return an array with length n_acc, each of whose element match the corresponding acc element by both field and index
const struct cellwise_rec_for_export **rearrange_metric_delta(const struct cellwise_rec_for_export *acc, size_t n_acc, const struct cellwise_rec_for_export *delta, size_t n_delta)
{
struct couple_export_table *map = couple_export_table_new();
for (int i = 0; i < n_delta; i++) {
const char *tag_json = json_writer_unwrap(delta[i].cjson_tags);
- if (tag_json == NULL) { // tag might be empty, give it a dummy name
+ if (tag_json == NULL) { // field might be empty, give it a dummy name
tag_json = NIL_TAG_JSON;
}
couple_export_table_add(map, tag_json, i);
@@ -425,7 +425,7 @@ const struct cellwise_rec_for_export **rearrange_metric_delta(const struct cellw
for (int id_acc = 0; id_acc < n_acc; id_acc++) {
const char *tag_str_acc = json_writer_unwrap(acc[id_acc].cjson_tags);
- if (tag_str_acc == NULL) { // tag might be empty, give it a dummy name
+ if (tag_str_acc == NULL) { // field might be empty, give it a dummy name
tag_str_acc = NIL_TAG_JSON;
}
@@ -573,28 +573,28 @@ void kv_pair_write_to_json(const struct export_kv_pair *pairs, struct json_write
}
}
-void tag_list_append_to_tag_object(const struct fieldstat_tag_list *tag_list, struct json_writer *cjson_tags)
+void tag_list_append_to_tag_object(const struct field_list *tag_list, struct json_writer *cjson_tags)
{
- size_t tag_list_len = tag_list->n_tag;
+ size_t tag_list_len = tag_list->n_field;
struct export_kv_pair pairs = {0};
for (int i = 0; i < tag_list_len; i++) {
- if (tag_list->n_tag == 0) {
+ if (tag_list->n_field == 0) {
continue;
}
memset(&pairs, 0, sizeof(struct export_kv_pair));
- pairs.key = (char *)tag_list->tag[i].key;
- pairs.type = tag_list->tag[i].type;
+ pairs.key = (char *)tag_list->field[i].key;
+ pairs.type = tag_list->field[i].type;
switch (pairs.type)
{
case TAG_INTEGER:
- pairs.value_longlong = tag_list->tag[i].value_longlong;
+ pairs.value_longlong = tag_list->field[i].value_longlong;
break;
case TAG_DOUBLE:
- pairs.value_double = tag_list->tag[i].value_double;
+ pairs.value_double = tag_list->field[i].value_double;
break;
case TAG_CSTRING:
- pairs.value_str = (char *)tag_list->tag[i].value_str;
+ pairs.value_str = (char *)tag_list->field[i].value_str;
break;
default:
break;
@@ -605,20 +605,20 @@ void tag_list_append_to_tag_object(const struct fieldstat_tag_list *tag_list, st
void cell_iter_read_tag_list(const struct cell_iter *iter, struct export_kv_pair **exported_tags, size_t *len_out)
{
- struct fieldstat_tag_list *tag_list_cell = &iter->tag_list[iter->curr_cell_idx];
- struct fieldstat_tag_list *tag_arr_shared = iter->shared_tag;
+ struct field_list *tag_list_cell = &iter->tag_list[iter->curr_cell_idx];
+ struct field_list *tag_arr_shared = iter->shared_tag;
- size_t ret_tag_list_len = tag_list_cell->n_tag + tag_arr_shared->n_tag;
+ size_t ret_tag_list_len = tag_list_cell->n_field + tag_arr_shared->n_field;
struct export_kv_pair *tag_list = malloc(sizeof(struct export_kv_pair) * ret_tag_list_len);
*exported_tags = tag_list;
*len_out = ret_tag_list_len;
- for (int i = 0; i < tag_list_cell->n_tag; i++) {
- kv_pair_fill_with_tags(tag_list++, &tag_list_cell->tag[i]);
+ for (int i = 0; i < tag_list_cell->n_field; i++) {
+ kv_pair_fill_with_tags(tag_list++, &tag_list_cell->field[i]);
}
- for (int i = 0; i < tag_arr_shared->n_tag; i++) {
- kv_pair_fill_with_tags(tag_list++, &tag_arr_shared->tag[i]);
+ for (int i = 0; i < tag_arr_shared->n_field; i++) {
+ kv_pair_fill_with_tags(tag_list++, &tag_arr_shared->field[i]);
}
}
@@ -955,7 +955,7 @@ char *fieldstat_json_exporter_export_with_delta(const struct fieldstat_json_expo
free(expair_delta[i].metric_pairs);
char *dummy_s;
size_t dummy_len;
- json_writer_finish(expair_delta[i].cjson_tags, &dummy_s, &dummy_len); // the tag json is not added to the root json, so we need to free it manually
+ json_writer_finish(expair_delta[i].cjson_tags, &dummy_s, &dummy_len); // the field json is not added to the root json, so we need to free it manually
free(dummy_s);
}
free(expair_delta);
@@ -975,30 +975,30 @@ struct fieldstat_json_exporter *fieldstat_json_exporter_new()
return exporter;
}
-void fieldstat_json_exporter_set_global_tag(struct fieldstat_json_exporter *exporter, const struct fieldstat_tag tag_list[], size_t n_tag)
+void fieldstat_json_exporter_set_global_tag(struct fieldstat_json_exporter *exporter, const struct field tag_list[], size_t n_field)
{
if (exporter->global_tag_list != NULL) {
- free(exporter->global_tag_list->tag);
+ free(exporter->global_tag_list->field);
free(exporter->global_tag_list);
}
- exporter->global_tag_list = malloc(sizeof(struct fieldstat_tag_list));
- exporter->global_tag_list->n_tag = n_tag;
- exporter->global_tag_list->tag = malloc(sizeof(struct fieldstat_tag) * n_tag);
- for (size_t i = 0; i < n_tag; i++) {
- struct fieldstat_tag *tag = &exporter->global_tag_list->tag[i];
- tag->key = strdup(tag_list[i].key);
- tag->type = tag_list[i].type;
- switch (tag->type)
+ exporter->global_tag_list = malloc(sizeof(struct field_list));
+ exporter->global_tag_list->n_field = n_field;
+ exporter->global_tag_list->field = malloc(sizeof(struct field) * n_field);
+ for (size_t i = 0; i < n_field; i++) {
+ struct field *field = &exporter->global_tag_list->field[i];
+ field->key = strdup(tag_list[i].key);
+ field->type = tag_list[i].type;
+ switch (field->type)
{
case TAG_INTEGER:
- tag->value_longlong = tag_list[i].value_longlong;
+ field->value_longlong = tag_list[i].value_longlong;
break;
case TAG_CSTRING:
- tag->value_str = strdup(tag_list[i].value_str);
+ field->value_str = strdup(tag_list[i].value_str);
break;
case TAG_DOUBLE:
- tag->value_double = tag_list[i].value_double;
+ field->value_double = tag_list[i].value_double;
break;
default:
diff --git a/src/fieldstat.c b/src/fieldstat.c
index cd43128..4e3a103 100644
--- a/src/fieldstat.c
+++ b/src/fieldstat.c
@@ -43,9 +43,9 @@ union metric_parameter *construct_parameters(enum metric_type type, ...)
return paras;
}
-void tag_array_copy(struct fieldstat_tag *tags_dst, const struct fieldstat_tag *tags_src, size_t n_tag)
+void tag_array_copy(struct field *tags_dst, const struct field *tags_src, size_t n_field)
{
- for (size_t i = 0; i < n_tag; i++) {
+ for (size_t i = 0; i < n_field; i++) {
tags_dst[i].key = strdup(tags_src[i].key);
tags_dst[i].type = tags_src[i].type;
switch (tags_src[i].type)
@@ -65,9 +65,9 @@ void tag_array_copy(struct fieldstat_tag *tags_dst, const struct fieldstat_tag *
}
}
-bool is_tag_array_same(const struct fieldstat_tag *tags1, const struct fieldstat_tag *tags2, size_t n_tag)
+bool is_tag_array_same(const struct field *tags1, const struct field *tags2, size_t n_field)
{
- for (size_t i = 0; i < n_tag; i++) {
+ for (size_t i = 0; i < n_field; i++) {
if (tags1[i].type != tags2[i].type) {
return false;
}
@@ -150,27 +150,27 @@ int fieldstat_destroy_cube(struct fieldstat *instance, int cube_id)
/* cube */
/* -------------------------------------------------------------------------- */
-void fieldstat_free_tag_array(struct fieldstat_tag *tags, size_t n_tags)
+void fieldstat_free_tag_array(struct field *fields, size_t n_tags)
{
for (size_t i = 0; i < n_tags; i++) {
- struct fieldstat_tag *tag = &tags[i];
- free((char *)tag->key);
- if (tag->type == TAG_CSTRING) {
- free((char *)tag->value_str);
+ struct field *field = &fields[i];
+ free((char *)field->key);
+ if (field->type == TAG_CSTRING) {
+ free((char *)field->value_str);
}
}
- free(tags);
+ free(fields);
}
-int fieldstat_create_cube(struct fieldstat *instance, const struct fieldstat_tag *cube_identifier, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
+int fieldstat_create_cube(struct fieldstat *instance, const struct field *cube_identifier, size_t cube_identifier_len, enum sampling_mode mode, size_t max_n_cell)
{
if (instance == NULL) {
return FS_ERR_NULL_HANDLER;
}
- if (n_tag == 0 || cube_identifier == NULL) {
+ if (cube_identifier_len == 0 || cube_identifier == NULL) {
cube_identifier = NULL;
- n_tag = 0;
+ cube_identifier_len = 0;
}
if (mode == SAMPLING_MODE_TOPK && max_n_cell == 0) {
return FS_ERR_INVALID_PARAM;
@@ -179,7 +179,7 @@ int fieldstat_create_cube(struct fieldstat *instance, const struct fieldstat_tag
max_n_cell = INT32_MAX;
}
- struct cube *cube = cube_new(cube_identifier, n_tag, mode, max_n_cell);
+ struct cube *cube = cube_new(cube_identifier, cube_identifier_len, mode, max_n_cell);
int ret = cube_manager_add(instance->cube_manager, cube);
if (ret < 0) {
cube_free(cube);
@@ -295,7 +295,7 @@ int fieldstat_register_hist(struct fieldstat *instance, const char *metric_name,
/* -------------------------------------------------------------------------- */
// cppcheck-suppress [constParameterPointer, unmatchedSuppression]
-int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long increment)
+int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, size_t n_fields, long long increment)
{
struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -306,11 +306,11 @@ int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric
return FS_ERR_INVALID_METRIC_ID;
}
- return cube_counter_incrby(cube, manifest, tags, n_tag, increment);
+ return cube_counter_incrby(cube, manifest, fields, n_fields, increment);
}
// cppcheck-suppress [constParameterPointer, unmatchedSuppression]
-int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
+int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, size_t n_fields, long long value)
{
struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -321,11 +321,11 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
return FS_ERR_INVALID_METRIC_ID;
}
- return cube_counter_set(cube, manifest, tags, n_tag, value);
+ return cube_counter_set(cube, manifest, fields, n_fields, value);
}
// cppcheck-suppress [constParameterPointer, unmatchedSuppression]
-int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, const char *key, size_t key_len)
+int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, size_t n_fields, const char *key, size_t key_len)
{
struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -336,11 +336,11 @@ int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, co
return FS_ERR_INVALID_METRIC_ID;
}
- return cube_hll_add(cube, manifest, tags, n_tag, key, key_len);
+ return cube_hll_add(cube, manifest, fields, n_fields, key, key_len);
}
// cppcheck-suppress [constParameterPointer, unmatchedSuppression]
-int fieldstat_hll_add_tag(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, const struct fieldstat_tag *tags_key, size_t n_tag_key)
+int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, size_t n_fields, const struct field *item, size_t item_len)
{
struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -351,11 +351,11 @@ int fieldstat_hll_add_tag(struct fieldstat *instance, int cube_id, int metric_id
return FS_ERR_INVALID_METRIC_ID;
}
- return cube_hll_add_tag(cube, manifest, tags, n_tag, tags_key, n_tag_key);
+ return cube_hll_add_tag(cube, manifest, fields, n_fields, item, item_len);
}
// cppcheck-suppress [constParameterPointer, unmatchedSuppression]
-int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
+int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *fields, size_t n_fields, long long value)
{
struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -366,7 +366,7 @@ int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id
return FS_ERR_INVALID_METRIC_ID;
}
- return cube_histogram_record(cube, manifest, tags, n_tag, value);
+ return cube_histogram_record(cube, manifest, fields, n_fields, value);
}
int fieldstat_merge(struct fieldstat *instance, const struct fieldstat *src)
@@ -444,7 +444,7 @@ void fieldstat_get_metrics(const struct fieldstat *instance, int **metric_id_out
}
}
-struct fieldstat_tag_list *fieldstat_cube_get_tags(const struct fieldstat *instance, int cube_id)
+struct field_list *fieldstat_cube_get_tags(const struct fieldstat *instance, int cube_id)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -454,36 +454,36 @@ struct fieldstat_tag_list *fieldstat_cube_get_tags(const struct fieldstat *insta
return cube_get_identifier(cube);
}
-int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, const struct fieldstat_tag_list *tags, int metric_id, long long *value)
+int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, const struct field_list *fields, int metric_id, long long *value)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
- return cube_counter_get(cube, metric_id, tags, value);
+ return cube_counter_get(cube, metric_id, fields, value);
}
-int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, const struct fieldstat_tag_list *tags, int metric_id, double *value)
+int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, const struct field_list *fields, int metric_id, double *value)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
- int ret = cube_hll_get(cube, metric_id, tags, value);
+ int ret = cube_hll_get(cube, metric_id, fields, value);
return ret;
}
-long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct fieldstat_tag_list *tags, int metric_id, double percentile)
+long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, const struct field_list *fields, int metric_id, double percentile)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
long long value;
- int ret = cube_histogram_value_at_percentile(cube, metric_id, tags, percentile, &value);
+ int ret = cube_histogram_value_at_percentile(cube, metric_id, fields, percentile, &value);
if (ret < 0) {
return ret;
}
@@ -491,21 +491,21 @@ 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 fieldstat_tag_list *tags, int metric_id, long long value)
+long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, const struct field_list *fields, int metric_id, long long value)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
long long count;
- int ret = cube_histogram_count_le_value(cube, metric_id, tags, value, &count);
+ int ret = cube_histogram_count_le_value(cube, metric_id, fields, value, &count);
if (ret < 0) {
return ret;
}
return count;
}
-void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, char **blob, size_t *blob_size)
+void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct field_list *fields, char **blob, size_t *blob_size)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -514,16 +514,16 @@ void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id
return;
}
- cube_get_serialization(cube, metric_id, tags, blob, blob_size);
+ cube_get_serialization(cube, metric_id, fields, blob, blob_size);
}
-void fieldstat_tag_list_arr_free(struct fieldstat_tag_list *tag_list, size_t n_cell)
+void fieldstat_tag_list_arr_free(struct field_list *tag_list, size_t n_cell)
{
if (tag_list == NULL) {
return;
}
for (int i = 0; i < n_cell; i++) {
- fieldstat_free_tag_array(tag_list[i].tag, tag_list[i].n_tag);
+ fieldstat_free_tag_array(tag_list[i].field, tag_list[i].n_field);
}
free(tag_list);
}
@@ -548,7 +548,7 @@ enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int
return metric->type;
}
-void fieldstat_cube_get_cells(const struct fieldstat *instance, int cube_id, struct fieldstat_tag_list **tag_list, size_t *n_cell)
+void fieldstat_cube_get_cells(const struct fieldstat *instance, int cube_id, struct field_list **tag_list, size_t *n_cell)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
if (cube == NULL) {
@@ -572,7 +572,7 @@ int fieldstat_get_used_sampling(const struct fieldstat *instance, int cube_id)
return cube_get_cell_count(cube);
}
-int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags)
+int fieldstat_find_cube(const struct fieldstat *instance, const struct field *shared_tags, size_t n_shared_tags)
{
if (instance == NULL) {
return FS_ERR_NULL_HANDLER;
@@ -586,8 +586,8 @@ int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat
return cube_id;
}
-void fieldstat_get_metric_in_cell(const struct fieldstat *instance, int cube_id, const struct fieldstat_tag_list *tags, int **metric_id_out, size_t *n_metric_out)
+void fieldstat_get_metric_in_cell(const struct fieldstat *instance, int cube_id, const struct field_list *fields, int **metric_id_out, size_t *n_metric_out)
{
const struct cube *cube = cube_manager_get_cube_by_id(instance->cube_manager, cube_id);
- return cube_get_cells_used_by_metric(cube, tags, metric_id_out, n_metric_out);
+ return cube_get_cells_used_by_metric(cube, fields, metric_id_out, n_metric_out);
} \ No newline at end of file
diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c
index 8b73b40..0e70a1c 100644
--- a/src/fieldstat_easy.c
+++ b/src/fieldstat_easy.c
@@ -114,7 +114,7 @@ void *fs_easy_output_thread(void *arg) // return void * for pthread_create check
return NULL; // return void * for pthread_create check only
}
-struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const char *name, const struct fieldstat_tag *tags, size_t n_tag) {
+struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const char *name, const struct field *fields, size_t n_field) {
if (max_thread_num <= 0) {
return NULL;
}
@@ -126,8 +126,8 @@ struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const char *name,
fse->accumulate = fieldstat_fork(fse->delta);
fse->exporter = fieldstat_json_exporter_new();
- if (tags != NULL && n_tag > 0) {
- fieldstat_json_exporter_set_global_tag(fse->exporter, tags, n_tag);
+ if (fields != NULL && n_field > 0) {
+ fieldstat_json_exporter_set_global_tag(fse->exporter, fields, n_field);
}
if (name != NULL) {
fieldstat_json_exporter_set_name(fse->exporter, name);
@@ -312,7 +312,7 @@ int fieldstat_easy_output_array_and_reset(struct fieldstat_easy *fse, char ***js
return 0;
}
-int fieldstat_easy_counter_incrby(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long increment)
+int fieldstat_easy_counter_incrby(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct field *fields, size_t n_field, long long increment)
{
if (thread_id < 0) {
return -1;
@@ -322,13 +322,13 @@ int fieldstat_easy_counter_incrby(struct fieldstat_easy *fse, int thread_id, int
}
pthread_spin_lock(&fse->fsu[thread_id].lock);
- int ret = fieldstat_counter_incrby(fse->fsu[thread_id].active, 0, metric_id, tags, n_tag, increment);
+ int ret = fieldstat_counter_incrby(fse->fsu[thread_id].active, 0, metric_id, fields, n_field, increment);
pthread_spin_unlock(&fse->fsu[thread_id].lock);
return ret;
}
-int fieldstat_easy_counter_set(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
+int fieldstat_easy_counter_set(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct field *fields, size_t n_field, long long value)
{
if (thread_id < 0) {
return -1;
@@ -338,13 +338,13 @@ int fieldstat_easy_counter_set(struct fieldstat_easy *fse, int thread_id, int me
}
pthread_spin_lock(&fse->fsu[thread_id].lock);
- int ret = fieldstat_counter_set(fse->fsu[thread_id].active, 0, metric_id, tags, n_tag, value);
+ int ret = fieldstat_counter_set(fse->fsu[thread_id].active, 0, metric_id, fields, n_field, value);
pthread_spin_unlock(&fse->fsu[thread_id].lock);
return ret;
}
-int fieldstat_easy_histogram_record(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
+int fieldstat_easy_histogram_record(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct field *fields, size_t n_field, long long value)
{
if (thread_id < 0) {
return -1;
@@ -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, tags, n_tag, value);
+ int ret = fieldstat_hist_record(fse->fsu[thread_id].active, 0, metric_id, fields, n_field, value);
pthread_spin_unlock(&fse->fsu[thread_id].lock);
return ret;
diff --git a/src/tags/heavy_keeper.c b/src/tags/heavy_keeper.c
index a7c77c7..5f2b197 100644
--- a/src/tags/heavy_keeper.c
+++ b/src/tags/heavy_keeper.c
@@ -597,7 +597,7 @@ int heavy_keeper_add(struct heavy_keeper *heavy_keeper, const char *key, size_t
// If a key is not in the min-heap, then the estimated key size should be no larger than nmin.
// or if the min-heap is not full(nmin == 0), every key should be taken into account, so of course it should be added.
// in neither case, bucket->count > nMin && not_in_sorted_set happen.
- // The keys whose counts are both larger than nmin and not in min-heap must have the same xxhash value, and its FP stored in bucket represents another tag,
+ // The keys whose counts are both larger than nmin and not in min-heap must have the same xxhash value, and its FP stored in bucket represents another field,
// In this case, the sketch won't be updated. This key is expected to be taken into account in another array,
// where its FP is different from the one it should collided with, so that element keys won't be missed.
if (not_in_sorted_set) {
@@ -638,7 +638,7 @@ int heavy_keeper_add(struct heavy_keeper *heavy_keeper, const char *key, size_t
if (maxv > old_cnt) {
sorted_set_incrby_count(summary, key, key_len, maxv - old_cnt);
}
- return 1; // no popped, but the tag definitely exists in the sorted set
+ return 1; // no popped, but the exdata definitely exists in the sorted set
}
}
@@ -759,7 +759,7 @@ void heavy_keeper_merge(struct heavy_keeper *dest, const struct heavy_keeper *sr
for (int i = 0; i < size_src; i++) {
const heap_entry *entry = sorted_set_find_entry(new_rec, key_arr[i], key_lens[i]);
- if (entry != NULL) { // the tag is in both dest and src, so has been processed in the previous loop. The reason why no need to sum up result is that merged sketch already keeps its summed up count
+ if (entry != NULL) { // the key is in both dest and src, so has been processed in the previous loop. The reason why no need to sum up result is that merged sketch already keeps its summed up count
void *exdata_new = sorted_set_entry_get_data(entry)->exdata;
void *exdata_src = exdatas_src[i];
dest->merge_fn(exdata_new, exdata_src);