summaryrefslogtreecommitdiff
path: root/src/exporter/cjson_exporter.c
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-18 18:03:05 +0800
committerchenzizhan <[email protected]>2024-07-18 18:03:05 +0800
commit7f415b4385607dcc29babe80356c2c973c301097 (patch)
tree14045d840ca574bf9d3a5ff971d7142cf02279a4 /src/exporter/cjson_exporter.c
parent5f25467142e9bf1dfae083edcd4dc29195105b1b (diff)
fieldstat easy output flat when called actively
Diffstat (limited to 'src/exporter/cjson_exporter.c')
-rw-r--r--src/exporter/cjson_exporter.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c
index 6a52c6a..b2a909d 100644
--- a/src/exporter/cjson_exporter.c
+++ b/src/exporter/cjson_exporter.c
@@ -876,7 +876,7 @@ char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *expor
int buf_len = 4096;
char *cjson_str_arr = (char *)malloc(buf_len);
- // cjson is so slow, so we construct the json array manually, the reason why we don't use json_writer is simply because I wrote this before implementing json_writer
+ // cjson is so slow, so we construct the json array manually
int used_len = add_object_to_json_array_start(cjson_str_arr, buf_len);
for (int i = 0; i < n_pair; i++) {
used_len = add_object_to_json_array(&cjson_str_arr, &buf_len, used_len, str_arr[i]);
@@ -1040,7 +1040,7 @@ void fieldstat_json_exporter_enable_delta(struct fieldstat_json_exporter *export
exporter->history = counter_history_new();
}
-void fieldstat_json_exporter_export_flat(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp, char ***output, size_t *output_size) {
+void fieldstat_json_exporter_export_flat_array(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp, char ***output, size_t *output_size) {
long long timestamp_ms = cal_ms_time(timestamp);
size_t n_pair;
@@ -1090,4 +1090,30 @@ void fieldstat_json_exporter_export_flat(const struct fieldstat_json_exporter *e
}
free(tag_field_pair);
+}
+
+char *fieldstat_json_exporter_export_flat(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp)
+{
+ char **str_arr = NULL;
+ size_t n_pair = 0;
+ fieldstat_json_exporter_export_flat_array(exporter, instance, timestamp, &str_arr, &n_pair);
+ if (str_arr == NULL || n_pair == 0) {
+ return NULL;
+ }
+
+ int buf_len = 4096;
+ char *cjson_str_arr = (char *)malloc(buf_len);
+ // cjson is so slow, so we construct the json array manually
+ int used_len = add_object_to_json_array_start(cjson_str_arr, buf_len);
+ for (int i = 0; i < n_pair; i++) {
+ used_len = add_object_to_json_array(&cjson_str_arr, &buf_len, used_len, str_arr[i]);
+ }
+ add_object_to_json_array_end(&cjson_str_arr, buf_len, used_len);
+
+ for (int i = 0; i < n_pair; i++) {
+ free(str_arr[i]);
+ }
+ free(str_arr);
+
+ return cjson_str_arr;
} \ No newline at end of file