summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-11-14 14:56:03 +0800
committerchenzizhan <[email protected]>2023-11-14 14:56:03 +0800
commit706e5dc7a2615cec0dc2a1bf9eddcff9a391855c (patch)
tree51aa2294b9ed76567ddff3f6ca1a8e82f6113d96 /src
parenta619037a074dd57398d185cd2e2154bb991d2c2b (diff)
fieldstat easy name
Diffstat (limited to 'src')
-rw-r--r--src/exporter/cjson_exporter.c3
-rw-r--r--src/fieldstat_easy.c10
2 files changed, 10 insertions, 3 deletions
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c
index 9b98958..c519ca7 100644
--- a/src/exporter/cjson_exporter.c
+++ b/src/exporter/cjson_exporter.c
@@ -860,8 +860,9 @@ void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *
for (int j = 0; j < tag_field_pair[i].n_metric; j++) {
kv_pair_write_to_json(tag_field_pair[i].metric_pairs[j], field_json);
}
- struct json_writer *field_json_delta = json_writer_init();
+ struct json_writer *field_json_delta = NULL;
if (exporter->history != NULL) { // not null when fieldstat_json_exporter_enable_delta is called
+ struct json_writer *field_json_delta = json_writer_init();
write_delta_to_json((struct fieldstat_json_exporter *)exporter, &tag_field_pair[i], field_json_delta);
}
diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c
index fc56bd5..61f17c5 100644
--- a/src/fieldstat_easy.c
+++ b/src/fieldstat_easy.c
@@ -114,7 +114,7 @@ void *fs_easy_output_thread(void *arg) // return void * for pthread_create check
return NULL; // return void * for pthread_create check only
}
-struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const struct fieldstat_tag *tags, size_t n_tag) {
+struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const char *name, const struct fieldstat_tag *tags, size_t n_tag) {
struct fieldstat_easy *fse = calloc(1, sizeof(struct fieldstat_easy));
fse->fsu = malloc(sizeof(struct fs_easy_thread) * max_thread_num);
fse->max_thread_num = max_thread_num;
@@ -123,7 +123,13 @@ struct fieldstat_easy *fieldstat_easy_new(int max_thread_num, const struct field
fse->accumulate = fieldstat_fork(fse->delta);
fse->exporter = fieldstat_json_exporter_new();
- fieldstat_json_exporter_set_global_tag(fse->exporter, tags, n_tag);
+ if (tags != NULL && n_tag > 0) {
+ fieldstat_json_exporter_set_global_tag(fse->exporter, tags, n_tag);
+ }
+ if (name != NULL) {
+ fieldstat_json_exporter_set_name(fse->exporter, name);
+ }
+
pthread_spin_init(&fse->outputting_lock, PTHREAD_PROCESS_PRIVATE);
for (int i = 0; i < max_thread_num; i++) {