Skip to content

Commit 9084feb

Browse files
committed
Merge branch 'jh/trace2-missing-def-param-fix' into jch
Some trace2 events that lacked def_param have learned to show it, enriching the output. Reviewed-by: Josh Steadmon <[email protected]> cf. <[email protected]> * jh/trace2-missing-def-param-fix: trace2: emit 'def_param' set with 'cmd_name' event trace2: avoid emitting 'def_param' set more than once t0211: demonstrate missing 'def_param' events for certain commands
2 parents 8d0d56e + 6111252 commit 9084feb

File tree

3 files changed

+246
-6
lines changed

3 files changed

+246
-6
lines changed

git.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,6 @@ static int handle_alias(int *argcp, const char ***argv)
379379
strvec_pushv(&child.args, (*argv) + 1);
380380

381381
trace2_cmd_alias(alias_command, child.args.v);
382-
trace2_cmd_list_config();
383-
trace2_cmd_list_env_vars();
384382
trace2_cmd_name("_run_shell_alias_");
385383

386384
ret = run_command(&child);
@@ -417,8 +415,6 @@ static int handle_alias(int *argcp, const char ***argv)
417415
COPY_ARRAY(new_argv + count, *argv + 1, *argcp);
418416

419417
trace2_cmd_alias(alias_command, new_argv);
420-
trace2_cmd_list_config();
421-
trace2_cmd_list_env_vars();
422418

423419
*argv = new_argv;
424420
*argcp += count - 1;
@@ -468,8 +464,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
468464

469465
trace_argv_printf(argv, "trace: built-in: git");
470466
trace2_cmd_name(p->cmd);
471-
trace2_cmd_list_config();
472-
trace2_cmd_list_env_vars();
473467

474468
validate_cache_entries(the_repository->index);
475469
status = p->fn(argc, argv, prefix);

t/t0211-trace2-perf.sh

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,235 @@ test_expect_success 'unsafe URLs are redacted by default' '
287287
grep "d0|main|def_param|.*|remote.origin.url:https://user:[email protected]" actual
288288
'
289289

