diff options
| author | chenzizhan <[email protected]> | 2024-10-16 10:18:48 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2024-10-16 10:18:48 +0800 |
| commit | f56b8f44b91a07bcbcd08614aa4341c2c892b4a1 (patch) | |
| tree | ef644d96e063bd29f2e3d1ef3c74cee9e9ef2af6 | |
| parent | e5c869ccbb7e9357b987754dd605b96f660c133f (diff) | |
rename fieldstat_hll_add_field
| -rw-r--r-- | include/fieldstat/fieldstat.h | 21 | ||||
| -rw-r--r-- | src/fieldstat.c | 4 | ||||
| -rw-r--r-- | src/version.map | 2 | ||||
| -rw-r--r-- | test/test_exporter_json.cpp | 4 | ||||
| -rw-r--r-- | test/test_fuzz_test.cpp | 4 | ||||
| -rw-r--r-- | test/test_merge.cpp | 8 | ||||
| -rw-r--r-- | test/test_metric_hll.cpp | 8 | ||||
| -rw-r--r-- | test/test_register_and_reset.cpp | 2 |
8 files changed, 36 insertions, 17 deletions
diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h index cb0851a..8268436 100644 --- a/include/fieldstat/fieldstat.h +++ b/include/fieldstat/fieldstat.h @@ -57,6 +57,14 @@ struct field { }; }; +struct field_t_0_fs *pst = (fields[]); +{ + uint64_t hashv = 0; + char *serialized_dimension; + int bucket_in_uthash; + struct cell *cell; +} + struct fieldstat; struct fieldstat *fieldstat_new(); void fieldstat_free(struct fieldstat *instance); @@ -120,6 +128,8 @@ int fieldstat_register_histogram(struct fieldstat *instance, int cube_id, const * @return Error codes. */ int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long increment); +int fieldstat_counter_incrby_batch(struct fieldstat *instance, int cube_id, const struct field *cell_dimensions, size_t n_dimensions, int metric_ids[], long long increments[], size_t n_metrics); + /* * @brief let the value of counter metric equal to value. Must be called on non-primary metric. Other annotations refer to fieldstat_counter_incrby. @@ -140,7 +150,7 @@ int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, co * @param item_len: the length of the field. * @return Error codes. */ -int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct field *item, size_t item_len); +int fieldstat_hll_add_fields(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct field *items, size_t n_items); /* @@ -150,6 +160,15 @@ int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_ * @return Error codes. */ int fieldstat_histogram_record(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, long long value); +struct histogram; +struct histogram *fieldstat_histogram_fork(struct fieldstat *instance, int metric_id); +void +void histogram_free(struct fieldstat_histogram *histogram); +void histogram_reset(struct fieldstat_histogram *histogram); +int fieldstat_histogram_merge(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct histogram *src); + + +struct /* * @brief Delete all the cells, also the content of every metrics. The cube and metrics are not deleted. diff --git a/src/fieldstat.c b/src/fieldstat.c index 431626d..86aa0b2 100644 --- a/src/fieldstat.c +++ b/src/fieldstat.c @@ -174,14 +174,14 @@ int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, co } // cppcheck-suppress [constParameterPointer, unmatchedSuppression] -int fieldstat_hll_add_field(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct field *item, size_t item_len) +int fieldstat_hll_add_fields(struct fieldstat *instance, int cube_id, int metric_id, const struct field *cell_dimensions, size_t n_dimensions, const struct field *items, size_t n_items) { 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_hll_add_field(cube, metric_id, cell_dimensions, n_dimensions, item, item_len); + return cube_hll_add_field(cube, metric_id, cell_dimensions, n_dimensions, items, n_items); } // cppcheck-suppress [constParameterPointer, unmatchedSuppression] diff --git a/src/version.map b/src/version.map index ede484f..5e22600 100644 --- a/src/version.map +++ b/src/version.map @@ -1,5 +1,5 @@ { - global: *fieldstat_*; + global: *fieldstat_*, *histogram*; GIT_VERSION*; local: *; };
\ No newline at end of file diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index 7794bb4..b93b974 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -303,14 +303,14 @@ TEST(export_test, cjson_export_on_one_cube_of_spreadsketch_sampling) { Flow flow = flow_generator.next(); Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper("bigger fanouts", flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); fieldstat_counter_incrby(instance, cube_id, metric_count, dimension.get_tag(), dimension.get_tag_count(), 1); } for (int i = 0; i < 100; i++) { Flow flow = flow_generator.next(); Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper("smaller fanouts", flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); fieldstat_counter_incrby(instance, cube_id, metric_count, dimension.get_tag(), dimension.get_tag_count(), 1); } diff --git a/test/test_fuzz_test.cpp b/test/test_fuzz_test.cpp index 34c0711..6057e5d 100644 --- a/test/test_fuzz_test.cpp +++ b/test/test_fuzz_test.cpp @@ -425,7 +425,7 @@ TEST(Fuzz_test, many_instance_random_flow_unregister_calibrate_reset_fork_merge_ int cube_id = rand() % CUBE_NUM; const Fieldstat_tag_list_wrapper *shared_tag = shared_tags[cube_id]; - int ret_add = fieldstat_hll_add_field(instance, cube_id, 0, cell_dimension.get_tag(), cell_dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + int ret_add = fieldstat_hll_add_fields(instance, cube_id, 0, cell_dimension.get_tag(), cell_dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); if (ret_add == FS_ERR_TOO_MANY_CELLS) { continue; } @@ -628,7 +628,7 @@ TEST(perf, simple_one_for_perf_spreadsketch) getchar(); for (int i = 0; i < TEST_ROUND; i++) { - fieldstat_hll_add_field(instance, cube_id, 0, cell_dimension[i]->get_tag(), cell_dimension[i]->get_tag_count(), items[i]->get_tag(), items[i]->get_tag_count()); + fieldstat_hll_add_fields(instance, cube_id, 0, cell_dimension[i]->get_tag(), cell_dimension[i]->get_tag_count(), items[i]->get_tag(), items[i]->get_tag_count()); } clock_t end = clock(); diff --git a/test/test_merge.cpp b/test/test_merge.cpp index 7aa1cf9..0e5f6fc 100644 --- a/test/test_merge.cpp +++ b/test/test_merge.cpp @@ -634,7 +634,7 @@ TEST(unit_test_merge, gen_dest_full_all_src_inserted_given_src_flows_larger_spre Flow flow = flow_generator.next(); Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper(src_key, flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); flow_cnt[dimension.to_string()].insert(item.to_string()); } @@ -643,7 +643,7 @@ TEST(unit_test_merge, gen_dest_full_all_src_inserted_given_src_flows_larger_spre Flow flow = flow_generator.next(); Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper(dest_key, flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance_dest, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance_dest, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); flow_cnt[dimension.to_string()].insert(item.to_string()); } @@ -692,7 +692,7 @@ TEST(unit_test_merge, merge_accuracy_test_gen_dest_full_some_inserted_and_some_m const char *use_key = rand()%2? "src":"common"; Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper(use_key, flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); flow_cnt[dimension.to_string()].insert(item.to_string()); } @@ -701,7 +701,7 @@ TEST(unit_test_merge, merge_accuracy_test_gen_dest_full_some_inserted_and_some_m const char *use_key = rand()%2? "dest":"common"; Fieldstat_tag_list_wrapper dimension = Fieldstat_tag_list_wrapper(use_key, flow.src_ip.c_str()); Fieldstat_tag_list_wrapper item = Fieldstat_tag_list_wrapper("dummy", flow.dst_ip.c_str()); - fieldstat_hll_add_field(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); + fieldstat_hll_add_fields(instance_src, cube_id, metric_id, dimension.get_tag(), dimension.get_tag_count(), item.get_tag(), item.get_tag_count()); flow_cnt[dimension.to_string()].insert(item.to_string()); } diff --git a/test/test_metric_hll.cpp b/test/test_metric_hll.cpp index 301863e..92211fb 100644 --- a/test/test_metric_hll.cpp +++ b/test/test_metric_hll.cpp @@ -81,9 +81,9 @@ TEST(metric_test_hll, simple_register_and_query) TEST(metric_test_hll, add_with_tags) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hll(); - fieldstat_hll_add_field(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_INT, 1); - fieldstat_hll_add_field(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_DOUBLE, 1); - fieldstat_hll_add_field(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_STRING, 1); + fieldstat_hll_add_fields(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_INT, 1); + fieldstat_hll_add_fields(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_DOUBLE, 1); + fieldstat_hll_add_fields(instance, 0, 0, &TEST_FIELD_INT, 1, &TEST_FIELD_STRING, 1); test_assert_standard_instance(instance); EXPECT_NEAR(my_fieldstat_hll_get(instance, 0, 0), 3, 0.5); @@ -247,7 +247,7 @@ TEST(metric_test_hll, spread_sketch_add_and_test_accuracy) Fieldstat_tag_list_wrapper dimension("src ip", f.src_ip.c_str()); Fieldstat_tag_list_wrapper counted("dst ip", f.dst_ip.c_str()); - fieldstat_hll_add_field(instance, 0, 0, dimension.get_tag(), dimension.get_tag_count(), counted.get_tag(), counted.get_tag_count()); + fieldstat_hll_add_fields(instance, 0, 0, dimension.get_tag(), dimension.get_tag_count(), counted.get_tag(), counted.get_tag_count()); flow_cnt[dimension.to_string()].insert(counted.to_string()); } diff --git a/test/test_register_and_reset.cpp b/test/test_register_and_reset.cpp index 95b7483..2cc9db2 100644 --- a/test/test_register_and_reset.cpp +++ b/test/test_register_and_reset.cpp @@ -65,7 +65,7 @@ TEST(test_register, delete_spreadsketch_cube_with_cells_and_metrics) fieldstat_cube_set_sampling(instance, cube_id, SAMPLING_MODE_TOP_CARDINALITY, 10, metric_primary); fieldstat_counter_incrby(instance, cube_id, metric_id1, &TEST_FIELD_INT, 1, 1); - fieldstat_hll_add_field(instance, cube_id, metric_primary, &TEST_FIELD_INT, 1, &TEST_FIELD_DOUBLE, 1); + fieldstat_hll_add_fields(instance, cube_id, metric_primary, &TEST_FIELD_INT, 1, &TEST_FIELD_DOUBLE, 1); fieldstat_cube_destroy(instance, cube_id); struct field_list *tag_list = fieldstat_cube_get_dimension(instance, cube_id); |
