tr2: shows scope unconditionally in addition to key-value pair

When we specify GIT_TRACE2_CONFIG_PARAMS or trace2.configparams, trace2 will prints "interesting" config values to log. Sometimes, when a config set in multiple scope files, the following output looks like (the irrelevant fields are omitted here as "..."): ...| def_param | ... | core.multipackindex:false ...| def_param | ... | core.multipackindex:false ...| def_param | ... | core.multipackindex:false As the log shows, even each config in different scope is dumped, but we don't know which scope it comes from. Therefore, it's better to add the scope names as well to make them be more recognizable. For example, when execute: $ GIT_TRACE2_PERF=1 \ > GIT_TRACE2_CONFIG_PARAMS=core.multipackIndex \ > git rev-list --test-bitmap HEAD" The following is the ouput (the irrelevant fields are omitted here as "..."): Format normal: ... git.c:461 ... def_param scope:system core.multipackindex=false ... git.c:461 ... def_param scope:global core.multipackindex=false ... git.c:461 ... def_param scope:local core.multipackindex=false Format perf: ... | def_param | ... | scope:system | core.multipackindex:false ... | def_param | ... | scope:global | core.multipackindex:false ... | def_param | ... | scope:local | core.multipackindex:false Format event: {"event":"def_param", ... ,"scope":"system","param":"core.multipackindex","value":"false"} {"event":"def_param", ... ,"scope":"global","param":"core.multipackindex","value":"false"} {"event":"def_param", ... ,"scope":"local","param":"core.multipackindex","value":"false"} Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Teng Long committed Aug 12, 2022 at 10:56 UTC 35ae40ead34f29c827abf101ba4e5412c2e67ab0
4 files changed +27 -7
Documentation/technical/api-trace2.txt
+13 -4
@@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
717 {
718 "event":"def_param",
719 ...
720 + "scope":"global",
721 "param":"core.abbrev",
722 "value":"7"
723 }
@@ -1216,7 +1217,13 @@ We can optionally emit configuration events, see
1217 it.
1218 +
1219 ----------------
1219 -$ git config color.ui auto
1220 +$ git config --system color.ui never
1221 +$ git config --global color.ui always
1222 +$ git config --local color.ui auto
1223 +$ git config --list --show-scope | grep 'color.ui'
1224 +system color.ui=never
1225 +global color.ui=always
1226 +local color.ui=auto
1227 ----------------
1228 +
1229 Then, mark the config `color.ui` as "interesting" config with
@@ -1232,11 +1239,13 @@ $ cat ~/log.perf
1239 d0 | main | version | | | | | ...
1240 d0 | main | start | | 0.001642 | | | /usr/local/bin/git version
1241 d0 | main | cmd_name | | | | | version (version)
1235 -d0 | main | def_param | | | | | color.ui:auto
1242 +d0 | main | def_param | | | | scope:system | color.ui:never
1243 +d0 | main | def_param | | | | scope:global | color.ui:always
1244 +d0 | main | def_param | | | | scope:local | color.ui:auto
1245 d0 | main | data | r0 | 0.002100 | 0.002100 | fsync | fsync/writeout-only:0
1246 d0 | main | data | r0 | 0.002126 | 0.002126 | fsync | fsync/hardware-flush:0
1238 -d0 | main | exit | | 0.002142 | | | code:0
1239 -d0 | main | atexit | | 0.002161 | | | code:0
1247 +d0 | main | exit | | 0.000470 | | | code:0
1248 +d0 | main | atexit | | 0.000477 | | | code:0
1249 ----------------
1250 == Future Work
1251
trace2/tr2_tgt_event.c
+3
@@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
479 {
480 const char *event_name = "def_param";
481 struct json_writer jw = JSON_WRITER_INIT;
482 + enum config_scope scope = current_config_scope();
483 + const char *scope_name = config_scope_name(scope);
484
485 jw_object_begin(&jw, 0);
486 event_fmt_prepare(event_name, file, line, NULL, &jw);
487 + jw_object_string(&jw, "scope", scope_name);
488 jw_object_string(&jw, "param", param);
489 jw_object_string(&jw, "value", value);
490 jw_end(&jw);
trace2/tr2_tgt_normal.c
+4 -1
@@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
298 const char *value)
299 {
300 struct strbuf buf_payload = STRBUF_INIT;
301 + enum config_scope scope = current_config_scope();
302 + const char *scope_name = config_scope_name(scope);
303
302 - strbuf_addf(&buf_payload, "def_param %s=%s", param, value);
304 + strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
305 + value);
306 normal_io_write_fl(file, line, &buf_payload);
307 strbuf_release(&buf_payload);
308 }
trace2/tr2_tgt_perf.c
+7 -2
@@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
441 {
442 const char *event_name = "def_param";
443 struct strbuf buf_payload = STRBUF_INIT;
444 + struct strbuf scope_payload = STRBUF_INIT;
445 + enum config_scope scope = current_config_scope();
446 + const char *scope_name = config_scope_name(scope);
447
448 strbuf_addf(&buf_payload, "%s:%s", param, value);
449 + strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
450
447 - perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
448 - &buf_payload);
451 + perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
452 + scope_payload.buf, &buf_payload);
453 strbuf_release(&buf_payload);
454 + strbuf_release(&scope_payload);
455 }
456
457 static void fn_repo_fl(const char *file, int line,