290+
# Confirm that the requested command produces a "cmd_name" and a
291+
# set of "def_param" events.
292+
#
293+
try_simple () {
294+
test_when_finished "rm prop.perf actual" &&
295+
296+
cmd=$1 &&
297+
cmd_name=$2 &&
298+
299+
test_config_global "trace2.configParams" "cfg.prop.*" &&
300+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
301+
302+
test_config_global "cfg.prop.foo" "red" &&
303+
304+
ENV_PROP_FOO=blue \
305+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
306+
$cmd &&
307+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
308+
grep "d0|main|cmd_name|.*|$cmd_name" actual &&
309+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
310+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual
311+
}
312+
313+
# Representative mainstream builtin Git command dispatched
314+
# in run_builtin() in git.c
315+
#
316+
test_expect_success 'expect def_params for normal builtin command' '
317+
try_simple "git version" "version"
318+
'
319+
320+
# Representative query command dispatched in handle_options()
321+
# in git.c
322+
#
323+
test_expect_success 'expect def_params for query command' '
324+
try_simple "git --man-path" "_query_"
325+
'
326+
327+
# remote-curl.c does not use the builtin setup in git.c, so confirm
328+
# that executables built from remote-curl.c emit def_params.
329+
#
330+
# Also tests the dashed-command handling where "git foo" silently
331+
# spawns "git-foo". Make sure that both commands should emit
332+
# def_params.
333+
#
334+
# Pass bogus arguments to remote-https and allow the command to fail
335+
# because we don't actually have a remote to fetch from. We just want
336+
# to see the run-dashed code run an executable built from
337+
# remote-curl.c rather than git.c. Confirm that we get def_param
338+
# events from both layers.
339+
#
340+
test_expect_success 'expect def_params for remote-curl and _run_dashed_' '
341+
test_when_finished "rm prop.perf actual" &&
342+
343+
test_config_global "trace2.configParams" "cfg.prop.*" &&
344+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
345+
346+
test_config_global "cfg.prop.foo" "red" &&
347+
348+
test_might_fail env \
349+
ENV_PROP_FOO=blue \
350+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
351+
git remote-http x y &&
352+
353+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
354+
355+
grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
356+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
357+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
358+
359+
grep "d1|main|cmd_name|.*|remote-curl" actual &&
360+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
361+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
362+
'
363+
364+
# Similarly, `git-http-fetch` is not built from git.c so do a
365+
# trivial fetch so that the main git.c run-dashed code spawns
366+
# an executable built from http-fetch.c. Confirm that we get
367+
# def_param events from both layers.
368+
#
369+
test_expect_success 'expect def_params for http-fetch and _run_dashed_' '
370+
test_when_finished "rm prop.perf actual" &&
371+
372+
test_config_global "trace2.configParams" "cfg.prop.*" &&
373+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
374+
375+
test_config_global "cfg.prop.foo" "red" &&
376+
377+
test_might_fail env \
378+
ENV_PROP_FOO=blue \
379+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
380+
git http-fetch --stdin file:/// <<-EOF &&
381+
EOF
382+
383+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
384+
385+
grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
386+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
387+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
388+
389+
grep "d1|main|cmd_name|.*|http-fetch" actual &&
390+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
391+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
392+
'
393+
394+
# Historically, alias expansion explicitly emitted the def_param
395+
# events (independent of whether the command was a builtin, a Git
396+
# command or arbitrary shell command) so that it wasn't dependent
397+
# upon the unpeeling of the alias. Let's make sure that we preserve
398+
# the net effect.
399+
#
400+
test_expect_success 'expect def_params during git alias expansion' '
401+
test_when_finished "rm prop.perf actual" &&
402+
403+
test_config_global "trace2.configParams" "cfg.prop.*" &&
404+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
405+
406+
test_config_global "cfg.prop.foo" "red" &&
407+
408+
test_config_global "alias.xxx" "version" &&
409+
410+
ENV_PROP_FOO=blue \
411+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
412+
git xxx &&
413+
414+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
415+
416+
# "git xxx" is first mapped to "git-xxx" and the child will fail.
417+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
418+
419+
# We unpeel that and substitute "version" into "xxx" (giving
420+
# "git version") and update the cmd_name event.
421+
grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_git_alias_)" actual &&
422+
423+
# These def_param events could be associated with either of the
424+
# above cmd_name events. It does not matter.
425+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
426+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
427+
428+
# The "git version" child sees a different cmd_name hierarchy.
429+
# Also test the def_param (only for completeness).
430+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_git_alias_/version)" actual &&
431+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
432+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
433+
'
434+
435+
test_expect_success 'expect def_params during shell alias expansion' '
436+
test_when_finished "rm prop.perf actual" &&
437+
438+
test_config_global "trace2.configParams" "cfg.prop.*" &&
439+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
440+
441+
test_config_global "cfg.prop.foo" "red" &&
442+
443+
test_config_global "alias.xxx" "!git version" &&
444+
445+
ENV_PROP_FOO=blue \
446+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
447+
git xxx &&
448+
449+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
450+
451+
# "git xxx" is first mapped to "git-xxx" and the child will fail.
452+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
453+
454+
# We unpeel that and substitute "git version" for "git xxx" (as a
455+
# shell command. Another cmd_name event is emitted as we unpeel.
456+
grep "d0|main|cmd_name|.*|_run_shell_alias_ (_run_dashed_/_run_shell_alias_)" actual &&
457+
458+
# These def_param events could be associated with either of the
459+
# above cmd_name events. It does not matter.
460+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
461+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
462+
463+
# We get the following only because we used a git command for the
464+
# shell command. In general, it could have been a shell script and
465+
# we would see nothing.
466+
#
467+
# The child knows the cmd_name hierarchy so it includes it.
468+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_shell_alias_/version)" actual &&
469+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
470+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
471+
'
472+
473+
test_expect_success 'expect def_params during nested git alias expansion' '
474+
test_when_finished "rm prop.perf actual" &&
475+
476+
test_config_global "trace2.configParams" "cfg.prop.*" &&
477+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
478+
479+
test_config_global "cfg.prop.foo" "red" &&
480+
481+
test_config_global "alias.xxx" "yyy" &&
482+
test_config_global "alias.yyy" "version" &&
483+
484+
ENV_PROP_FOO=blue \
485+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
486+
git xxx &&
487+
488+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
489+
490+
# "git xxx" is first mapped to "git-xxx" and try to spawn "git-xxx"
491+
# and the child will fail.
492+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
493+
grep "d0|main|child_start|.*|.* class:dashed argv:\[git-xxx\]" actual &&
494+
495+
# We unpeel that and substitute "yyy" into "xxx" (giving "git yyy")
496+
# and spawn "git-yyy" and the child will fail.
497+
grep "d0|main|alias|.*|alias:xxx argv:\[yyy\]" actual &&
498+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_/_run_dashed_)" actual &&
499+
grep "d0|main|child_start|.*|.* class:dashed argv:\[git-yyy\]" actual &&
500+
501+
# We unpeel that and substitute "version" into "xxx" (giving
502+
# "git version") and update the cmd_name event.
503+
grep "d0|main|alias|.*|alias:yyy argv:\[version\]" actual &&
504+
grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_dashed_/_run_git_alias_)" actual &&
505+
506+
# These def_param events could be associated with any of the
507+
# above cmd_name events. It does not matter.
508+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual >actual.matches &&
509+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
510+
511+
# However, we do not want them repeated each time we unpeel.
512+
test_line_count = 1 actual.matches &&
513+
514+
# The "git version" child sees a different cmd_name hierarchy.
515+
# Also test the def_param (only for completeness).
516+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_dashed_/_run_git_alias_/version)" actual &&
517+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
518+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
519+
'
520+
290521
test_done

trace2.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ void trace2_cmd_name_fl(const char *file, int line, const char *name)
433433
for_each_wanted_builtin (j, tgt_j)
434434
if (tgt_j->pfn_command_name_fl)
435435
tgt_j->pfn_command_name_fl(file, line, name, hierarchy);
436+
437+
trace2_cmd_list_config();
438+
trace2_cmd_list_env_vars();
436439
}
437440

438441
void trace2_cmd_mode_fl(const char *file, int line, const char *mode)
@@ -464,17 +467,29 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,
464467

465468
void trace2_cmd_list_config_fl(const char *file, int line)
466469
{
470+
static int emitted = 0;
471+
467472
if (!trace2_enabled)
468473
return;
469474

475+
if (emitted)
476+
return;
477+
emitted = 1;
478+
470479
tr2_cfg_list_config_fl(file, line);
471480
}
472481

473482
void trace2_cmd_list_env_vars_fl(const char *file, int line)
474483
{
484+
static int emitted = 0;
485+
475486
if (!trace2_enabled)
476487
return;
477488

489+
if (emitted)
490+
return;
491+
emitted = 1;
492+
478493
tr2_list_env_vars_fl(file, line);
479494
}
480495

0 commit comments

Comments
 (0)