diff options
Diffstat (limited to 'trace2/tr2_tgt_event.c')
-rw-r--r-- | trace2/tr2_tgt_event.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index af5a8edb47..16f6332755 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -642,6 +642,24 @@ static void fn_timer(const struct tr2_timer_metadata *meta, jw_release(&jw); } +static void fn_counter(const struct tr2_counter_metadata *meta, + const struct tr2_counter *counter, + int is_final_data) +{ + const char *event_name = is_final_data ? "counter" : "th_counter"; + struct json_writer jw = JSON_WRITER_INIT; + + jw_object_begin(&jw, 0); + event_fmt_prepare(event_name, __FILE__, __LINE__, NULL, &jw); + jw_object_string(&jw, "category", meta->category); + jw_object_string(&jw, "name", meta->name); + jw_object_intmax(&jw, "count", counter->value); + jw_end(&jw); + + tr2_dst_write_line(&tr2dst_event, &jw.json); + jw_release(&jw); +} + struct tr2_tgt tr2_tgt_event = { .pdst = &tr2dst_event, @@ -674,4 +692,5 @@ struct tr2_tgt tr2_tgt_event = { .pfn_data_json_fl = fn_data_json_fl, .pfn_printf_va_fl = NULL, .pfn_timer = fn_timer, + .pfn_counter = fn_counter, }; |