Skip to content

Commit 35ae40e

Browse files
dyronegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 050d0dc commit 35ae40e

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Documentation/technical/api-trace2.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
717717
{
718718
"event":"def_param",
719719
...
720+
"scope":"global",
720721
"param":"core.abbrev",
721722
"value":"7"
722723
}
@@ -1216,7 +1217,13 @@ We can optionally emit configuration events, see
12161217
it.
12171218
+
12181219
----------------
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
12201227
----------------
12211228
+
12221229
Then, mark the config `color.ui` as "interesting" config with
@@ -1232,11 +1239,13 @@ $ cat ~/log.perf
12321239
d0 | main | version | | | | | ...
12331240
d0 | main | start | | 0.001642 | | | /usr/local/bin/git version
12341241
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
12361245
d0 | main | data | r0 | 0.002100 | 0.002100 | fsync | fsync/writeout-only:0
12371246
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
12401249
----------------
12411250
== Future Work
12421251

trace2/tr2_tgt_event.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
479479
{
480480
const char *event_name = "def_param";
481481
struct json_writer jw = JSON_WRITER_INIT;
482+
enum config_scope scope = current_config_scope();
483+
const char *scope_name = config_scope_name(scope);
482484

483485
jw_object_begin(&jw, 0);
484486
event_fmt_prepare(event_name, file, line, NULL, &jw);
487+
jw_object_string(&jw, "scope", scope_name);
485488
jw_object_string(&jw, "param", param);
486489
jw_object_string(&jw, "value", value);
487490
jw_end(&jw);

trace2/tr2_tgt_normal.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
298298
const char *value)
299299
{
300300
struct strbuf buf_payload = STRBUF_INIT;
301+
enum config_scope scope = current_config_scope();
302+
const char *scope_name = config_scope_name(scope);
301303

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);
303306
normal_io_write_fl(file, line, &buf_payload);
304307
strbuf_release(&buf_payload);
305308
}

trace2/tr2_tgt_perf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
441441
{
442442
const char *event_name = "def_param";
443443
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);
444447

445448
strbuf_addf(&buf_payload, "%s:%s", param, value);
449+
strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
446450

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);
449453
strbuf_release(&buf_payload);
454+
strbuf_release(&scope_payload);
450455
}
451456

452457
static void fn_repo_fl(const char *file, int line,

0 commit comments

Comments
 (0)