使用profile-fast-install编译Git失败,提示缺失测试文件
编译Git Profile优化版遇到的问题与解决
问题现象
- 使用
profile-fast-install编译Git 2.49.0、2.48.1、2.48.0版本(无论是GitHub源码仓库还是Kernel.org压缩包)时,均触发错误:
cannot open test-results/p5332-multi-pack-reuse.subtests: No such file or directory at ./aggregate.perl line 159.
- 直接运行性能测试脚本
./p5332-multi-pack-reuse.sh时,出现如下错误:
warning: unknown preferred pack: 'pack-e837cfde5d0c6e0eebcb9aefb374b63a3726eb0f.idx' error: no pack files to index. error: last command exited with $?=1
核心疑问:按照官方文档编译“Profile优化版”Git是否可行?
问题复现Dockerfile
# syntax=docker/dockerfile:1 # compile Git # docker build -f <this file> /tmp/ # see https://github.com/git/git# # see https://github.com/git/git/blob/master/INSTALL # see https://www.kernel.org/pub/software/scm/git/ # see https://git-scm.com/book/en/v2/Getting-Started-Installing-Git # see https://www.kernel.org/signature.html # see https://marc.info/?l=git&m=156686939702976&w=2 FROM ubuntu:22.04 as base RUN apt update -y \ && apt install -y \ make dh-autoreconf libcurl4-gnutls-dev libexpat1-dev zlib1g-dev libssl-dev gettext xz-utils gpg git WORKDIR /home # NOTE 2.49.0 was 683c54c at the time of writing RUN git clone https://github.com/git/git.git ./git \ && git -C ./git checkout v2.49.0 RUN cd git \ && make configure \ && ./configure --prefix=/home/.local \ && make -j all \ && make PREFIX=/home/.local profile-fast-install # NOTE you can trigger it by RUN cd git/t/perf \ && rm -rf test-results \ && ./run p5332-multi-pack-reuse.sh
测试执行日志
root@0a1a0100a22b:/git/t/perf# rm -rf test-results/ root@0a1a0100a22b:/git/t/perf# ./p5332-multi-pack-reuse.sh -xv checking prerequisite: SYMLINKS mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-SYMLINKS" && ( cd "$TRASH_DIRECTORY/prereq-test-dir-SYMLINKS" && # test whether the filesystem supports symbolic links ln -s x y && test -h y ) + mkdir -p /git/t/perf/trash directory.p5332-multi-pack-reuse/prereq-test-dir-SYMLINKS + cd /git/t/perf/trash directory.p5332-multi-pack-reuse/prereq-test-dir-SYMLINKS + ln -s x y + test -h y prerequisite SYMLINKS ok expecting success of p5332.1 'create 1-pack scenario': repack_into_n_chunks $nr_packs + repack_into_n_chunks 1 + git repack -adk Enumerating objects: 774560, done. Counting objects: 100% (387280/387280), done. Delta compression using up to 8 threads Compressing objects: 100% (92515/92515), done. Writing objects: 100% (387280/387280), done. Total 387280 (delta 292211), reused 387280 (delta 292211), pack-reused 0 (from 0) + test 1 -eq 1 + return ok 1 - create 1-pack scenario expecting success of p5332.2 'setup bitmaps for 1-pack scenario': find $packdir -type f -name "*.idx" | sed -e "s/.*\/\(.*\)$/\+\1/g" | git multi-pack-index write --stdin-packs --bitmap \ --preferred-pack="$(find_pack $(git rev-parse HEAD))" + find .git/objects/pack -type f -name *.idx + sed -e s/.*\/\(.*\)$/\+\1/g + git rev-parse HEAD + find_pack 683c54c999c301c2cd6f715c411407c413b1d84e + git show-index + grep -q 683c54c999c301c2cd6f715c411407c413b1d84e + basename .git/objects/pack/pack-e837cfde5d0c6e0eebcb9aefb374b63a3726eb0f.idx + git multi-pack-index write --stdin-packs --bitmap --preferred-pack=pack-e837cfde5d0c6e0eebcb9aefb374b63a3726eb0f.idx warning: unknown preferred pack: 'pack-e837cfde5d0c6e0eebcb9aefb374b63a3726eb0f.idx' error: no pack files to index. error: last command exited with $?=1 not ok 2 - setup bitmaps for 1-pack scenario # # find $packdir -type f -name "*.idx" | sed -e "s/.*\/\(.*\)$/\+\1/g" | # git multi-pack-index write --stdin-packs --bitmap \ # --preferred-pack="$(find_pack $(git rev-parse HEAD))" # 1..2
解决方案与可行性说明
编译Profile优化版Git是完全可行的,当前错误是性能测试脚本p5332-multi-pack-reuse.sh的逻辑问题,与profile-fast-install本身无关。
问题根源
测试脚本中,sed -e "s/.*\/\(.*\)$/\+\1/g"会给每个pack文件名前添加+号,但--preferred-pack参数传入的是不带+号的pack文件名,导致Git无法识别该pack,进而触发错误。
修复步骤
- 修改测试脚本
p5332-multi-pack-reuse.sh,在生成--preferred-pack参数时,给pack文件名前添加+号:
将原代码:
修改为:git multi-pack-index write --stdin-packs --bitmap \ --preferred-pack="$(find_pack $(git rev-parse HEAD))"git multi-pack-index write --stdin-packs --bitmap \ --preferred-pack="+$(find_pack $(git rev-parse HEAD))" - 重新运行测试脚本,或直接跳过该测试继续完成编译(若仅需编译优化版Git,无需通过全部性能测试)。
替代编译方式
若不想修改测试脚本,可跳过性能测试环节,直接手动执行Profile优化流程:
- 先完成普通编译:
make -j all - 生成Profile数据:
make profile(运行性能测试生成Profile文件) - 编译优化版:
make profile-fast - 安装:
make PREFIX=/home/.local install
内容的提问来源于stack exchange,提问作者Michael Teresi
相关产品推荐
相关产品推荐

