diff options
| author | fumingwei <[email protected]> | 2023-05-29 14:04:57 +0800 |
|---|---|---|
| committer | fumingwei <[email protected]> | 2023-06-02 10:41:12 +0800 |
| commit | 2b6a1bfd1a6c41fb71b59dd50f62d2c3f4688fa8 (patch) | |
| tree | a4bc90b8a752dee1f42bfda1b313cb824d1ed0ff /src/file_output.cpp | |
| parent | d5389fb9f1cf48f413eb6cd7baad27a57efe2274 (diff) | |
bugfix:新增historgam和summary line protocol输出
Diffstat (limited to 'src/file_output.cpp')
| -rw-r--r-- | src/file_output.cpp | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/file_output.cpp b/src/file_output.cpp index 9b29ad4..a6ae655 100644 --- a/src/file_output.cpp +++ b/src/file_output.cpp @@ -390,6 +390,27 @@ static int output_file_print_hdr_head(struct metric *metric, char *print_buf, si return used_len; } +static struct hdr_histogram *read_hdr_unit_output(struct metric *metric) +{ + struct histogram_t *h = &(metric->histogram); + struct hdr_histogram *h_out = NULL, *h_tmp = NULL; + hdr_init(h->lowest_trackable_value, h->highest_trackable_value, + h->significant_figures, &(h_tmp)); + + if(h->previous_changed != NULL) + { + hdr_close(h->previous_changed); + } + + h->previous_changed = atomic_read(&(h->changing)); + h_tmp=atomic_set(&(h->changing), h_tmp); + hdr_add(h->accumulated, h->previous_changed); + + h_out = (metric->output_window == 0)?h->accumulated:h->previous_changed; + + return h_out; +} + static int output_file_print_hdr_unit(struct metric *metric, char *print_buf, size_t size) { int used_len = 0; @@ -397,28 +418,13 @@ static int output_file_print_hdr_unit(struct metric *metric, char *print_buf, si int bins_num = metric->histogram.bins_num; long long value = 0; int i = 0; - struct histogram_t *h=&(metric->histogram); - struct hdr_histogram *h_out=NULL, *h_tmp=NULL; + struct hdr_histogram *h_out=NULL; char int_format[STR_LEN_256], double_format[STR_LEN_256]; snprintf(int_format, sizeof(int_format), "%%%dlld",HISTOGRAM_WIDTH); snprintf(double_format, sizeof(double_format), "%%%d.2lf",HISTOGRAM_WIDTH); - hdr_init(h->lowest_trackable_value, h->highest_trackable_value, h->significant_figures, &(h_tmp)); - - if(h->previous_changed != NULL) - { - hdr_close(h->previous_changed); - } - - h->previous_changed=atomic_read(&(h->changing)); - h_tmp=atomic_set(&(h->changing), h_tmp);// left h_tmp is used to avoid warining [-Wunused-value] - - hdr_add(h->accumulated, h->previous_changed); - - metric->output_window == 0 - ?h_out = h->accumulated - :h_out = h->previous_changed; + h_out = read_hdr_unit_output(metric); used_len += snprintf(print_buf + used_len, size - used_len, "%-10s\t", metric->field_name); @@ -443,8 +449,6 @@ static int output_file_print_hdr_unit(struct metric *metric, char *print_buf, si used_len += snprintf(print_buf + used_len, size - used_len,"\n"); - h_tmp = NULL; - return used_len; } @@ -592,18 +596,7 @@ int output_file_format_json(struct fieldstat_instance *instance, int n_cur_metri break; case FIELD_TYPE_SUMMARY: case FILED_TYPE_HISTOGRAM: - struct histogram_t* h=&(metric->histogram); - struct hdr_histogram* h_out=NULL, *h_tmp=NULL; - hdr_init(h->lowest_trackable_value, h->highest_trackable_value, h->significant_figures, &(h_tmp)); - if(h->previous_changed!=NULL) hdr_close(h->previous_changed); - - h->previous_changed=atomic_read(&(h->changing)); - h_tmp=atomic_set(&(h->changing), h_tmp);// left h_tmp is used to avoid warining [-Wunused-value] - - hdr_add(h->accumulated, h->previous_changed); - metric->output_window == 0 - ?h_out = h->accumulated - :h_out = h->previous_changed; + struct hdr_histogram *h_out = read_hdr_unit_output(metric); tmp_obj = cJSON_CreateObject(); for(int j = 0; j < metric->histogram.bins_num; j++) |
