diff options
Diffstat (limited to 'trace2')
-rw-r--r-- | trace2/tr2_cfg.c | 58 | ||||
-rw-r--r-- | trace2/tr2_cfg.h | 8 | ||||
-rw-r--r-- | trace2/tr2_sid.c | 2 | ||||
-rw-r--r-- | trace2/tr2_sysenv.c | 2 | ||||
-rw-r--r-- | trace2/tr2_sysenv.h | 1 | ||||
-rw-r--r-- | trace2/tr2_tgt_perf.c | 17 |
6 files changed, 72 insertions, 16 deletions
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c index caa7f06948..ec9ac1a6ef 100644 --- a/trace2/tr2_cfg.c +++ b/trace2/tr2_cfg.c @@ -7,6 +7,10 @@ static struct strbuf **tr2_cfg_patterns; static int tr2_cfg_count_patterns; static int tr2_cfg_loaded; +static struct strbuf **tr2_cfg_env_vars; +static int tr2_cfg_env_vars_count; +static int tr2_cfg_env_vars_loaded; + /* * Parse a string containing a comma-delimited list of config keys * or wildcard patterns into a list of strbufs. @@ -46,6 +50,45 @@ void tr2_cfg_free_patterns(void) tr2_cfg_loaded = 0; } +/* + * Parse a string containing a comma-delimited list of environment variable + * names into a list of strbufs. + */ +static int tr2_load_env_vars(void) +{ + struct strbuf **s; + const char *varlist; + + if (tr2_cfg_env_vars_loaded) + return tr2_cfg_env_vars_count; + tr2_cfg_env_vars_loaded = 1; + + varlist = tr2_sysenv_get(TR2_SYSENV_ENV_VARS); + if (!varlist || !*varlist) + return tr2_cfg_env_vars_count; + + tr2_cfg_env_vars = strbuf_split_buf(varlist, strlen(varlist), ',', -1); + for (s = tr2_cfg_env_vars; *s; s++) { + struct strbuf *buf = *s; + + if (buf->len && buf->buf[buf->len - 1] == ',') + strbuf_setlen(buf, buf->len - 1); + strbuf_trim_trailing_newline(*s); + strbuf_trim(*s); + } + + tr2_cfg_env_vars_count = s - tr2_cfg_env_vars; + return tr2_cfg_env_vars_count; +} + +void tr2_cfg_free_env_vars(void) +{ + if (tr2_cfg_env_vars) + strbuf_list_free(tr2_cfg_env_vars); + tr2_cfg_env_vars_count = 0; + tr2_cfg_env_vars_loaded = 0; +} + struct tr2_cfg_data { const char *file; int line; @@ -79,6 +122,21 @@ void tr2_cfg_list_config_fl(const char *file, int line) read_early_config(tr2_cfg_cb, &data); } +void tr2_list_env_vars_fl(const char *file, int line) +{ + struct strbuf **s; + + if (tr2_load_env_vars() <= 0) + return; + + for (s = tr2_cfg_env_vars; *s; s++) { + struct strbuf *buf = *s; + const char *val = getenv(buf->buf); + if (val && *val) + trace2_def_param_fl(file, line, buf->buf, val); + } +} + void tr2_cfg_set_fl(const char *file, int line, const char *key, const char *value) { diff --git a/trace2/tr2_cfg.h b/trace2/tr2_cfg.h index d9c98f64dd..a11d71feb5 100644 --- a/trace2/tr2_cfg.h +++ b/trace2/tr2_cfg.h @@ -8,6 +8,12 @@ void tr2_cfg_list_config_fl(const char *file, int line); /* + * Iterate over all "interesting" environment variables and emit 'def_param' + * events for them to TRACE2. + */ +void tr2_list_env_vars_fl(const char *file, int line); + +/* * Emit a "def_param" event for the given key/value pair IF we consider * the key to be "interesting". */ @@ -16,4 +22,6 @@ void tr2_cfg_set_fl(const char *file, int line, const char *key, void tr2_cfg_free_patterns(void); +void tr2_cfg_free_env_vars(void); + #endif /* TR2_CFG_H */ diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index 6948fd4108..dc6e75ef13 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -19,7 +19,7 @@ static int tr2sid_nr_git_parents; * "H<first_8_chars_of_sha1_of_hostname>" * "Localhost" when no hostname. * - * where <process> is a 9 character string containing the least signifcant + * where <process> is a 9 character string containing the least significant * 32 bits in the process-id. * "P<pid>" * (This is an abribrary choice. On most systems pid_t is a 32 bit value, diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c index 3c3792eca2..a380dcf910 100644 --- a/trace2/tr2_sysenv.c +++ b/trace2/tr2_sysenv.c @@ -29,6 +29,8 @@ struct tr2_sysenv_entry { static struct tr2_sysenv_entry tr2_sysenv_settings[] = { [TR2_SYSENV_CFG_PARAM] = { "GIT_TRACE2_CONFIG_PARAMS", "trace2.configparams" }, + [TR2_SYSENV_ENV_VARS] = { "GIT_TRACE2_ENV_VARS", + "trace2.envvars" }, [TR2_SYSENV_DST_DEBUG] = { "GIT_TRACE2_DST_DEBUG", "trace2.destinationdebug" }, diff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h index d4364a7b85..3292ee15bc 100644 --- a/trace2/tr2_sysenv.h +++ b/trace2/tr2_sysenv.h @@ -11,6 +11,7 @@ */ enum tr2_sysenv_variable { TR2_SYSENV_CFG_PARAM = 0, + TR2_SYSENV_ENV_VARS, TR2_SYSENV_DST_DEBUG, diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c index ffac8029ad..a8018f18cc 100644 --- a/trace2/tr2_tgt_perf.c +++ b/trace2/tr2_tgt_perf.c @@ -26,12 +26,9 @@ static int tr2env_perf_be_brief; #define TR2FMT_PERF_REPO_WIDTH (3) #define TR2FMT_PERF_CATEGORY_WIDTH (12) -#define TR2_DOTS_BUFFER_SIZE (100) #define TR2_INDENT (2) #define TR2_INDENT_LENGTH(ctx) (((ctx)->nr_open_regions - 1) * TR2_INDENT) -static struct strbuf dots = STRBUF_INIT; - static int fn_init(void) { int want = tr2_dst_trace_want(&tr2dst_perf); @@ -41,8 +38,6 @@ static int fn_init(void) if (!want) return want; - strbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE); - brief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF); if (brief && *brief && ((want_brief = git_parse_maybe_bool(brief)) != -1)) @@ -54,8 +49,6 @@ static int fn_init(void) static void fn_term(void) { tr2_dst_trace_disable(&tr2dst_perf); - - strbuf_release(&dots); } /* @@ -138,14 +131,8 @@ static void perf_fmt_prepare(const char *event_name, strbuf_addf(buf, "%-*.*s | ", TR2FMT_PERF_CATEGORY_WIDTH, TR2FMT_PERF_CATEGORY_WIDTH, (category ? category : "")); - if (ctx->nr_open_regions > 0) { - int len_indent = TR2_INDENT_LENGTH(ctx); - while (len_indent > dots.len) { - strbuf_addbuf(buf, &dots); - len_indent -= dots.len; - } - strbuf_addf(buf, "%.*s", len_indent, dots.buf); - } + if (ctx->nr_open_regions > 0) + strbuf_addchars(buf, '.', TR2_INDENT_LENGTH(ctx)); } static void perf_io_write_fl(const char *file, int line, const char *event_name, |