Skip to content

Commit 342e9ef

Browse files
trastgitster
authored andcommitted
Introduce a performance testing framework
This introduces a performance testing framework under t/perf/. It tries to be as close to the test-lib.sh infrastructure as possible, and thus should be easy to get used to for git developers. The following points were considered for the implementation: 1. You usually want to compare arbitrary revisions/build trees against each other. They may not have the performance test under consideration, or even the perf-lib.sh infrastructure. To cope with this, the 'run' script lets you specify arbitrary build dirs and revisions. It even automatically builds the revisions if it doesn't have them at hand yet. 2. Usually you would not want to run all tests. It would take too long anyway. The 'run' script lets you specify which tests to run; or you can also do it manually. There is a Makefile for discoverability and 'make clean', but it is not meant for real-world use. 3. Creating test repos from scratch in every test is extremely time-consuming, and shipping or downloading such large/weird repos is out of the question. We leave this decision to the user. Two different sizes of test repos can be configured, and the scripts just copy one or more of those (using hardlinks for the object store). By default it tries to use the build tree's git.git repository. This is fairly fast and versatile. Using a copy instead of a clone preserves many properties that the user may want to test for, such as lots of loose objects, unpacked refs, etc. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12a29b1 commit 342e9ef

File tree

12 files changed

+774
-5
lines changed

12 files changed

+774
-5
lines changed

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,10 @@ GIT-BUILD-OPTIONS: FORCE
23612361
@echo USE_LIBPCRE=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@
23622362
@echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
23632363
@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
2364+
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
2365+
ifdef GIT_TEST_OPTS
2366+
@echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@
2367+
endif
23642368
ifdef GIT_TEST_CMP
23652369
@echo GIT_TEST_CMP=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_CMP)))'\' >>$@
23662370
endif
@@ -2369,7 +2373,18 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
23692373
endif
23702374
@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@
23712375
@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
2372-
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
2376+
ifdef GIT_PERF_REPEAT_COUNT
2377+
@echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@
2378+
endif
2379+
ifdef GIT_PERF_REPO
2380+
@echo GIT_PERF_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPO)))'\' >>$@
2381+
endif
2382+
ifdef GIT_PERF_LARGE_REPO
2383+
@echo GIT_PERF_LARGE_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_LARGE_REPO)))'\' >>$@
2384+
endif
2385+
ifdef GIT_PERF_MAKE_OPTS
2386+
@echo GIT_PERF_MAKE_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_MAKE_OPTS)))'\' >>$@
2387+
endif
23732388

23742389
### Detect Tck/Tk interpreter path changes
23752390
ifndef NO_TCLTK
@@ -2405,6 +2420,11 @@ export NO_SVN_TESTS
24052420
test: all
24062421
$(MAKE) -C t/ all
24072422

2423+
perf: all
2424+
$(MAKE) -C t/perf/ all
2425+
2426+
.PHONY: test perf
2427+
24082428
test-ctype$X: ctype.o
24092429

24102430
test-date$X: date.o ctype.o

