summaryrefslogtreecommitdiff
path: root/src
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
parent5f25467142e9bf1dfae083edcd4dc29195105b1b (diff)
fieldstat easy output flat when called actively
Diffstat (limited to 'src')
-rw-r--r--src/exporter/cjson_exporter.c30
-rw-r--r--src/fieldstat_easy.c11
2 files changed, 31 insertions, 10 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
diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c
index 46133f4..f32dbd9 100644
--- a/src/fieldstat_easy.c
+++ b/src/fieldstat_easy.c
@@ -275,7 +275,7 @@ void fieldstat_easy_output(struct fieldstat_easy *fse, char **buff, size_t *buff
struct fieldstat *dest = merge_all_instance(fse);
struct timeval timestamp = get_current_timestamp();
- *buff = fieldstat_json_exporter_export(fse->exporter, dest, &timestamp);
+ *buff = fieldstat_json_exporter_export_flat(fse->exporter, dest, &timestamp);
if (*buff == NULL) {
*buff = strdup("[]");
}
@@ -289,7 +289,7 @@ void fieldstat_easy_output_array(struct fieldstat_easy *fse, char ***json_object
struct timeval timestamp = get_current_timestamp();
struct fieldstat *dest = merge_all_instance(fse);
- fieldstat_json_exporter_export_array(fse->exporter, dest, &timestamp, json_objects, n_object);
+ fieldstat_json_exporter_export_flat_array(fse->exporter, dest, &timestamp, json_objects, n_object);
fieldstat_free(dest);
}
@@ -307,7 +307,7 @@ int fieldstat_easy_output_array_and_reset(struct fieldstat_easy *fse, char ***js
}
struct timeval timestamp = get_current_timestamp();
- fieldstat_json_exporter_export_array(fse->exporter, dest, &timestamp, json_objects, n_object);
+ fieldstat_json_exporter_export_flat_array(fse->exporter, dest, &timestamp, json_objects, n_object);
fieldstat_free(dest);
return 0;
@@ -360,8 +360,3 @@ int fieldstat_easy_histogram_record(struct fieldstat_easy *fse, int thread_id, i
return ret;
}
-
-void fieldstat_easy_enable_delta_in_active_output(struct fieldstat_easy *fse)
-{
- fieldstat_json_exporter_enable_delta(fse->exporter);
-} \ No newline at end of file