Skip to content

Commit dd90365

Browse files
committed
Merge branch 'js/fetch-push-trace2-annotation'
More trace2 events at key points on push and fetch code paths have been added. * js/fetch-push-trace2-annotation: send-pack: add new tracing regions for push fetch: add top-level trace2 regions trace2: implement trace2_printf() for event target
2 parents 533e308 + db52812 commit dd90365

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

Documentation/technical/api-trace2.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ yields
128128

129129
------------
130130
$ cat ~/log.event
131-
{"event":"version","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.620713Z","file":"common-main.c","line":38,"evt":"3","exe":"2.20.1.155.g426c96fcdb"}
131+
{"event":"version","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.620713Z","file":"common-main.c","line":38,"evt":"4","exe":"2.20.1.155.g426c96fcdb"}
132132
{"event":"start","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.621027Z","file":"common-main.c","line":39,"t_abs":0.001173,"argv":["git","version"]}
133133
{"event":"cmd_name","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"}
134134
{"event":"exit","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.621236Z","file":"git.c","line":662,"t_abs":0.001227,"code":0}
@@ -344,7 +344,7 @@ only present on the "start" and "atexit" events.
344344
{
345345
"event":"version",
346346
...
347-
"evt":"3", # EVENT format version
347+
"evt":"4", # EVENT format version
348348
"exe":"2.20.1.155.g426c96fcdb" # git version
349349
}
350350
------------
@@ -835,6 +835,19 @@ The "value" field may be an integer or a string.
835835
}
836836
------------
837837

838+
`"printf"`::
839+
This event logs a human-readable message with no particular formatting
840+
guidelines.
841+
+
842+
------------
843+
{
844+
"event":"printf",
845+
...
846+
"t_abs":0.015905, # elapsed time in seconds
847+
"msg":"Hello world" # optional
848+
}
849+
------------
850+
838851

839852
== Example Trace2 API Usage
840853

builtin/fetch.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
24082408
struct oidset_iter iter;
24092409
const struct object_id *oid;
24102410

2411+
trace2_region_enter("fetch", "negotiate-only", the_repository);
24112412
if (!remote)
24122413
die(_("must supply remote when using --negotiate-only"));
24132414
gtransport = prepare_transport(remote, 1);
@@ -2416,6 +2417,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
24162417
} else {
24172418
warning(_("protocol does not support --negotiate-only, exiting"));
24182419
result = 1;
2420+
trace2_region_leave("fetch", "negotiate-only", the_repository);
24192421
goto cleanup;
24202422
}
24212423
if (server_options.nr)
@@ -2426,11 +2428,17 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
24262428
while ((oid = oidset_iter_next(&iter)))
24272429
printf("%s\n", oid_to_hex(oid));
24282430
oidset_clear(&acked_commits);
2431+
trace2_region_leave("fetch", "negotiate-only", the_repository);
24292432
} 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);
24312435
fetch_one_setup_partial(remote);
2436+
trace2_region_leave("fetch", "setup-partial", the_repository);
2437+
}
2438+
trace2_region_enter("fetch", "fetch-one", the_repository);
24322439
result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs,
24332440
&config);
2441+
trace2_region_leave("fetch", "fetch-one", the_repository);
24342442
} else {
24352443
int max_children = max_jobs;
24362444

@@ -2450,7 +2458,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
24502458
max_children = config.parallel;
24512459

24522460
/* TODO should this also die if we have a previous partial-clone? */
2461+
trace2_region_enter("fetch", "fetch-multiple", the_repository);
24532462
result = fetch_multiple(&list, max_children, &config);
2463+
trace2_region_leave("fetch", "fetch-multiple", the_repository);
24542464
}
24552465

24562466
/*
@@ -2472,13 +2482,15 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
24722482
max_children = config.parallel;
24732483

24742484
add_options_to_argv(&options, &config);
2485+
trace2_region_enter_printf("fetch", "recurse-submodule", the_repository, "%s", submodule_prefix);
24752486
result = fetch_submodules(the_repository,
24762487
&options,
24772488
submodule_prefix,
24782489
config.recurse_submodules,
24792490
recurse_submodules_default,
24802491
verbosity < 0,
24812492
max_children);
2493+
trace2_region_leave_printf("fetch", "recurse-submodule", the_repository, "%s", submodule_prefix);
24822494
strvec_clear(&options);
24832495
}
24842496

@@ -2502,9 +2514,11 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
25022514
if (progress)
25032515
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
25042516

2517+
trace2_region_enter("fetch", "write-commit-graph", the_repository);
25052518
write_commit_graph_reachable(the_repository->objects->odb,
25062519
commit_graph_flags,
25072520
NULL);
2521+
trace2_region_leave("fetch", "write-commit-graph", the_repository);
25082522
}
25092523

25102524
if (enable_auto_gc) {

bundle-uri.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "config.h"
1414
#include "fetch-pack.h"
1515
#include "remote.h"
16+
#include "trace2.h"
1617

1718
static struct {
1819
enum bundle_list_heuristic heuristic;
@@ -799,6 +800,8 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
799800
.id = xstrdup(""),
800801
};
801802

803+
trace2_region_enter("fetch", "fetch-bundle-uri", the_repository);
804+
802805
init_bundle_list(&list);
803806

804807
/*
@@ -824,6 +827,7 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
824827
for_all_bundles_in_list(&list, unlink_bundle, NULL);
825828
clear_bundle_list(&list);
826829
clear_remote_bundle_info(&bundle, NULL);
830+
trace2_region_leave("fetch", "fetch-bundle-uri", the_repository);
827831
return result;
828832
}
829833

send-pack.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
7575
int i;
7676
int rc;
7777

78+
trace2_region_enter("send_pack", "pack_objects", the_repository);
7879
strvec_push(&po.args, "pack-objects");
7980
strvec_push(&po.args, "--all-progress-implied");
8081
strvec_push(&po.args, "--revs");
@@ -146,8 +147,10 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
146147
*/
147148
if (rc > 128 && rc != 141)
148149
error("pack-objects died of signal %d", rc - 128);
150+
trace2_region_leave("send_pack", "pack_objects", the_repository);
149151
return -1;
150152
}
153+
trace2_region_leave("send_pack", "pack_objects", the_repository);
151154
return 0;
152155
}
153156

