fetch: add top-level trace2 regions

At $DAYJOB we experienced some slow fetch operations and needed some additional data to help diagnose the issue. Add top-level trace2 regions for the various modes of operation of `git-fetch`. None of these regions are in recursive code, so any enclosed trace messages should only see their nesting level increase by one. Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh Steadmon committed Aug 22, 2024 at 14:57 UTC a45ab549879d0f8e2524f820796daf2f6a1f7d00
2 files changed +19 -1
builtin/fetch.c
+15 -1
@@ -2408,6 +2408,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2408 struct oidset_iter iter;
2409 const struct object_id *oid;
2410
2411 + trace2_region_enter("fetch", "negotiate-only", the_repository);
2412 if (!remote)
2413 die(_("must supply remote when using --negotiate-only"));
2414 gtransport = prepare_transport(remote, 1);
@@ -2416,6 +2417,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2417 } else {
2418 warning(_("protocol does not support --negotiate-only, exiting"));
2419 result = 1;
2420 + trace2_region_leave("fetch", "negotiate-only", the_repository);
2421 goto cleanup;
2422 }
2423 if (server_options.nr)
@@ -2426,11 +2428,17 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2428 while ((oid = oidset_iter_next(&iter)))
2429 printf("%s\n", oid_to_hex(oid));
2430 oidset_clear(&acked_commits);
2431 + trace2_region_leave("fetch", "negotiate-only", the_repository);
2432 } else if (remote) {
2430 - if (filter_options.choice || repo_has_promisor_remote(the_repository))
2433 + if (filter_options.choice || repo_has_promisor_remote(the_repository)) {
2434 + trace2_region_enter("fetch", "setup-partial", the_repository);
2435 fetch_one_setup_partial(remote);
2436 + trace2_region_leave("fetch", "setup-partial", the_repository);
2437 + }
2438 + trace2_region_enter("fetch", "fetch-one", the_repository);
2439 result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs,
2440 &config);
2441 + trace2_region_leave("fetch", "fetch-one", the_repository);
2442 } else {
2443 int max_children = max_jobs;
2444
@@ -2450,7 +2458,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2458 max_children = config.parallel;
2459
2460 /* TODO should this also die if we have a previous partial-clone? */
2461 + trace2_region_enter("fetch", "fetch-multiple", the_repository);
2462 result = fetch_multiple(&list, max_children, &config);
2463 + trace2_region_leave("fetch", "fetch-multiple", the_repository);
2464 }
2465
2466 /*
@@ -2472,6 +2482,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2482 max_children = config.parallel;
2483
2484 add_options_to_argv(&options, &config);
2485 + trace2_region_enter_printf("fetch", "recurse-submodule", the_repository, "%s", submodule_prefix);
2486 result = fetch_submodules(the_repository,
2487 &options,
2488 submodule_prefix,
@@ -2479,6 +2490,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2490 recurse_submodules_default,
2491 verbosity < 0,
2492 max_children);
2493 + trace2_region_leave_printf("fetch", "recurse-submodule", the_repository, "%s", submodule_prefix);
2494 strvec_clear(&options);
2495 }
2496
@@ -2502,9 +2514,11 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2514 if (progress)
2515 commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
2516
2517 + trace2_region_enter("fetch", "write-commit-graph", the_repository);
2518 write_commit_graph_reachable(the_repository->objects->odb,
2519 commit_graph_flags,
2520 NULL);
2521 + trace2_region_leave("fetch", "write-commit-graph", the_repository);
2522 }
2523
2524 if (enable_auto_gc) {
bundle-uri.c
+4
@@ -13,6 +13,7 @@
13 #include "config.h"
14 #include "fetch-pack.h"
15 #include "remote.h"
16 +#include "trace2.h"
17
18 static struct {
19 enum bundle_list_heuristic heuristic;
@@ -799,6 +800,8 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
800 .id = xstrdup(""),
801 };
802
803 + trace2_region_enter("fetch", "fetch-bundle-uri", the_repository);
804 +
805 init_bundle_list(&list);
806
807 /*
@@ -824,6 +827,7 @@ cleanup:
827 for_all_bundles_in_list(&list, unlink_bundle, NULL);
828 clear_bundle_list(&list);
829 clear_remote_bundle_info(&bundle, NULL);
830 + trace2_region_leave("fetch", "fetch-bundle-uri", the_repository);
831 return result;
832 }
833