summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-02 11:07:54 +0800
committerchenzizhan <[email protected]>2024-07-02 11:07:54 +0800
commit1c77a52523b730fe2dc3a81f6531e7b3f08a232b (patch)
treeb1d4cf31a611390ff8fbf04973b575365af3a471 /src
parent46935eec3e986fd0f392b9c6356a52e2a865feef (diff)
renames
Diffstat (limited to 'src')
-rw-r--r--src/fieldstat.c191
-rw-r--r--src/fieldstat_easy.c28
-rw-r--r--src/metrics/metric.c150
-rw-r--r--src/metrics/st_hyperloglog.c14
-rw-r--r--src/metrics/st_hyperloglog.h4
-rw-r--r--src/tags/heavy_keeper.h2
-rw-r--r--src/tags/my_ut_hash.c24
7 files changed, 208 insertions, 205 deletions
diff --git a/src/fieldstat.c b/src/fieldstat.c
index eac8e4c..b090c5f 100644
--- a/src/fieldstat.c
+++ b/src/fieldstat.c
@@ -18,7 +18,7 @@
#define DEFAULT_N_CUBE 128
-struct exdata { // TODO: 重命名成cell
+struct cell {
struct metric **metrics;
size_t valid_metric_arr_len; // TODO: 单纯就是每次超过就realloc,使用UTARRAY
size_t max_n_metric;
@@ -31,13 +31,13 @@ union cell_manager {
}; // todo: 移到cube里了, 名字叫cell tabel
-struct fs_cube { // TODO rename 到 cube
+struct cube {
enum sampling_mode sampling_mode;
union cell_manager cells;
size_t max_n_cell;
// the key of cube is the combination of shared tags
- struct fieldstat_tag *shared_tags; // TODO: CUBE IDENTIFIER
+ struct fieldstat_tag *cube_identifier;
size_t n_shared_tags;
struct tag_hash_key *key_tag; // TODO: 删了它
// const char *key_tag;
@@ -62,7 +62,7 @@ struct exdata_new_args {
};
struct fieldstat {
- struct fs_cube **cube;
+ struct cube **cube;
unsigned long *cube_version; // increase from 0 every time the cube is deleted
unsigned long cell_version; // increase from 0 every time fieldstat_reset is called
size_t valid_cube_arr_length;
@@ -142,42 +142,42 @@ struct metric_name_id_map *name_id_map_copy(struct metric_name_id_map *map)
return map_dup;
}
-void add_metric_to_exdata(struct exdata *exdata, struct metric *metric, int metric_id)
+void add_metric_to_cell(struct cell *cell, struct metric *metric, int metric_id)
{
- if (metric_id >= exdata->max_n_metric) {
- exdata->max_n_metric *= 2;
- exdata->metrics = realloc(exdata->metrics, sizeof(struct metric *) * exdata->max_n_metric);
- memset(exdata->metrics + exdata->valid_metric_arr_len, 0, sizeof(struct metric *) * (exdata->max_n_metric - exdata->valid_metric_arr_len));
+ if (metric_id >= cell->max_n_metric) {
+ cell->max_n_metric *= 2;
+ cell->metrics = realloc(cell->metrics, sizeof(struct metric *) * cell->max_n_metric);
+ memset(cell->metrics + cell->valid_metric_arr_len, 0, sizeof(struct metric *) * (cell->max_n_metric - cell->valid_metric_arr_len));
}
- exdata->metrics[metric_id] = metric;
- if (metric_id >= exdata->valid_metric_arr_len) {
- exdata->valid_metric_arr_len = metric_id + 1;
+ cell->metrics[metric_id] = metric;
+ if (metric_id >= cell->valid_metric_arr_len) {
+ cell->valid_metric_arr_len = metric_id + 1;
}
}
-struct metric *find_metric_in_exdata(const struct exdata *exdata, int metric_id)
+struct metric *find_metric_in_cell(const struct cell *cell, int metric_id)
{
- if (metric_id >= exdata->valid_metric_arr_len) {
+ if (metric_id >= cell->valid_metric_arr_len) {
return NULL;
}
- return exdata->metrics[metric_id];
+ return cell->metrics[metric_id];
}
-struct metric *construct_or_find_metric_to_exdata(struct fieldstat *instance, struct exdata *exdata, int metric_id)
+struct metric *add_or_find_metric_in_cell(struct fieldstat *instance, struct cell *cell, int metric_id)
{
- struct metric *metric = find_metric_in_exdata(exdata, metric_id);
+ struct metric *metric = find_metric_in_cell(cell, metric_id);
if (metric != NULL) {
return metric;
}
metric = metric_fork(instance->metric_masters[metric_id]);
- add_metric_to_exdata(exdata, metric, metric_id);
+ add_metric_to_cell(cell, metric, metric_id);
return metric;
}
-struct exdata *exdata_new(const struct exdata_new_args *args) {
- struct exdata *pthis = malloc(sizeof(struct exdata));
+struct cell *cell_new(const struct exdata_new_args *args) {
+ struct cell *pthis = malloc(sizeof(struct cell));
pthis->metrics = calloc(DEFAULT_N_METRIC, sizeof(struct metric *));
pthis->valid_metric_arr_len = 0;
pthis->max_n_metric = DEFAULT_N_METRIC;
@@ -188,7 +188,7 @@ struct exdata *exdata_new(const struct exdata_new_args *args) {
return pthis;
}
-void exdata_free(struct exdata *pthis) {
+void cell_free(struct cell *pthis) {
for (size_t i = 0; i < pthis->valid_metric_arr_len; i++) {
metric_free(pthis->metrics[i]);
}
@@ -203,8 +203,8 @@ void exdata_free(struct exdata *pthis) {
free(pthis);
}
-struct exdata *exdata_copy(const struct exdata *src) {
- struct exdata *pthis = malloc(sizeof(struct exdata));
+struct cell *cell_copy(const struct cell *src) {
+ struct cell *pthis = malloc(sizeof(struct cell));
pthis->metrics = calloc(src->max_n_metric, sizeof(struct metric *));
pthis->valid_metric_arr_len = src->valid_metric_arr_len;
pthis->max_n_metric = src->max_n_metric;
@@ -223,7 +223,7 @@ struct exdata *exdata_copy(const struct exdata *src) {
return pthis;
}
-void exdata_reset(struct exdata *pthis) {
+void cell_reset(struct cell *pthis) {
for (size_t i = 0; i < pthis->valid_metric_arr_len; i++) {
if (pthis->metrics[i] == NULL) {
continue;
@@ -232,18 +232,18 @@ void exdata_reset(struct exdata *pthis) {
}
}
-void exdata_merge(struct exdata *dest, const struct exdata *src) {
+void cell_merge(struct cell *dest, const struct cell *src) {
for (size_t i = 0; i < src->valid_metric_arr_len; i++) {
const struct metric *metric_src = src->metrics[i];
if (metric_src == NULL) {
continue;
}
- struct metric *metric_dst = find_metric_in_exdata(dest, i);
+ struct metric *metric_dst = find_metric_in_cell(dest, i);
assert(strcmp(metric_get_name(metric_src), metric_get_name(metric_dst)) == 0);
if (metric_dst == NULL) {
metric_dst = metric_copy(metric_src);
- add_metric_to_exdata(dest, metric_dst, i);
+ add_metric_to_cell(dest, metric_dst, i);
} else {
metric_merge(metric_dst, metric_src);
}
@@ -251,32 +251,35 @@ void exdata_merge(struct exdata *dest, const struct exdata *src) {
}
void *exdata_new_i(void *arg) {
- return exdata_new((struct exdata_new_args *)arg);
+ return cell_new((struct exdata_new_args *)arg);
}
void exdata_free_i(void *exdata) {
- exdata_free((struct exdata *)exdata);
+ cell_free((struct cell *)exdata);
}
void exdata_reset_i(void *exdata) {
- exdata_reset((struct exdata *)exdata);
+ cell_reset((struct cell *)exdata);
}
void exdata_merge_i(void *dest, void *src) {
- exdata_merge((struct exdata *)dest, (struct exdata *)src);
+ cell_merge((struct cell *)dest, (struct cell *)src);
}
void *exdata_copy_i(void *exdata) {
- return exdata_copy((struct exdata *)exdata);
+ return cell_copy((struct cell *)exdata);
}
+/* -------------------------------------------------------------------------- */
+/* fieldstat */
+/* -------------------------------------------------------------------------- */
struct fieldstat *fieldstat_new()
{
struct fieldstat *instance = calloc(1, sizeof(struct fieldstat));
instance->max_n_cube = DEFAULT_N_CUBE;
- instance->cube = calloc(instance->max_n_cube, sizeof(struct fs_cube *));
+ instance->cube = calloc(instance->max_n_cube, sizeof(struct cube *));
instance->cube_version = calloc(instance->max_n_cube, sizeof(unsigned long));
instance->max_n_metric_master = DEFAULT_N_METRIC;
@@ -316,7 +319,7 @@ void fieldstat_reset(struct fieldstat *instance)
return;
}
for (size_t i = 0; i < instance->valid_cube_arr_length; i++) {
- struct fs_cube *cube = instance->cube[i];
+ struct cube *cube = instance->cube[i];
if (cube == NULL) {
continue;
}
@@ -350,7 +353,7 @@ int fieldstat_destroy_cube(struct fieldstat *instance, int cube_id)
return FS_ERR_INVALID_CUBE_ID;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
cube_manager_delete(instance->shared_tag_cube_manager, cube->key_tag);
fieldstat_cube_free(instance, cube_id);
@@ -391,13 +394,13 @@ void fieldstat_free_tag_array(struct fieldstat_tag *tags, size_t n_tags)
free(tags);
}
-void add_cube_to_position(struct fieldstat *instance, struct fs_cube *cube, int cube_id)
+void add_cube_to_position(struct fieldstat *instance, struct cube *cube, int cube_id)
{
if (cube_id >= instance->max_n_cube) {
instance->max_n_cube *= 2;
- struct fs_cube **old_cube_arr = instance->cube;
- instance->cube = calloc(instance->max_n_cube, sizeof(struct fs_cube *));
- memcpy(instance->cube, old_cube_arr, sizeof(struct fs_cube *) * instance->valid_cube_arr_length);
+ struct cube **old_cube_arr = instance->cube;
+ instance->cube = calloc(instance->max_n_cube, sizeof(struct cube *));
+ memcpy(instance->cube, old_cube_arr, sizeof(struct cube *) * instance->valid_cube_arr_length);
free(old_cube_arr);
unsigned long *old_ver_arr = instance->cube_version;
@@ -411,7 +414,7 @@ void add_cube_to_position(struct fieldstat *instance, struct fs_cube *cube, int
}
}
-int fieldstat_append_cube_to_instance(struct fieldstat *instance, struct fs_cube *cube)
+int fieldstat_append_cube_to_instance(struct fieldstat *instance, struct cube *cube)
{
for (int i = 0; i < instance->valid_cube_arr_length; i++) {
if (instance->cube[i] == NULL) {
@@ -427,16 +430,16 @@ int fieldstat_append_cube_to_instance(struct fieldstat *instance, struct fs_cube
return cube_id;
}
-struct fs_cube *fieldstat_cube_info_init(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
+struct cube *fieldstat_cube_info_init(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
{
- struct fs_cube *cube = calloc(1, sizeof(struct fs_cube));
+ struct cube *cube = calloc(1, sizeof(struct cube));
cube->sampling_mode = mode;
if (n_tag == 0) {
- cube->shared_tags = NULL;
+ cube->cube_identifier = NULL;
} else {
- cube->shared_tags = malloc(sizeof(struct fieldstat_tag) * n_tag);
- tag_array_copy(cube->shared_tags, shared_tags, n_tag);
+ cube->cube_identifier = malloc(sizeof(struct fieldstat_tag) * n_tag);
+ tag_array_copy(cube->cube_identifier, shared_tags, n_tag);
}
cube->n_shared_tags = n_tag;
@@ -450,9 +453,9 @@ struct fs_cube *fieldstat_cube_info_init(const struct fieldstat_tag *shared_tags
return cube;
}
-struct fs_cube *fieldstat_cube_new(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
+struct cube *fieldstat_cube_new(const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell)
{
- struct fs_cube *cube = fieldstat_cube_info_init(shared_tags, n_tag, mode, max_n_cell);
+ struct cube *cube = fieldstat_cube_info_init(shared_tags, n_tag, mode, max_n_cell);
switch (mode)
{
@@ -495,7 +498,7 @@ int fieldstat_create_cube(struct fieldstat *instance, const struct fieldstat_tag
return FS_ERR_INVALID_KEY;
}
- struct fs_cube *cube = fieldstat_cube_new(shared_tags, n_tag, mode, max_n_cell);
+ struct cube *cube = fieldstat_cube_new(shared_tags, n_tag, mode, max_n_cell);
int cube_id = fieldstat_append_cube_to_instance(instance, cube);
@@ -504,7 +507,7 @@ int fieldstat_create_cube(struct fieldstat *instance, const struct fieldstat_tag
void fieldstat_cube_free_contents(struct fieldstat *instance, int cube_id)
{
- struct fs_cube *cube = instance->cube[cube_id];
+ struct cube *cube = instance->cube[cube_id];
switch (cube->sampling_mode)
{
@@ -519,7 +522,7 @@ void fieldstat_cube_free_contents(struct fieldstat *instance, int cube_id)
break;
}
- fieldstat_free_tag_array(cube->shared_tags, cube->n_shared_tags);
+ fieldstat_free_tag_array(cube->cube_identifier, cube->n_shared_tags);
tag_hash_key_free(cube->key_tag);
free(cube);
@@ -549,7 +552,7 @@ int fieldstat_cube_set_primary_metric(struct fieldstat *instance, int cube_id, i
if (cube_id < 0 || cube_id >= instance->valid_cube_arr_length) {
return FS_ERR_INVALID_CUBE_ID;
}
- struct fs_cube *cube = instance->cube[cube_id];
+ struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
@@ -688,9 +691,9 @@ int check_before_add(const struct fieldstat *instance, int cube_id, int metric_i
return FS_OK;
}
-struct exdata *find_or_add_exdata_comprehensive(struct tag_map *comprehensive, const char *key, size_t key_len, struct exdata_new_args *args)
+struct cell *find_or_add_exdata_comprehensive(struct tag_map *comprehensive, const char *key, size_t key_len, struct exdata_new_args *args)
{
- struct exdata *cell_data = tag_map_get0_exdata(comprehensive, key, key_len);
+ struct cell *cell_data = tag_map_get0_exdata(comprehensive, key, key_len);
if (cell_data == NULL) {
int tmp_ret = tag_map_add(comprehensive, key, key_len, args);
if (tmp_ret != 1) {
@@ -708,7 +711,7 @@ int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric
return ret;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
char *tag_in_string;
size_t tag_len;
@@ -718,7 +721,7 @@ int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric
args.tags = tags;
args.n_tags = n_tag;
- struct exdata *cell_data = NULL;
+ struct cell *cell_data = NULL;
switch (cube->sampling_mode)
{
case SAMPLING_MODE_TOPK:
@@ -763,7 +766,7 @@ int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric
break;
}
- struct metric *metric = construct_or_find_metric_to_exdata(instance, cell_data, metric_id);
+ struct metric *metric = add_or_find_metric_in_cell(instance, cell_data, metric_id);
metric_counter_incrby(metric, increment);
free(tag_in_string);
@@ -776,7 +779,7 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
if (ret != FS_OK) {
return ret;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
char *tag_in_string;
size_t tag_len;
build_dynamic_cell_key(tags, n_tag, &tag_in_string, &tag_len);
@@ -785,7 +788,7 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
args.tags = tags;
args.n_tags = n_tag;
- struct exdata *cell_data = NULL;
+ struct cell *cell_data = NULL;
switch (cube->sampling_mode)
{
case SAMPLING_MODE_TOPK: {
@@ -803,7 +806,7 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
long long current_count = 0;
cell_data = heavy_keeper_get0_exdata(cube->cells.topk, tag_in_string, tag_len);
if (cell_data != NULL) {
- const struct metric *tmp_metric = find_metric_in_exdata(cell_data, metric_id);
+ const struct metric *tmp_metric = find_metric_in_cell(cell_data, metric_id);
if (tmp_metric != NULL) {
current_count = metric_counter_get(tmp_metric);
}
@@ -832,7 +835,7 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
break;
}
assert(cell_data != NULL); // to mute the warning
- struct metric *metric = construct_or_find_metric_to_exdata(instance, cell_data, metric_id);
+ struct metric *metric = add_or_find_metric_in_cell(instance, cell_data, metric_id);
free(tag_in_string);
metric_counter_set(metric, value);
return FS_OK;
@@ -856,8 +859,8 @@ int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, co
args.tags = tags;
args.n_tags = n_tag;
- struct exdata *cell_data = find_or_add_exdata_comprehensive(instance->cube[cube_id]->cells.comprehensive, tag_in_string, tag_len, &args);
- struct metric *metric = construct_or_find_metric_to_exdata(instance, cell_data, metric_id);
+ struct cell *cell_data = find_or_add_exdata_comprehensive(instance->cube[cube_id]->cells.comprehensive, tag_in_string, tag_len, &args);
+ struct metric *metric = add_or_find_metric_in_cell(instance, cell_data, metric_id);
metric_hll_add(metric, key, key_len);
free(tag_in_string);
@@ -883,12 +886,12 @@ int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id
args.tags = tags;
args.n_tags = n_tag;
- struct exdata *cell_data = find_or_add_exdata_comprehensive(instance->cube[cube_id]->cells.comprehensive, tag_in_string, tag_len, &args);
+ struct cell *cell_data = find_or_add_exdata_comprehensive(instance->cube[cube_id]->cells.comprehensive, tag_in_string, tag_len, &args);
free(tag_in_string);
// // metric_histogram_record may fail, unlike the other add functions.
- struct metric *metric = find_metric_in_exdata(cell_data, metric_id);
+ struct metric *metric = find_metric_in_cell(cell_data, metric_id);
if (metric != NULL) {
ret = metric_histogram_record(metric, value);
if (ret < 0) {
@@ -901,7 +904,7 @@ int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id
metric_free(metric);
return FS_ERR_INVALID_PARAM;
}
- add_metric_to_exdata(cell_data, metric, metric_id);
+ add_metric_to_cell(cell_data, metric, metric_id);
}
return FS_OK;
@@ -911,9 +914,9 @@ int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id
/* merge */
/* -------------------------------------------------------------------------- */
-struct fs_cube *fieldstat_cube_copy(const struct fs_cube *cube)
+struct cube *fieldstat_cube_copy(const struct cube *cube)
{
- struct fs_cube *cube_dup = fieldstat_cube_info_init(cube->shared_tags, cube->n_shared_tags, cube->sampling_mode, cube->max_n_cell);
+ struct cube *cube_dup = fieldstat_cube_info_init(cube->cube_identifier, cube->n_shared_tags, cube->sampling_mode, cube->max_n_cell);
cube_dup->primary_metric_id = cube->primary_metric_id;
switch (cube->sampling_mode)
@@ -932,7 +935,7 @@ struct fs_cube *fieldstat_cube_copy(const struct fs_cube *cube)
return cube_dup;
}
-void fieldstat_cube_merge(struct fs_cube *dest, const struct fs_cube *src)
+void fieldstat_cube_merge(struct cube *dest, const struct cube *src)
{
assert(dest->sampling_mode == src->sampling_mode);
@@ -979,7 +982,7 @@ int fieldstat_merge(struct fieldstat *instance, struct fieldstat *src)
const struct cube_manager *tag_cube_id_map = instance->shared_tag_cube_manager;
int ret = 0;
for (int i = 0; i < n_cube_src; i++) {
- const struct fs_cube *cube_src = src->cube[i];
+ const struct cube *cube_src = src->cube[i];
if (cube_src == NULL) {
continue;
}
@@ -987,10 +990,10 @@ int fieldstat_merge(struct fieldstat *instance, struct fieldstat *src)
const struct tag_hash_key *shared_tag_key_src = cube_src->key_tag;
int cube_id_tmp = cube_manager_find(tag_cube_id_map, shared_tag_key_src);
if (cube_id_tmp == -1) {
- struct fs_cube *copied_cube = fieldstat_cube_copy(cube_src);
+ struct cube *copied_cube = fieldstat_cube_copy(cube_src);
fieldstat_append_cube_to_instance(instance, copied_cube);
} else {
- struct fs_cube *cube_dst = instance->cube[cube_id_tmp];
+ struct cube *cube_dst = instance->cube[cube_id_tmp];
if (cube_dst->sampling_mode != cube_src->sampling_mode) {
ret = FS_ERR_INVALID_PARAM;
continue;
@@ -1007,8 +1010,8 @@ int fieldstat_merge(struct fieldstat *instance, struct fieldstat *src)
}
// only copy the cube configurations, leave the cells empty
-struct fs_cube *fieldstat_cube_fork(const struct fs_cube *cube) {
- struct fs_cube *ret = fieldstat_cube_new(cube->shared_tags, cube->n_shared_tags, cube->sampling_mode, cube->max_n_cell);
+struct cube *fieldstat_cube_fork(const struct cube *cube) {
+ struct cube *ret = fieldstat_cube_new(cube->cube_identifier, cube->n_shared_tags, cube->sampling_mode, cube->max_n_cell);
ret->primary_metric_id = cube->primary_metric_id;
return ret;
@@ -1024,9 +1027,9 @@ struct fieldstat *fieldstat_fork(const struct fieldstat *instance)
new_instance->valid_cube_arr_length = instance->valid_cube_arr_length;
new_instance->max_n_cube = instance->max_n_cube;
- new_instance->cube = calloc(new_instance->max_n_cube, sizeof(struct fs_cube *));
+ new_instance->cube = calloc(new_instance->max_n_cube, sizeof(struct cube *));
for (size_t i = 0; i < new_instance->valid_cube_arr_length; i++) {
- const struct fs_cube *cube = instance->cube[i];
+ const struct cube *cube = instance->cube[i];
if (cube == NULL) {
continue;
}
@@ -1094,8 +1097,8 @@ int fieldstat_calibrate(const struct fieldstat *master, struct fieldstat *replic
}
if (replica->max_n_cube < master->max_n_cube) {
- replica->cube = (struct fs_cube **)realloc(replica->cube, sizeof(struct fs_cube *) * master->max_n_cube);
- memset(replica->cube + replica->max_n_cube, 0, sizeof(struct fs_cube *) * (master->max_n_cube - replica->max_n_cube));
+ replica->cube = (struct cube **)realloc(replica->cube, sizeof(struct cube *) * master->max_n_cube);
+ memset(replica->cube + replica->max_n_cube, 0, sizeof(struct cube *) * (master->max_n_cube - replica->max_n_cube));
replica->cube_version = (unsigned long *)realloc(replica->cube_version, sizeof(unsigned long) * master->max_n_cube);
memset(replica->cube_version + replica->max_n_cube, 0, sizeof(unsigned long) * (master->max_n_cube - replica->max_n_cube));
replica->max_n_cube = master->max_n_cube;
@@ -1105,8 +1108,8 @@ int fieldstat_calibrate(const struct fieldstat *master, struct fieldstat *replic
size_t len_replica = replica->valid_cube_arr_length;
size_t longer_arr_len = len_master > len_replica ? len_master : len_replica;
for (size_t i = 0; i < longer_arr_len; i++) {
- const struct fs_cube *cube_master = i >= len_master ? NULL : master->cube[i];
- const struct fs_cube *cube_target = i >= len_replica ? NULL : replica->cube[i];
+ const struct cube *cube_master = i >= len_master ? NULL : master->cube[i];
+ const struct cube *cube_target = i >= len_replica ? NULL : replica->cube[i];
if (cube_master == NULL && cube_target == NULL) {
continue;
@@ -1116,7 +1119,7 @@ int fieldstat_calibrate(const struct fieldstat *master, struct fieldstat *replic
continue;
}
if (cube_master != NULL && cube_target == NULL) {
- struct fs_cube *cube_dup = fieldstat_cube_fork(cube_master);
+ struct cube *cube_dup = fieldstat_cube_fork(cube_master);
add_cube_to_position(replica, cube_dup, i);
continue;
}
@@ -1126,7 +1129,7 @@ int fieldstat_calibrate(const struct fieldstat *master, struct fieldstat *replic
}
fieldstat_cube_free_contents(replica, i);
- struct fs_cube *cube_dup = fieldstat_cube_fork(cube_master);
+ struct cube *cube_dup = fieldstat_cube_fork(cube_master);
add_cube_to_position(replica, cube_dup, i);
}
@@ -1153,7 +1156,7 @@ void fieldstat_get_cubes(const struct fieldstat *instance, int **cube_ids, int *
int *tmp_ids = (int *)malloc(sizeof(int) * instance->valid_cube_arr_length);
for (int i = 0; i < instance->valid_cube_arr_length; i++) {
- const struct fs_cube *tmp_cube = instance->cube[i];
+ const struct cube *tmp_cube = instance->cube[i];
if (tmp_cube == NULL) {
continue;
}
@@ -1197,7 +1200,7 @@ struct fieldstat_tag_list *fieldstat_get_shared_tags(const struct fieldstat *ins
if (instance == NULL || cube_id >= instance->valid_cube_arr_length || cube_id < 0) {
return NULL;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
return NULL;
}
@@ -1212,14 +1215,14 @@ struct fieldstat_tag_list *fieldstat_get_shared_tags(const struct fieldstat *ins
tag_list->tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * cube->n_shared_tags);
tag_list->n_tag = cube->n_shared_tags;
- tag_array_copy(tag_list->tag, cube->shared_tags, cube->n_shared_tags);
+ tag_array_copy(tag_list->tag, cube->cube_identifier, cube->n_shared_tags);
return tag_list;
}
-const struct exdata *get_exdata_by_tag_list(const struct fs_cube *cube, const struct fieldstat_tag_list *tags)
+const struct cell *get_exdata_by_tag_list(const struct cube *cube, const struct fieldstat_tag_list *tags)
{
- const struct exdata *ret = NULL;
+ const struct cell *ret = NULL;
char *tag_in_string;
size_t tag_len;
build_dynamic_cell_key(tags->tag, tags->n_tag, &tag_in_string, &tag_len);
@@ -1247,13 +1250,13 @@ const struct metric *get_metric_by_tag_list(const struct fieldstat *instance, in
*ret = FS_ERR_INVALID_CUBE_ID;
return NULL;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
*ret = FS_ERR_INVALID_CUBE_ID;
return NULL;
}
- const struct exdata *data = get_exdata_by_tag_list(cube, tags);
+ const struct cell *data = get_exdata_by_tag_list(cube, tags);
if (data == NULL) {
*ret = FS_ERR_INVALID_TAG;
@@ -1385,12 +1388,12 @@ void fieldstat_get_cells_used_by_cube(const struct fieldstat *instance, int cube
if (instance == NULL || cube_id < 0 || cube_id >= instance->valid_cube_arr_length) {
return;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
return;
}
- struct exdata **cell_datas = NULL;
+ struct cell **cell_datas = NULL;
size_t n_cell_tmp = 0;
switch (cube->sampling_mode) {
case SAMPLING_MODE_COMPREHENSIVE:
@@ -1414,7 +1417,7 @@ void fieldstat_get_cells_used_by_cube(const struct fieldstat *instance, int cube
*n_cell = n_cell_tmp;
for (int i = 0; i < n_cell_tmp; i++) {
- struct exdata *cell_data = cell_datas[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) {
@@ -1436,7 +1439,7 @@ int fieldstat_get_used_sampling(const struct fieldstat *instance, int cube_id)
if (cube_id < 0 || cube_id >= instance->valid_cube_arr_length) {
return FS_ERR_INVALID_CUBE_ID;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
@@ -1475,7 +1478,7 @@ int fieldstat_get_cube_mode(const struct fieldstat *instance, int cube_id, enum
if (cube_id < 0 || cube_id >= instance->valid_cube_arr_length) {
return FS_ERR_INVALID_CUBE_ID;
}
- const struct fs_cube *cube = instance->cube[cube_id];
+ const struct cube *cube = instance->cube[cube_id];
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
@@ -1492,7 +1495,7 @@ int fieldstat_get_cube_mode(const struct fieldstat *instance, int cube_id, enum
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)
{
- const struct exdata *cell_data = get_exdata_by_tag_list(instance->cube[cube_id], tags);
+ const struct cell *cell_data = get_exdata_by_tag_list(instance->cube[cube_id], tags);
if (cell_data == NULL) {
*metric_id_out = NULL;
*n_metric_out = 0;
diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c
index 9319a41..8b73b40 100644
--- a/src/fieldstat_easy.c
+++ b/src/fieldstat_easy.c
@@ -250,35 +250,35 @@ struct timeval get_current_timestamp()
struct fieldstat *merge_all_instance(struct fieldstat_easy *fse)
{
- struct fieldstat *dst = fieldstat_new();
+ struct fieldstat *dest = fieldstat_new();
// collect all the data recorded since last passive output, if passive output happened. Otherwise, its the data since the program started.
for (int i = 0; i < fse->max_thread_num; i++) {
pthread_spin_lock(&fse->fsu[i].lock);
- fieldstat_merge(dst, fse->fsu[i].active);
+ fieldstat_merge(dest, fse->fsu[i].active);
pthread_spin_unlock(&fse->fsu[i].lock);
}
// add the outputted data
if (fse->output_thread_running) {
pthread_spin_lock(&fse->outputting_lock);
- fieldstat_merge(dst, fse->accumulate);
+ fieldstat_merge(dest, fse->accumulate);
pthread_spin_unlock(&fse->outputting_lock);
}
- return dst;
+ return dest;
}
// output an json string for accumulated data
void fieldstat_easy_output(struct fieldstat_easy *fse, char **buff, size_t *buff_len)
{
- struct fieldstat *dst = merge_all_instance(fse);
+ struct fieldstat *dest = merge_all_instance(fse);
struct timeval timestamp = get_current_timestamp();
- *buff = fieldstat_json_exporter_export(fse->exporter, dst, &timestamp);
+ *buff = fieldstat_json_exporter_export(fse->exporter, dest, &timestamp);
if (*buff == NULL) {
*buff = strdup("[]");
}
- fieldstat_free(dst);
+ fieldstat_free(dest);
*buff_len = strlen(*buff);
}
@@ -286,10 +286,10 @@ void fieldstat_easy_output(struct fieldstat_easy *fse, char **buff, size_t *buff
void fieldstat_easy_output_array(struct fieldstat_easy *fse, char ***json_objects, size_t *n_object)
{
struct timeval timestamp = get_current_timestamp();
- struct fieldstat *dst = merge_all_instance(fse);
+ struct fieldstat *dest = merge_all_instance(fse);
- fieldstat_json_exporter_export_array(fse->exporter, dst, &timestamp, json_objects, n_object);
- fieldstat_free(dst);
+ fieldstat_json_exporter_export_array(fse->exporter, dest, &timestamp, json_objects, n_object);
+ fieldstat_free(dest);
}
int fieldstat_easy_output_array_and_reset(struct fieldstat_easy *fse, char ***json_objects, size_t *n_object)
@@ -299,15 +299,15 @@ int fieldstat_easy_output_array_and_reset(struct fieldstat_easy *fse, char ***js
return -1;
}
- struct fieldstat *dst = fieldstat_new();
+ struct fieldstat *dest = fieldstat_new();
for (int i = 0; i < fse->max_thread_num; i++) {
rcu_reclaim_handler(fse->fsu + i);
- fieldstat_merge(dst, fse->fsu[i].read_only);
+ fieldstat_merge(dest, fse->fsu[i].read_only);
}
struct timeval timestamp = get_current_timestamp();
- fieldstat_json_exporter_export_array(fse->exporter, dst, &timestamp, json_objects, n_object);
- fieldstat_free(dst);
+ fieldstat_json_exporter_export_array(fse->exporter, dest, &timestamp, json_objects, n_object);
+ fieldstat_free(dest);
return 0;
}
diff --git a/src/metrics/metric.c b/src/metrics/metric.c
index b58e229..44e8f39 100644
--- a/src/metrics/metric.c
+++ b/src/metrics/metric.c
@@ -34,23 +34,23 @@ struct metric_parameter {
};
};
-struct metric_info { // TODO: 别用info 这个词,用manifest。另外新建一个这样的结构体。
+struct metric_manifest {
int id;
char *name;
struct metric_parameter *paras;
enum metric_type type;
};
-typedef struct metric_measure_data *(*metric_func_new)(const struct metric_parameter *);
-typedef void (*metric_func_del)(struct metric_measure_data *);
-typedef int (*metric_func_merge)(struct metric_measure_data *, const struct metric_measure_data *);
-typedef int (*metric_func_copy)(struct metric_measure_data *, const struct metric_measure_data *);
-typedef void (*metric_func_serialize)(const struct metric_measure_data *, char **/*blob*/, size_t */*blob_size*/);
-typedef struct metric_measure_data * (*metric_func_deserialize)(const char *, size_t );
-typedef void (*metric_func_reset)(struct metric_measure_data *);
+typedef struct metric_data *(*metric_func_new)(const struct metric_parameter *);
+typedef void (*metric_func_free)(struct metric_data *);
+typedef int (*metric_func_merge)(struct metric_data *, const struct metric_data *);
+typedef int (*metric_func_copy)(struct metric_data *, const struct metric_data *);
+typedef void (*metric_func_serialize)(const struct metric_data *, char **/*blob*/, size_t */*blob_size*/);
+typedef struct metric_data * (*metric_func_deserialize)(const char *, size_t );
+typedef void (*metric_func_reset)(struct metric_data *);
struct metric_scheme {
metric_func_new new;
- metric_func_del del; // TODO: del -> free
+ metric_func_free free;
metric_func_merge merge;
metric_func_copy copy;
metric_func_serialize serialize;
@@ -58,7 +58,7 @@ struct metric_scheme {
metric_func_reset reset;
};
-struct metric_measure_data { // TODO: 改成data 就行
+struct metric_data {
union {
struct metric_counter_or_gauge *counter;
struct ST_hyperloglog *hll;
@@ -68,8 +68,8 @@ struct metric_measure_data { // TODO: 改成data 就行
struct metric {
const struct metric_scheme *scheme;
- struct metric_info *info;
- struct metric_measure_data *data_array; // todo: 重命名,data
+ struct metric_manifest *info;
+ struct metric_data *data;
};
/* -------------------------------------------------------------------------- */
@@ -78,22 +78,22 @@ struct metric {
/* --------------------------------- counter -------------------------------- */
-struct metric_measure_data *metric_scheme_counter_new(const struct metric_parameter *_para)
+struct metric_data *metric_scheme_counter_new(const struct metric_parameter *_para)
{
- struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *data = (struct metric_data *)malloc(sizeof(struct metric_data));
struct metric_counter_or_gauge *counter = (struct metric_counter_or_gauge *)malloc(sizeof(struct metric_counter_or_gauge));
data->counter = counter;
counter->value = 0;
return data;
}
-static void metric_scheme_counter_free(struct metric_measure_data *data)
+static void metric_scheme_counter_free(struct metric_data *data)
{
free(data->counter);
free(data);
}
-static void metric_scheme_counter_serialize(const struct metric_measure_data *data, char **blob, size_t *blob_size)
+static void metric_scheme_counter_serialize(const struct metric_data *data, char **blob, size_t *blob_size)
{
const struct metric_counter_or_gauge *counter = data->counter;
struct fs_reader *reader = fs_reader_new();
@@ -103,7 +103,7 @@ static void metric_scheme_counter_serialize(const struct metric_measure_data *da
fs_reader_finalize(reader, blob, blob_size);
}
-static int metric_scheme_counter_merge(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_counter_merge(struct metric_data *pthis, const struct metric_data *from)
{
struct metric_counter_or_gauge *counter = pthis->counter;
const struct metric_counter_or_gauge *from_counter = from->counter;
@@ -112,7 +112,7 @@ static int metric_scheme_counter_merge(struct metric_measure_data *pthis, const
return 0;
}
-static int metric_scheme_counter_copy(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_counter_copy(struct metric_data *pthis, const struct metric_data *from)
{
struct metric_counter_or_gauge *counter = pthis->counter;
const struct metric_counter_or_gauge *from_counter = from->counter;
@@ -120,10 +120,10 @@ static int metric_scheme_counter_copy(struct metric_measure_data *pthis, const s
return 0;
}
-struct metric_measure_data *metric_scheme_counter_deserialize(const char *blob, size_t blob_size)
+struct metric_data *metric_scheme_counter_deserialize(const char *blob, size_t blob_size)
{
struct fs_writer *writer = fs_writer_new(blob, blob_size);
- struct metric_measure_data *ret = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *ret = (struct metric_data *)malloc(sizeof(struct metric_data));
struct metric_counter_or_gauge *counter = (struct metric_counter_or_gauge *)malloc(sizeof(struct metric_counter_or_gauge));
ret->counter = counter;
@@ -133,103 +133,103 @@ struct metric_measure_data *metric_scheme_counter_deserialize(const char *blob,
return ret;
}
-void metric_scheme_counter_reset(struct metric_measure_data *data)
+void metric_scheme_counter_reset(struct metric_data *data)
{
data->counter->value = 0;
}
/* --------------------------------- hll -------------------------------- */
-struct metric_measure_data *metric_scheme_hll_new(const struct metric_parameter *para)
+struct metric_data *metric_scheme_hll_new(const struct metric_parameter *para)
{
- struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *data = (struct metric_data *)malloc(sizeof(struct metric_data));
struct ST_hyperloglog *hll = ST_hyperloglog_new(para->hll.precision);
data->hll = hll;
return data;
}
-static void metric_scheme_hll_free(struct metric_measure_data *data)
+static void metric_scheme_hll_free(struct metric_data *data)
{
ST_hyperloglog_free(data->hll);
free(data);
}
-static void metric_scheme_hll_serialize(const struct metric_measure_data *data, char **blob, size_t *blob_size)
+static void metric_scheme_hll_serialize(const struct metric_data *data, char **blob, size_t *blob_size)
{
ST_hyperloglog_serialize(data->hll, blob, blob_size);
}
-static int metric_scheme_hll_merge(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_hll_merge(struct metric_data *pthis, const struct metric_data *from)
{
return ST_hyperloglog_merge(pthis->hll, from->hll);
}
-static int metric_scheme_hll_copy(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_hll_copy(struct metric_data *pthis, const struct metric_data *from)
{
return ST_hyperloglog_merge(pthis->hll, from->hll);
}
-struct metric_measure_data *metric_scheme_hll_deserialize(const char *blob, size_t blob_size)
+struct metric_data *metric_scheme_hll_deserialize(const char *blob, size_t blob_size)
{
- struct metric_measure_data *ret = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *ret = (struct metric_data *)malloc(sizeof(struct metric_data));
struct ST_hyperloglog *hll = ST_hyperloglog_deserialize(blob, blob_size);
ret->hll = hll;
return ret;
}
-void metric_scheme_hll_reset(struct metric_measure_data *data)
+void metric_scheme_hll_reset(struct metric_data *data)
{
ST_hyperloglog_reset(data->hll);
}
/* --------------------------------- histogram -------------------------------- */
-struct metric_measure_data *metric_scheme_histogram_new(const struct metric_parameter *para)
+struct metric_data *metric_scheme_histogram_new(const struct metric_parameter *para)
{
struct hdr_histogram* tmp_p_hdr = NULL;
int ret = hdr_init((int64_t)para->hdr.lowest_trackable_value, (int64_t)para->hdr.highest_trackable_value, para->hdr.significant_figures, &tmp_p_hdr);
if (ret != 0) {
return NULL;
}
- struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *data = (struct metric_data *)malloc(sizeof(struct metric_data));
data->hdr = tmp_p_hdr;
return data;
}
-static void metric_scheme_histogram_free(struct metric_measure_data *data)
+static void metric_scheme_histogram_free(struct metric_data *data)
{
hdr_close(data->hdr);
free(data);
}
-static void metric_scheme_histogram_serialize(const struct metric_measure_data *data, char **blob, size_t *blob_size)
+static void metric_scheme_histogram_serialize(const struct metric_data *data, char **blob, size_t *blob_size)
{
histogram_encode_into_blob(data->hdr, blob, blob_size);
}
-static int metric_scheme_histogram_merge(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_histogram_merge(struct metric_data *pthis, const struct metric_data *from)
{
(void)hdr_add(pthis->hdr, from->hdr);
return 0;
}
-static int metric_scheme_histogram_copy(struct metric_measure_data *pthis, const struct metric_measure_data *from)
+static int metric_scheme_histogram_copy(struct metric_data *pthis, const struct metric_data *from)
{
(void)hdr_add(pthis->hdr, from->hdr);
return 0;
}
-struct metric_measure_data *metric_scheme_histogram_deserialize(const char *blob, size_t blob_size)
+struct metric_data *metric_scheme_histogram_deserialize(const char *blob, size_t blob_size)
{
struct hdr_histogram *hdr = histogram_decode_from_blob(blob, blob_size);
- struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
+ struct metric_data *data = (struct metric_data *)malloc(sizeof(struct metric_data));
data->hdr = hdr;
return data;
}
-void metric_scheme_histogram_reset(struct metric_measure_data *data)
+void metric_scheme_histogram_reset(struct metric_data *data)
{
hdr_reset(data->hdr);
}
@@ -237,7 +237,7 @@ void metric_scheme_histogram_reset(struct metric_measure_data *data)
static const struct metric_scheme g_metric_scheme_table[] = {
[METRIC_TYPE_COUNTER] = {
.new = metric_scheme_counter_new,
- .del = metric_scheme_counter_free,
+ .free = metric_scheme_counter_free,
.serialize = metric_scheme_counter_serialize,
.deserialize = metric_scheme_counter_deserialize,
.merge = metric_scheme_counter_merge,
@@ -246,7 +246,7 @@ static const struct metric_scheme g_metric_scheme_table[] = {
},
[METRIC_TYPE_HLL] = {
.new = metric_scheme_hll_new,
- .del = metric_scheme_hll_free,
+ .free = metric_scheme_hll_free,
.serialize = metric_scheme_hll_serialize,
.deserialize = metric_scheme_hll_deserialize,
.merge = metric_scheme_hll_merge,
@@ -255,7 +255,7 @@ static const struct metric_scheme g_metric_scheme_table[] = {
},
[METRIC_TYPE_HISTOGRAM] = {
.new = metric_scheme_histogram_new,
- .del = metric_scheme_histogram_free,
+ .free = metric_scheme_histogram_free,
.serialize = metric_scheme_histogram_serialize,
.deserialize = metric_scheme_histogram_deserialize,
.merge = metric_scheme_histogram_merge,
@@ -291,9 +291,9 @@ struct metric_parameter *construct_parameters(enum metric_type type, ...)
return paras;
}
-struct metric_info *metric_info_new(const char *name, enum metric_type type, struct metric_parameter *para)
+struct metric_manifest *metric_info_new(const char *name, enum metric_type type, struct metric_parameter *para)
{
- struct metric_info *info = (struct metric_info *)malloc(sizeof(struct metric_info));
+ struct metric_manifest *info = (struct metric_manifest *)malloc(sizeof(struct metric_manifest));
info->name = strdup(name);
info->paras = para;
info->type = type;
@@ -301,7 +301,7 @@ struct metric_info *metric_info_new(const char *name, enum metric_type type, str
return info;
}
-void metric_info_free(struct metric_info *info)
+void metric_info_free(struct metric_manifest *info)
{
free(info->name);
free(info->paras);
@@ -313,7 +313,7 @@ struct metric *metric_new(const char *name, enum metric_type type, struct metric
struct metric *pthis = (struct metric *)calloc(1, sizeof(struct metric));
pthis->info = metric_info_new(name, type, para);
pthis->scheme = &g_metric_scheme_table[type]; // todo: 改成Switch type
- pthis->data_array = NULL;
+ pthis->data = NULL;
return pthis;
}
@@ -324,56 +324,56 @@ void metric_free(struct metric *pthis)
return;
}
- if (pthis->data_array) {
- pthis->scheme->del(pthis->data_array);
+ if (pthis->data) {
+ pthis->scheme->free(pthis->data);
}
metric_info_free(pthis->info);
free(pthis);
}
void metric_reset(struct metric *pthis) {
- pthis->scheme->reset(pthis->data_array);
+ pthis->scheme->reset(pthis->data);
}
-void metric_info_copy(struct metric_info *dst, const struct metric_info *src)
+void metric_info_copy(struct metric_manifest *dest, const struct metric_manifest *src)
{
- dst->name = strdup(src->name);
+ dest->name = strdup(src->name);
if (src->paras == NULL) {
- dst->paras = NULL;
+ dest->paras = NULL;
} else {
- dst->paras = (struct metric_parameter *)malloc(sizeof(struct metric_parameter));
- memcpy(dst->paras, src->paras, sizeof(struct metric_parameter));
+ dest->paras = (struct metric_parameter *)malloc(sizeof(struct metric_parameter));
+ memcpy(dest->paras, src->paras, sizeof(struct metric_parameter));
}
- dst->type = src->type;
- dst->id = src->id;
+ dest->type = src->type;
+ dest->id = src->id;
}
struct metric *metric_fork(const struct metric *src) {
- struct metric *dst = (struct metric *)malloc(sizeof(struct metric));
- dst->info = (struct metric_info *)malloc(sizeof(struct metric_info));
- metric_info_copy(dst->info, src->info);
- dst->scheme = &g_metric_scheme_table[src->info->type];
+ struct metric *dest = (struct metric *)malloc(sizeof(struct metric));
+ dest->info = (struct metric_manifest *)malloc(sizeof(struct metric_manifest));
+ metric_info_copy(dest->info, src->info);
+ dest->scheme = &g_metric_scheme_table[src->info->type];
- dst->data_array = dst->scheme->new(dst->info->paras);
+ dest->data = dest->scheme->new(dest->info->paras);
- return dst;
+ return dest;
}
struct metric *metric_copy(const struct metric *src) {
- struct metric *dst = metric_fork(src);
- src->scheme->copy(dst->data_array, src->data_array);
+ struct metric *dest = metric_fork(src);
+ src->scheme->copy(dest->data, src->data);
- return dst;
+ return dest;
}
//return -1 when merge error. 0 when success. 1 when src has no cell.
int metric_merge(struct metric *dest, const struct metric *src) {
- return dest->scheme->merge(dest->data_array, src->data_array);
+ return dest->scheme->merge(dest->data, src->data);
}
void metric_get_plain_blob(const struct metric *pthis, char **blob, size_t *blob_size) {
- struct metric_measure_data *data = pthis->data_array;
+ struct metric_data *data = pthis->data;
if (pthis->info->type == METRIC_TYPE_HLL) {
ST_hyperloglog_serialize_for_networking(data->hll, blob, blob_size);
return;
@@ -394,17 +394,17 @@ struct metric *metric_counter_new(const char *name) {
}
void metric_counter_incrby(struct metric *pthis, long long value) {
- struct metric_counter_or_gauge *counter = pthis->data_array->counter;
+ struct metric_counter_or_gauge *counter = pthis->data->counter;
counter->value += value;
}
void metric_counter_set(struct metric *pthis, long long value) {
- struct metric_counter_or_gauge *counter = pthis->data_array->counter;
+ struct metric_counter_or_gauge *counter = pthis->data->counter;
counter->value = value;
}
long long metric_counter_get(const struct metric *pthis) {
- return pthis->data_array->counter->value;
+ return pthis->data->counter->value;
}
struct metric *metric_hll_new(const char *name, unsigned char precision) {
@@ -413,11 +413,11 @@ struct metric *metric_hll_new(const char *name, unsigned char precision) {
}
void metric_hll_add(struct metric *pthis, const char *key, size_t key_len) {
- ST_hyperloglog_add(pthis->data_array->hll, key, key_len);
+ ST_hyperloglog_add(pthis->data->hll, key, key_len);
}
double metric_hll_get(const struct metric *pthis) {
- return ST_hyperloglog_count(pthis->data_array->hll);
+ return ST_hyperloglog_count(pthis->data->hll);
}
struct metric *metric_histogram_new(const char *name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) {
@@ -429,7 +429,7 @@ int metric_histogram_record(struct metric *pthis, long long value) {
if (value > pthis->info->paras->hdr.highest_trackable_value) {
value = pthis->info->paras->hdr.highest_trackable_value;
}
- bool ret = hdr_record_value(pthis->data_array->hdr, value);
+ bool ret = hdr_record_value(pthis->data->hdr, value);
if (!ret) {
return -1;
}
@@ -437,11 +437,11 @@ int metric_histogram_record(struct metric *pthis, long long value) {
}
long long metric_histogram_value_at_percentile(const struct metric *pthis, double percentile) {
- return hdr_value_at_percentile(pthis->data_array->hdr, percentile);
+ return hdr_value_at_percentile(pthis->data->hdr, percentile);
}
long long metric_histogram_count_le_value(const struct metric *pthis, long long value) {
- return hdr_count_le_value(pthis->data_array->hdr, value);
+ return hdr_count_le_value(pthis->data->hdr, value);
}
const char *metric_get_name(const struct metric *metrics)
diff --git a/src/metrics/st_hyperloglog.c b/src/metrics/st_hyperloglog.c
index a372583..0b12c74 100644
--- a/src/metrics/st_hyperloglog.c
+++ b/src/metrics/st_hyperloglog.c
@@ -129,16 +129,16 @@ int ST_hyperloglog_add(struct ST_hyperloglog *h, const char *key, size_t keylen)
return hll_add_hash(h, hash);
}
// https://djhworld.github.io/hyperloglog/merging/
-int ST_hyperloglog_merge(struct ST_hyperloglog *dst, const struct ST_hyperloglog *src)
+int ST_hyperloglog_merge(struct ST_hyperloglog *dest, const struct ST_hyperloglog *src)
{
- if(dst->cfg.precision != src->cfg.precision) return -1;
- int n_register=NUM_REG(dst->cfg.precision);
+ if(dest->cfg.precision != src->cfg.precision) return -1;
+ int n_register=NUM_REG(dest->cfg.precision);
int s_reg=0, d_reg=0;
for(int i=0; i<n_register; i++)
{
s_reg=get_register(src, i);
- d_reg=get_register(dst, i);
- set_register(dst, i, MAX(s_reg, d_reg));
+ d_reg=get_register(dest, i);
+ set_register(dest, i, MAX(s_reg, d_reg));
}
return 0;
}
@@ -219,10 +219,10 @@ void ST_hyperloglog_serialize_for_networking(const struct ST_hyperloglog *h, cha
return;
}
-void ST_hyperloglog_merge_blob(struct ST_hyperloglog *dst, const char *blob, size_t blob_sz)
+void ST_hyperloglog_merge_blob(struct ST_hyperloglog *dest, const char *blob, size_t blob_sz)
{
struct ST_hyperloglog *src=ST_hyperloglog_deserialize(blob, blob_sz);
- ST_hyperloglog_merge(dst, src);
+ ST_hyperloglog_merge(dest, src);
ST_hyperloglog_free(src);
return;
}
diff --git a/src/metrics/st_hyperloglog.h b/src/metrics/st_hyperloglog.h
index 98dd7a3..9d05674 100644
--- a/src/metrics/st_hyperloglog.h
+++ b/src/metrics/st_hyperloglog.h
@@ -50,8 +50,8 @@ size_t ST_hyperloglog_serialized_size(const struct ST_hyperloglog *h);
void ST_hyperloglog_serialize(const struct ST_hyperloglog *h, char **blob, size_t *blob_sz);
void ST_hyperloglog_serialize_for_networking(const struct ST_hyperloglog *h, char **blob, size_t *blob_sz);
struct ST_hyperloglog *ST_hyperloglog_deserialize(const char *blob, size_t blob_sz);
-int ST_hyperloglog_merge(struct ST_hyperloglog *dst, const struct ST_hyperloglog *src);
-void ST_hyperloglog_merge_blob(struct ST_hyperloglog *dst, const char *blob, size_t blob_sz);
+int ST_hyperloglog_merge(struct ST_hyperloglog *dest, const struct ST_hyperloglog *src);
+void ST_hyperloglog_merge_blob(struct ST_hyperloglog *dest, const char *blob, size_t blob_sz);
double ST_hyperloglog_error_for_precision(unsigned char precision);
void ST_hyperloglog_configure(struct ST_hyperloglog *h, unsigned char precision, int time_window_seconds, const struct timeval now);
#ifdef __cplusplus
diff --git a/src/tags/heavy_keeper.h b/src/tags/heavy_keeper.h
index 4644e48..6660c97 100644
--- a/src/tags/heavy_keeper.h
+++ b/src/tags/heavy_keeper.h
@@ -36,7 +36,7 @@ int heavy_keeper_get_count(const struct heavy_keeper *hk);
// size_t heavy_keeper_list(const struct heavy_keeper *hk, void **exdatas, size_t n_exdatas); //use list: void **exdatas, heavy_keeper_list(&exdatas); void *exdata = exdatas[i]; // TODO: 用户申请exdata 数组
void heavy_keeper_list(const struct heavy_keeper *hk, void ***exdatas, size_t *n_exdatas);
-void heavy_keeper_merge(struct heavy_keeper *dest, const struct heavy_keeper *src); // TODO: dst 和 dest 统一一下
+void heavy_keeper_merge(struct heavy_keeper *dest, const struct heavy_keeper *src);
struct heavy_keeper *heavy_keeper_copy(const struct heavy_keeper *src);
diff --git a/src/tags/my_ut_hash.c b/src/tags/my_ut_hash.c
index b020761..af27356 100644
--- a/src/tags/my_ut_hash.c
+++ b/src/tags/my_ut_hash.c
@@ -336,22 +336,22 @@ void tag_hash_key_convert_to_fieldstat_tag(const struct tag_hash_key *tag_key, s
struct tag_hash_key *tag_hash_key_copy(const struct tag_hash_key *src)
{
- struct tag_hash_key *dst = (struct tag_hash_key *)malloc(sizeof(struct tag_hash_key));
- dst->n_my_tag = src->n_my_tag;
- dst->hashv = src->hashv;
- dst->is_deep_copy = true;
- dst->hashv128 = src->hashv128;
-
- if (dst->n_my_tag == 0) {
- dst->tags = NULL;
+ struct tag_hash_key *dest = (struct tag_hash_key *)malloc(sizeof(struct tag_hash_key));
+ dest->n_my_tag = src->n_my_tag;
+ dest->hashv = src->hashv;
+ dest->is_deep_copy = true;
+ dest->hashv128 = src->hashv128;
+
+ if (dest->n_my_tag == 0) {
+ dest->tags = NULL;
} else {
- dst->tags = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * dst->n_my_tag);
- for (int i = 0; i < dst->n_my_tag; i++) {
- fieldtag_copy(&dst->tags[i], &src->tags[i]);
+ dest->tags = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * dest->n_my_tag);
+ for (int i = 0; i < dest->n_my_tag; i++) {
+ fieldtag_copy(&dest->tags[i], &src->tags[i]);
}
}
- return dst;
+ return dest;
}
void tag_hash_key_free(struct tag_hash_key *tag_key)