@@ -170,6 +173,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
170173
int new_report = 0;
171174
int once = 0;
172175

176+
trace2_region_enter("send_pack", "receive_status", the_repository);
173177
hint = NULL;
174178
ret = receive_unpack_status(reader);
175179
while (1) {
@@ -268,6 +272,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
268272
new_report = 1;
269273
}
270274
}
275+
trace2_region_leave("send_pack", "receive_status", the_repository);
271276
return ret;
272277
}
273278

@@ -512,8 +517,11 @@ int send_pack(struct send_pack_args *args,
512517
}
513518

514519
git_config_get_bool("push.negotiate", &push_negotiate);
515-
if (push_negotiate)
520+
if (push_negotiate) {
521+
trace2_region_enter("send_pack", "push_negotiate", the_repository);
516522
get_commons_through_negotiation(args->url, remote_refs, &commons);
523+
trace2_region_leave("send_pack", "push_negotiate", the_repository);
524+
}
517525

518526
if (!git_config_get_bool("push.usebitmaps", &use_bitmaps))
519527
args->disable_bitmaps = !use_bitmaps;
@@ -641,10 +649,11 @@ int send_pack(struct send_pack_args *args,
641649
/*
642650
* Finally, tell the other end!
643651
*/
644-
if (!args->dry_run && push_cert_nonce)
652+
if (!args->dry_run && push_cert_nonce) {
645653
cmds_sent = generate_push_cert(&req_buf, remote_refs, args,
646654
cap_buf.buf, push_cert_nonce);
647-
else if (!args->dry_run)
655+
trace2_printf("Generated push certificate");
656+
} else if (!args->dry_run) {
648657
for (ref = remote_refs; ref; ref = ref->next) {
649658
char *old_hex, *new_hex;
650659

@@ -664,6 +673,7 @@ int send_pack(struct send_pack_args *args,
664673
old_hex, new_hex, ref->name);
665674
}
666675
}
676+
}
667677

668678
if (use_push_options) {
669679
struct string_list_item *item;

trace2/tr2_tgt_event.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static struct tr2_dst tr2dst_event = {
2424
* a new field to an existing event, do not require an increment to the EVENT
2525
* format version.
2626
*/
27-
#define TR2_EVENT_VERSION "3"
27+
#define TR2_EVENT_VERSION "4"
2828

2929
/*
3030
* Region nesting limit for messages written to the event target.
@@ -622,6 +622,24 @@ static void fn_data_json_fl(const char *file, int line,
622622
}
623623
}
624624

625+
static void fn_printf_va_fl(const char *file, int line,
626+
uint64_t us_elapsed_absolute,
627+
const char *fmt, va_list ap)
628+
{
629+
const char *event_name = "printf";
630+
struct json_writer jw = JSON_WRITER_INIT;
631+
double t_abs = (double)us_elapsed_absolute / 1000000.0;
632+
633+
jw_object_begin(&jw, 0);
634+
event_fmt_prepare(event_name, file, line, NULL, &jw);
635+
jw_object_double(&jw, "t_abs", 6, t_abs);
636+
maybe_add_string_va(&jw, "msg", fmt, ap);
637+
jw_end(&jw);
638+
639+
tr2_dst_write_line(&tr2dst_event, &jw.json);
640+
jw_release(&jw);
641+
}
642+
625643
static void fn_timer(const struct tr2_timer_metadata *meta,
626644
const struct tr2_timer *timer,
627645
int is_final_data)
@@ -694,7 +712,7 @@ struct tr2_tgt tr2_tgt_event = {
694712
.pfn_region_leave_printf_va_fl = fn_region_leave_printf_va_fl,
695713
.pfn_data_fl = fn_data_fl,
696714
.pfn_data_json_fl = fn_data_json_fl,
697-
.pfn_printf_va_fl = NULL,
715+
.pfn_printf_va_fl = fn_printf_va_fl,
698716
.pfn_timer = fn_timer,
699717
.pfn_counter = fn_counter,
700718
};

0 commit comments

Comments
 (0)