From ee4512ed481a126dadd33334186e0e759d7f2f47 Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 22 Feb 2019 14:25:01 -0800 Subject: trace2: create new combined trace facility Create a new unified tracing facility for git. The eventual intent is to replace the current trace_printf* and trace_performance* routines with a unified set of git_trace2* routines. In addition to the usual printf-style API, trace2 provides higer-level event verbs with fixed-fields allowing structured data to be written. This makes post-processing and analysis easier for external tools. Trace2 defines 3 output targets. These are set using the environment variables "GIT_TR2", "GIT_TR2_PERF", and "GIT_TR2_EVENT". These may be set to "1" or to an absolute pathname (just like the current GIT_TRACE). * GIT_TR2 is intended to be a replacement for GIT_TRACE and logs command summary data. * GIT_TR2_PERF is intended as a replacement for GIT_TRACE_PERFORMANCE. It extends the output with columns for the command process, thread, repo, absolute and relative elapsed times. It reports events for child process start/stop, thread start/stop, and per-thread function nesting. * GIT_TR2_EVENT is a new structured format. It writes event data as a series of JSON records. Calls to trace2 functions log to any of the 3 output targets enabled without the need to call different trace_printf* or trace_performance* routines. Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b80fc4ba3d..6bcc4f1bd7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1816,11 +1816,10 @@ static int update_submodules(struct submodule_update_clone *suc) { int i; - run_processes_parallel(suc->max_jobs, - update_clone_get_next_task, - update_clone_start_failure, - update_clone_task_finished, - suc); + run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, + update_clone_start_failure, + update_clone_task_finished, suc, "submodule", + "parallel/update"); /* * We saved the output and put it out all at once now. -- cgit v1.2.3 From 6206286e49b88bd4bb709c62e7b7455685c1993a Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 22 Feb 2019 14:25:06 -0800 Subject: trace2:data: add trace2 hook classification Classify certain child processes as hooks. Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/am.c | 1 + builtin/receive-pack.c | 4 ++++ builtin/worktree.c | 1 + 3 files changed, 6 insertions(+) (limited to 'builtin') diff --git a/builtin/am.c b/builtin/am.c index 58a2aef28b..cca494d9c3 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -453,6 +453,7 @@ static int run_post_rewrite_hook(const struct am_state *state) cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); cp.stdout_to_stderr = 1; + cp.trace2_hook_name = "post-rewrite"; ret = run_command(&cp); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d58b7750b6..8bc714a5fc 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -694,6 +694,8 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, proc.argv = argv; proc.in = -1; proc.stdout_to_stderr = 1; + proc.trace2_hook_name = hook_name; + if (feed_state->push_options) { int i; for (i = 0; i < feed_state->push_options->nr; i++) @@ -807,6 +809,7 @@ static int run_update_hook(struct command *cmd) proc.stdout_to_stderr = 1; proc.err = use_sideband ? -1 : 0; proc.argv = argv; + proc.trace2_hook_name = "update"; code = start_command(&proc); if (code) @@ -1190,6 +1193,7 @@ static void run_update_post_hook(struct command *commands) proc.no_stdin = 1; proc.stdout_to_stderr = 1; proc.err = use_sideband ? -1 : 0; + proc.trace2_hook_name = "post-update"; if (!start_command(&proc)) { if (use_sideband) diff --git a/builtin/worktree.c b/builtin/worktree.c index 3f9907fcc9..6cc094a453 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -402,6 +402,7 @@ done: cp.dir = path; cp.env = env; cp.argv = NULL; + cp.trace2_hook_name = "post-checkout"; argv_array_pushl(&cp.args, absolute_path(hook), oid_to_hex(&null_oid), oid_to_hex(&commit->object.oid), -- cgit v1.2.3 From ae417807b01b34b7fd4f1a5a9d889b34f8a563d2 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Fri, 22 Feb 2019 14:25:07 -0800 Subject: trace2:data: pack-objects: add trace2 regions When studying the performance of 'git push' we would like to know how much time is spent at various parts of the command. One area that could cause performance trouble is 'git pack-objects'. Add trace2 regions around the three main actions taken in this command: 1. Enumerate objects. 2. Prepare pack. 3. Write pack-file. Signed-off-by: Derrick Stolee Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/pack-objects.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index a9fac7c128..a154fc29f6 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -33,6 +33,7 @@ #include "object-store.h" #include "dir.h" #include "midx.h" +#include "trace2.h" #define IN_PACK(obj) oe_in_pack(&to_pack, obj) #define SIZE(obj) oe_size(&to_pack, obj) @@ -3473,6 +3474,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } } + trace2_region_enter("pack-objects", "enumerate-objects", + the_repository); prepare_packing_data(the_repository, &to_pack); if (progress) @@ -3487,12 +3490,23 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (include_tag && nr_result) for_each_ref(add_ref_tag, NULL); stop_progress(&progress_state); + trace2_region_leave("pack-objects", "enumerate-objects", + the_repository); if (non_empty && !nr_result) return 0; - if (nr_result) + if (nr_result) { + trace2_region_enter("pack-objects", "prepare-pack", + the_repository); prepare_pack(window, depth); + trace2_region_leave("pack-objects", "prepare-pack", + the_repository); + } + + trace2_region_enter("pack-objects", "write-pack-file", the_repository); write_pack_file(); + trace2_region_leave("pack-objects", "write-pack-file", the_repository); + if (progress) fprintf_ln(stderr, _("Total %"PRIu32" (delta %"PRIu32")," -- cgit v1.2.3 From e27dd8ae9ff894b60d2f9212db7ff9ce80e2826b Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 22 Feb 2019 14:25:08 -0800 Subject: trace2:data: add subverb to checkout command Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/checkout.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index 24b8593b93..c14e8c5610 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -263,6 +263,8 @@ static int checkout_paths(const struct checkout_opts *opts, struct lock_file lock_file = LOCK_INIT; int nr_checkouts = 0, nr_unmerged = 0; + trace2_cmd_mode(opts->patch_mode ? "patch" : "path"); + if (opts->track != BRANCH_TRACK_UNSPECIFIED) die(_("'%s' cannot be used with updating paths"), "--track"); @@ -966,6 +968,9 @@ static int switch_branches(const struct checkout_opts *opts, void *path_to_free; struct object_id rev; int flag, writeout_error = 0; + + trace2_cmd_mode("branch"); + memset(&old_branch_info, 0, sizeof(old_branch_info)); old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag); if (old_branch_info.path) @@ -1203,6 +1208,8 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts) int status; struct strbuf branch_ref = STRBUF_INIT; + trace2_cmd_mode("unborn"); + if (!opts->new_branch) die(_("You are on a branch yet to be born")); strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch); -- cgit v1.2.3 From c18b6c1a2b8cea158d91481e38f983cd664a9aa0 Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 22 Feb 2019 14:25:09 -0800 Subject: trace2:data: add subverb to reset command Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/reset.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'builtin') diff --git a/builtin/reset.c b/builtin/reset.c index 4d18a461fa..7882829a95 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -341,6 +341,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (patch_mode) { if (reset_type != NONE) die(_("--patch is incompatible with --{hard,mixed,soft}")); + trace2_cmd_mode("patch-interactive"); return run_add_interactive(rev, "--patch=reset", &pathspec); } @@ -357,6 +358,11 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type == NONE) reset_type = MIXED; /* by default */ + if (pathspec.nr) + trace2_cmd_mode("path"); + else + trace2_cmd_mode(reset_type_names[reset_type]); + if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree())) setup_work_tree(); -- cgit v1.2.3 From b3a5d5a80ce76ebfc1f7c86afe985562174b6325 Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 22 Feb 2019 14:25:10 -0800 Subject: trace2:data: add subverb for rebase Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- builtin/rebase.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index 7c7bc13e91..52114cbf0d 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1027,6 +1027,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) ACTION_EDIT_TODO, ACTION_SHOW_CURRENT_PATCH, } action = NO_ACTION; + static const char *action_names[] = { N_("undefined"), + N_("continue"), + N_("skip"), + N_("abort"), + N_("quit"), + N_("edit_todo"), + N_("show_current_patch"), + NULL }; const char *gpg_sign = NULL; struct string_list exec = STRING_LIST_INIT_NODUP; const char *rebase_merges = NULL; @@ -1212,6 +1220,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("The --edit-todo action can only be used during " "interactive rebase.")); + if (trace2_is_enabled()) { + if (is_interactive(&options)) + trace2_cmd_mode("interactive"); + else if (exec.nr) + trace2_cmd_mode("interactive-exec"); + else + trace2_cmd_mode(action_names[action]); + } + switch (action) { case ACTION_CONTINUE: { struct object_id head; -- cgit v1.2.3