diff options
Diffstat (limited to 'trace2/tr2_tgt_event.c')
| -rw-r--r-- | trace2/tr2_tgt_event.c | 77 |
1 files changed, 63 insertions, 14 deletions
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 37a3163be1..59910a1a4f 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "json-writer.h" +#include "repository.h" #include "run-command.h" #include "version.h" #include "trace2/tr2_dst.h" @@ -9,6 +10,7 @@ #include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" +#include "trace2/tr2_tmr.h" static struct tr2_dst tr2dst_event = { .sysenv_var = TR2_SYSENV_EVENT, @@ -90,7 +92,7 @@ static void event_fmt_prepare(const char *event_name, const char *file, jw_object_string(jw, "event", event_name); jw_object_string(jw, "sid", tr2_sid_get()); - jw_object_string(jw, "thread", ctx->thread_name.buf); + jw_object_string(jw, "thread", ctx->thread_name); /* * In brief mode, only emit <time> on these 2 event types. @@ -333,7 +335,7 @@ static void fn_alias_fl(const char *file, int line, const char *alias, } static void fn_child_start_fl(const char *file, int line, - uint64_t us_elapsed_absolute, + uint64_t us_elapsed_absolute UNUSED, const struct child_process *cmd) { const char *event_name = "child_start"; @@ -365,7 +367,8 @@ static void fn_child_start_fl(const char *file, int line, } static void fn_child_exit_fl(const char *file, int line, - uint64_t us_elapsed_absolute, int cid, int pid, + uint64_t us_elapsed_absolute UNUSED, + int cid, int pid, int code, uint64_t us_elapsed_child) { const char *event_name = "child_exit"; @@ -386,7 +389,8 @@ static void fn_child_exit_fl(const char *file, int line, } static void fn_child_ready_fl(const char *file, int line, - uint64_t us_elapsed_absolute, int cid, int pid, + uint64_t us_elapsed_absolute UNUSED, + int cid, int pid, const char *ready, uint64_t us_elapsed_child) { const char *event_name = "child_ready"; @@ -407,7 +411,7 @@ static void fn_child_ready_fl(const char *file, int line, } static void fn_thread_start_fl(const char *file, int line, - uint64_t us_elapsed_absolute) + uint64_t us_elapsed_absolute UNUSED) { const char *event_name = "thread_start"; struct json_writer jw = JSON_WRITER_INIT; @@ -421,7 +425,7 @@ static void fn_thread_start_fl(const char *file, int line, } static void fn_thread_exit_fl(const char *file, int line, - uint64_t us_elapsed_absolute, + uint64_t us_elapsed_absolute UNUSED, uint64_t us_elapsed_thread) { const char *event_name = "thread_exit"; @@ -437,7 +441,8 @@ static void fn_thread_exit_fl(const char *file, int line, jw_release(&jw); } -static void fn_exec_fl(const char *file, int line, uint64_t us_elapsed_absolute, +static void fn_exec_fl(const char *file, int line, + uint64_t us_elapsed_absolute UNUSED, int exec_id, const char *exe, const char **argv) { const char *event_name = "exec"; @@ -458,8 +463,8 @@ static void fn_exec_fl(const char *file, int line, uint64_t us_elapsed_absolute, } static void fn_exec_result_fl(const char *file, int line, - uint64_t us_elapsed_absolute, int exec_id, - int code) + uint64_t us_elapsed_absolute UNUSED, + int exec_id, int code) { const char *event_name = "exec_result"; struct json_writer jw = JSON_WRITER_INIT; @@ -475,11 +480,11 @@ static void fn_exec_result_fl(const char *file, int line, } static void fn_param_fl(const char *file, int line, const char *param, - const char *value) + const char *value, const struct key_value_info *kvi) { const char *event_name = "def_param"; struct json_writer jw = JSON_WRITER_INIT; - enum config_scope scope = current_config_scope(); + enum config_scope scope = kvi->scope; const char *scope_name = config_scope_name(scope); jw_object_begin(&jw, 0); @@ -509,7 +514,7 @@ static void fn_repo_fl(const char *file, int line, } static void fn_region_enter_printf_va_fl(const char *file, int line, - uint64_t us_elapsed_absolute, + uint64_t us_elapsed_absolute UNUSED, const char *category, const char *label, const struct repository *repo, @@ -536,7 +541,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line, } static void fn_region_leave_printf_va_fl( - const char *file, int line, uint64_t us_elapsed_absolute, + const char *file, int line, uint64_t us_elapsed_absolute UNUSED, uint64_t us_elapsed_region, const char *category, const char *label, const struct repository *repo, const char *fmt, va_list ap) { @@ -617,6 +622,48 @@ static void fn_data_json_fl(const char *file, int line, } } +static void fn_timer(const struct tr2_timer_metadata *meta, + const struct tr2_timer *timer, + int is_final_data) +{ + const char *event_name = is_final_data ? "timer" : "th_timer"; + struct json_writer jw = JSON_WRITER_INIT; + double t_total = NS_TO_SEC(timer->total_ns); + double t_min = NS_TO_SEC(timer->min_ns); + double t_max = NS_TO_SEC(timer->max_ns); + + 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, "intervals", timer->interval_count); + jw_object_double(&jw, "t_total", 6, t_total); + jw_object_double(&jw, "t_min", 6, t_min); + jw_object_double(&jw, "t_max", 6, t_max); + jw_end(&jw); + + tr2_dst_write_line(&tr2dst_event, &jw.json); + 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, @@ -648,4 +695,6 @@ struct tr2_tgt tr2_tgt_event = { .pfn_data_fl = fn_data_fl, .pfn_data_json_fl = fn_data_json_fl, .pfn_printf_va_fl = NULL, + .pfn_timer = fn_timer, + .pfn_counter = fn_counter, }; |
