Commit
a6c983765fa2005436475eff3aa5b9b5fe5181da
pack-objects: trace pack bytes written
We want to measure how compression settings affect push performance on the client. Different settings can produce different-sized packs from the same objects. Trace2 records the object count, but we also need the pack size to compare those settings. Add a write_pack_file/wrote_bytes Trace2 datum alongside write_pack_file/wrote. Count packs written to stdout or disk, including each pack's header and trailing checksum. When pack.packSizeLimit splits the output, report the sum of the pack sizes. Signed-off-by: Friel <friel@openai.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Friel <friel@openai.com> · 2026-08-19 23:28 UTC · committed by Junio C Hamano
2 files changed,
+29
−0
modified builtin/pack-objects.c
| @@ -1337,6 +1337,7 @@ static void write_pack_file(void) | |||
| 1337 | 1337 | uint32_t nr_remaining = nr_result; | |
| 1338 | 1338 | time_t last_mtime = 0; | |
| 1339 | 1339 | struct object_entry **write_order; | |
| 1340 | + | off_t bytes_written = 0; | |
| 1340 | 1341 | ||
| 1341 | 1342 | if (progress > pack_to_stdout) | |
| 1342 | 1343 | progress_state = start_progress(the_repository, | |
| @@ -1389,6 +1390,8 @@ static void write_pack_file(void) | |||
| 1389 | 1390 | display_progress(progress_state, written); | |
| 1390 | 1391 | } | |
| 1391 | 1392 | ||
| 1393 | + | bytes_written += hashfile_total(f) + | |
| 1394 | + | the_repository->hash_algo->rawsz; | |
| 1392 | 1395 | if (pack_to_stdout) { | |
| 1393 | 1396 | /* | |
| 1394 | 1397 | * We never fsync when writing to stdout since we may | |
| @@ -1510,6 +1513,8 @@ static void write_pack_file(void) | |||
| 1510 | 1513 | written, nr_result); | |
| 1511 | 1514 | trace2_data_intmax("pack-objects", the_repository, | |
| 1512 | 1515 | "write_pack_file/wrote", nr_result); | |
| 1516 | + | trace2_data_intmax("pack-objects", the_repository, | |
| 1517 | + | "write_pack_file/wrote_bytes", bytes_written); | |
| 1513 | 1518 | } | |
| 1514 | 1519 | ||
| 1515 | 1520 | static int no_try_delta(const char *path) | |
modified t/t5300-pack-object.sh
| @@ -33,6 +33,30 @@ test_expect_success 'setup' ' | |||
| 33 | 33 | } >expect | |
| 34 | 34 | ' | |
| 35 | 35 | ||
| 36 | + | test_expect_success 'pack-object traces bytes written to stdout' ' | |
| 37 | + | test_when_finished "rm -f pack.trace pack.pack" && | |
| 38 | + | GIT_TRACE2_EVENT="$PWD/pack.trace" \ | |
| 39 | + | git pack-objects --quiet --revs --stdout >pack.pack <<-EOF && | |
| 40 | + | $commit | |
| 41 | + | EOF | |
| 42 | + | bytes=$(test_file_size pack.pack) && | |
| 43 | + | test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace | |
| 44 | + | ' | |
| 45 | + | ||
| 46 | + | test_expect_success 'pack-object traces bytes written to split pack files' ' | |
| 47 | + | test_when_finished "rm -f split.trace traced-pack-*" && | |
| 48 | + | GIT_TRACE2_EVENT="$PWD/split.trace" \ | |
| 49 | + | git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack <obj-list && | |
| 50 | + | test 2 = $(ls traced-pack-*.pack | wc -l) && | |
| 51 | + | bytes=0 && | |
| 52 | + | for pack in traced-pack-*.pack | |
| 53 | + | do | |
| 54 | + | pack_size=$(test_file_size "$pack") && | |
| 55 | + | bytes=$((bytes + pack_size)) || return 1 | |
| 56 | + | done && | |
| 57 | + | test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" split.trace | |
| 58 | + | ' | |
| 59 | + | ||
| 36 | 60 | test_expect_success 'setup pack-object <stdin' ' | |
| 37 | 61 | git init pack-object-stdin && | |
| 38 | 62 | test_commit -C pack-object-stdin one && | |