diff options
Diffstat (limited to 'trace2/tr2_tgt_event.c')
-rw-r--r-- | trace2/tr2_tgt_event.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 89a4d3ae9a..48d9193b2c 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -6,10 +6,11 @@ #include "trace2/tr2_dst.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 }; +static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 }; /* * The version number of the JSON data generated by the EVENT target @@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 }; * are primarily intended for the performance target during debugging. * * Some of the outer-most messages, however, may be of interest to the - * event target. Set this environment variable to a larger integer for - * more detail in the event target. + * event target. Use the TR2_SYSENV_EVENT_NESTING setting to increase + * region details in the event target. */ -#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING" -static int tr2env_event_nesting_wanted = 2; +static int tr2env_event_max_nesting_levels = 2; /* - * Set this environment variable to true to omit the <time>, <file>, and + * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and * <line> fields from most events. */ -#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF" -static int tr2env_event_brief; +static int tr2env_event_be_brief; static int fn_init(void) { int want = tr2_dst_trace_want(&tr2dst_event); - int want_nesting; + int max_nesting; int want_brief; - char *nesting; - char *brief; + const char *nesting; + const char *brief; if (!want) return want; - nesting = getenv(TR2_ENVVAR_EVENT_NESTING); - if (nesting && ((want_nesting = atoi(nesting)) > 0)) - tr2env_event_nesting_wanted = want_nesting; + nesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING); + if (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0)) + tr2env_event_max_nesting_levels = max_nesting; - brief = getenv(TR2_ENVVAR_EVENT_BRIEF); - if (brief && ((want_brief = atoi(brief)) > 0)) - tr2env_event_brief = want_brief; + brief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF); + if (brief && *brief && + ((want_brief = git_parse_maybe_bool(brief)) != -1)) + tr2env_event_be_brief = want_brief; return want; } @@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file, /* * In brief mode, only emit <time> on these 2 event types. */ - if (!tr2env_event_brief || !strcmp(event_name, "version") || + if (!tr2env_event_be_brief || !strcmp(event_name, "version") || !strcmp(event_name, "atexit")) { tr2_tbuf_utc_time(&tb_now); jw_object_string(jw, "time", tb_now.buf); } - if (!tr2env_event_brief && file && *file) { + if (!tr2env_event_be_brief && file && *file) { jw_object_string(jw, "file", file); jw_object_intmax(jw, "line", line); } @@ -459,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line, { const char *event_name = "region_enter"; struct tr2tls_thread_ctx *ctx = tr2tls_get_self(); - if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) { + if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) { struct json_writer jw = JSON_WRITER_INIT; jw_object_begin(&jw, 0); @@ -484,7 +484,7 @@ static void fn_region_leave_printf_va_fl( { const char *event_name = "region_leave"; struct tr2tls_thread_ctx *ctx = tr2tls_get_self(); - if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) { + if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) { struct json_writer jw = JSON_WRITER_INIT; double t_rel = (double)us_elapsed_region / 1000000.0; @@ -511,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute, { const char *event_name = "data"; struct tr2tls_thread_ctx *ctx = tr2tls_get_self(); - if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) { + if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) { struct json_writer jw = JSON_WRITER_INIT; double t_abs = (double)us_elapsed_absolute / 1000000.0; double t_rel = (double)us_elapsed_region / 1000000.0; @@ -539,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line, { const char *event_name = "data_json"; struct tr2tls_thread_ctx *ctx = tr2tls_get_self(); - if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) { + if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) { struct json_writer jw = JSON_WRITER_INIT; double t_abs = (double)us_elapsed_absolute / 1000000.0; double t_rel = (double)us_elapsed_region / 1000000.0; |