diff options
| author | chenzizhan <[email protected]> | 2023-11-24 18:51:01 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-11-24 18:51:01 +0800 |
| commit | 04d5d38bf1d1c9c77967cc9f4dac905a45edfc38 (patch) | |
| tree | 3eee3960b10478deef6fdd447e7a23c021ddf665 | |
| parent | d0219e918b21fc39ecb567a00b81161bb7387eec (diff) | |
more readable rearrange_metric_delta
| -rw-r--r-- | src/exporter/cjson_exporter.c | 32 | ||||
| -rw-r--r-- | src/tags/my_ut_hash.c | 1 | ||||
| -rw-r--r-- | test/test_easy_fs.cpp | 1 | ||||
| -rw-r--r-- | test/test_exporter_json.cpp | 21 |
4 files changed, 53 insertions, 2 deletions
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index e430f5a..c96ada3 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -426,7 +426,7 @@ int couple_export_table_find(const struct couple_export_table *tbl, const char * struct couple_export_table_item *node; HASH_FIND_STR(tbl->items, json, node); if (node == NULL) { - return false; + return -1; } return node->kv_pair_id; } @@ -451,6 +451,36 @@ void couple_export_table_free(struct couple_export_table *tbl) 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(); // todo: 这个map更新放到exporter里,不要每次都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 + tag_json = "\anil"; + } + couple_export_table_add(map, tag_json, i); + } + + const struct cellwise_rec_for_export **ret = calloc(n_acc, sizeof(struct cellwise_rec_for_export *)); + + 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 + tag_str_acc = "\anil"; + } + + int id_delta = couple_export_table_find(map, tag_str_acc); + if (id_delta == -1) { + continue; + } + ret[id_acc] = &delta[id_delta]; + } + + couple_export_table_free(map); + return ret; +} + +const struct cellwise_rec_for_export **rearrange_metric_delta1(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(); // todo: 这个map更新放到exporter里,不要每次都new for (int i = 0; i < n_acc; i++) { const char *tag_json = json_writer_unwrap(acc[i].cjson_tags); if (tag_json == NULL) { // tag might be empty, give it a dummy name diff --git a/src/tags/my_ut_hash.c b/src/tags/my_ut_hash.c index 4038067..0c1f2af 100644 --- a/src/tags/my_ut_hash.c +++ b/src/tags/my_ut_hash.c @@ -145,7 +145,6 @@ XXH128_hash_t cal_tag_hash_xxhash128(const struct fieldstat_tag *tag, size_t n_t for (int i = 0; i < n_tag; i++) { - // XXH32_update(&state, (const xxh_u8 *)tag[i].key, strlen(tag[i].key)); XXH3_128bits_update(state, tag[i].key, strlen(tag[i].key)); if (tag[i].type != TAG_CSTRING) { // sizeof(long long) == sizeof(double) diff --git a/test/test_easy_fs.cpp b/test/test_easy_fs.cpp index 8c752e5..54e22f6 100644 --- a/test/test_easy_fs.cpp +++ b/test/test_easy_fs.cpp @@ -187,6 +187,7 @@ TEST(test_easy_fieldstat, ensure_data_racing_of_two_output_and_of_incyby) for (int i = 0; i < 1000000; i++) { // loop million times to ensure no core dump fieldstat_easy_counter_incrby(fse, thread_id, counter_id, &TEST_TAG_INT, 1, 1); fieldstat_easy_histogram_record(fse, thread_id, hdr_id, &TEST_TAG_INT, 1, rand() % 10000); + usleep(1); // 1us * 1000000 = 1s, just long enough to output } }); } diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index f58c6ea..09aa579 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -949,6 +949,27 @@ TEST(export_test, delta_with_two_instance_different_cell) fieldstat_free(delta); } +// TEST(export_test, sort_tag) { +// const struct fieldstat_tag tag1[3] = {TEST_TAG_INT, TEST_TAG_STRING, TEST_TAG_DOUBLE}; +// const struct fieldstat_tag tag2[3] = {TEST_TAG_STRING, TEST_TAG_DOUBLE, TEST_TAG_INT}; + +// struct fieldstat *instance = fieldstat_new(); +// fieldstat_create_cube(instance, NULL, 0, SAMPLING_MODE_COMPREHENSIVE, 0); +// int id_counter = fieldstat_register_counter(instance, "counter"); +// fieldstat_counter_incrby(instance, 0, id_counter, tag1, 3, 1); +// fieldstat_counter_incrby(instance, 0, id_counter, tag2, 3, 10); + +// // export test +// cJSON *root_arr = test_exporter_extract_results(instance); +// EXPECT_EQ(cJSON_GetArraySize(root_arr), 1); +// cJSON *root = cJSON_GetArrayItem(root_arr, 0); +// cJSON *metrics = cJSON_GetObjectItem(root, "fields"); +// cJSON *counter = cJSON_GetObjectItem(metrics, "counter"); +// EXPECT_EQ(counter->valueint, 11); + +// cJSON_Delete(root_arr); +// fieldstat_free(instance); +// } extern "C" { extern int add_object_to_json_array_start(char *buf, int buf_len); |