t/Makefile

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,45 @@ gitweb-test:
7373
valgrind:
7474
$(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
7575

76-
.PHONY: pre-clean $(T) aggregate-results clean valgrind
76+
perf:
77+
$(MAKE) -C perf/ all
78+
79+
# Smoke testing targets
80+
-include ../GIT-VERSION-FILE
81+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo unknown')
82+
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo unknown')
83+
84+
test-results:
85+
mkdir -p test-results
86+
87+
test-results/git-smoke.tar.gz: test-results
88+
$(PERL_PATH) ./harness \
89+
--archive="test-results/git-smoke.tar.gz" \
90+
$(T)
91+
92+
smoke: test-results/git-smoke.tar.gz
93+
94+
SMOKE_UPLOAD_FLAGS =
95+
ifdef SMOKE_USERNAME
96+
SMOKE_UPLOAD_FLAGS += -F username="$(SMOKE_USERNAME)" -F password="$(SMOKE_PASSWORD)"
97+
endif
98+
ifdef SMOKE_COMMENT
99+
SMOKE_UPLOAD_FLAGS += -F comments="$(SMOKE_COMMENT)"
100+
endif
101+
ifdef SMOKE_TAGS
102+
SMOKE_UPLOAD_FLAGS += -F tags="$(SMOKE_TAGS)"
103+
endif
104+
105+
smoke_report: smoke
106+
curl \
107+
-H "Expect: " \
108+
-F project=Git \
109+
-F architecture="$(uname_M)" \
110+
-F platform="$(uname_S)" \
111+
-F revision="$(GIT_VERSION)" \
112+
-F report_file=@test-results/git-smoke.tar.gz \
113+
$(SMOKE_UPLOAD_FLAGS) \
114+
http://smoke.git.nix.is/app/projects/process_add_report/1 \
115+
| grep -v ^Redirecting
116+
117+
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf

t/perf/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
test-results/

t/perf/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-include ../../config.mak
2+
export GIT_TEST_OPTIONS
3+
4+
all: perf
5+
6+
perf: pre-clean
7+
./run
8+
9+
pre-clean:
10+
rm -rf test-results
11+
12+
clean:
13+
rm -rf build "trash directory".* test-results
14+
15+
.PHONY: all perf pre-clean clean

t/perf/README

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Git performance tests
2+
=====================
3+
4+
This directory holds performance testing scripts for git tools. The
5+
first part of this document describes the various ways in which you
6+
can run them.
7+
8+
When fixing the tools or adding enhancements, you are strongly
9+
encouraged to add tests in this directory to cover what you are
10+
trying to fix or enhance. The later part of this short document
11+
describes how your test scripts should be organized.
12+
13+
14+
Running Tests
15+
-------------
16+
17+
The easiest way to run tests is to say "make". This runs all
18+
the tests on the current git repository.
19+
20+
=== Running 2 tests in this tree ===
21+
[...]
22+
Test this tree
23+
---------------------------------------------------------
24+
0001.1: rev-list --all 0.54(0.51+0.02)
25+
0001.2: rev-list --all --objects 6.14(5.99+0.11)
26+
7810.1: grep worktree, cheap regex 0.16(0.16+0.35)
27+
7810.2: grep worktree, expensive regex 7.90(29.75+0.37)
28+
7810.3: grep --cached, cheap regex 3.07(3.02+0.25)
29+
7810.4: grep --cached, expensive regex 9.39(30.57+0.24)
30+
31+
You can compare multiple repositories and even git revisions with the
32+
'run' script:
33+
34+
$ ./run . origin/next /path/to/git-tree p0001-rev-list.sh
35+
36+
where . stands for the current git tree. The full invocation is
37+
38+
./run [<revision|directory>...] [--] [<test-script>...]
39+
40+
A '.' argument is implied if you do not pass any other
41+
revisions/directories.
42+
43+
You can also manually test this or another git build tree, and then
44+
call the aggregation script to summarize the results:
45+
46+
$ ./p0001-rev-list.sh
47+
[...]
48+
$ GIT_BUILD_DIR=/path/to/other/git ./p0001-rev-list.sh
49+
[...]
50+
$ ./aggregate.perl . /path/to/other/git ./p0001-rev-list.sh
51+
52+
aggregate.perl has the same invocation as 'run', it just does not run
53+
anything beforehand.
54+
55+
You can set the following variables (also in your config.mak):
56+
57+
GIT_PERF_REPEAT_COUNT
58+
Number of times a test should be repeated for best-of-N
59+
measurements. Defaults to 5.
60+
61+
GIT_PERF_MAKE_OPTS
62+
Options to use when automatically building a git tree for
63+
performance testing. E.g., -j6 would be useful.
64+
65+
GIT_PERF_REPO
66+
GIT_PERF_LARGE_REPO
67+
Repositories to copy for the performance tests. The normal
68+
repo should be at least git.git size. The large repo should
69+
probably be about linux-2.6.git size for optimal results.
70+
Both default to the git.git you are running from.
71+
72+
You can also pass the options taken by ordinary git tests; the most
73+
useful one is:
74+
75+
--root=<directory>::
76+
Create "trash" directories used to store all temporary data during
77+
testing under <directory>, instead of the t/ directory.
78+
Using this option with a RAM-based filesystem (such as tmpfs)
79+
can massively speed up the test suite.
80+
81+
82+
Naming Tests
83+
------------
84+
85+
The performance test files are named as:
86+
87+
pNNNN-commandname-details.sh
88+
89+
where N is a decimal digit. The same conventions for choosing NNNN as
90+
for normal tests apply.
91+
92+
93+
Writing Tests
94+
-------------
95+
96+
The perf script starts much like a normal test script, except it
97+
sources perf-lib.sh:
98+
99+
#!/bin/sh
100+
#
101+
# Copyright (c) 2005 Junio C Hamano
102+
#
103+
104+
test_description='xxx performance test'
105+
. ./perf-lib.sh
106+
107+
After that you will want to use some of the following:
108+
109+
test_perf_default_repo # sets up a "normal" repository
110+
test_perf_large_repo # sets up a "large" repository
111+
112+
test_perf_default_repo sub # ditto, in a subdir "sub"
113+
114+
test_checkout_worktree # if you need the worktree too
115+
116+
At least one of the first two is required!
117+
118+
You can use test_expect_success as usual. For actual performance
119+
tests, use
120+
121+
test_perf 'descriptive string' '
122+
command1 &&
123+
command2
124+
'
125+
126+
test_perf spawns a subshell, for lack of better options. This means
127+
that
128+
129+
* you _must_ export all variables that you need in the subshell
130+
131+
* you _must_ flag all variables that you want to persist from the
132+
subshell with 'test_export':
133+
134+
test_perf 'descriptive string' '
135+
foo=$(git rev-parse HEAD) &&
136+
test_export foo
137+
'
138+
139+
The so-exported variables are automatically marked for export in the
140+
shell executing the perf test. For your convenience, test_export is
141+
the same as export in the main shell.
142+
143+
This feature relies on a bit of magic using 'set' and 'source'.
144+
While we have tried to make sure that it can cope with embedded
145+
whitespace and other special characters, it will not work with
146+
multi-line data.

0 commit comments

Comments
 (0)