summaryrefslogtreecommitdiff
path: root/src/exporter
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-11-24 18:51:01 +0800
committerchenzizhan <[email protected]>2023-11-24 18:51:01 +0800
commit04d5d38bf1d1c9c77967cc9f4dac905a45edfc38 (patch)
tree3eee3960b10478deef6fdd447e7a23c021ddf665 /src/exporter
parentd0219e918b21fc39ecb567a00b81161bb7387eec (diff)
more readable rearrange_metric_delta
Diffstat (limited to 'src/exporter')
-rw-r--r--src/exporter/cjson_exporter.c32
1 files changed, 31 insertions, 1 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