Skip to content

Commit

Permalink
Introduce a performance testing framework
Browse files Browse the repository at this point in the history
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 <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
trast authored and gitster committed Feb 17, 2012
1 parent 12a29b1 commit 342e9ef
Show file tree
Hide file tree
Showing 12 changed files with 774 additions and 5 deletions.
22 changes: 21 additions & 1 deletion Makefile
Expand Up @@ -2361,6 +2361,10 @@ GIT-BUILD-OPTIONS: FORCE
@echo USE_LIBPCRE=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@
@echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
ifdef GIT_TEST_OPTS
@echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@
endif
ifdef GIT_TEST_CMP
@echo GIT_TEST_CMP=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_CMP)))'\' >>$@
endif
Expand All @@ -2369,7 +2373,18 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
endif
@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@
@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
ifdef GIT_PERF_REPEAT_COUNT
@echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@
endif
ifdef GIT_PERF_REPO
@echo GIT_PERF_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPO)))'\' >>$@
endif
ifdef GIT_PERF_LARGE_REPO
@echo GIT_PERF_LARGE_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_LARGE_REPO)))'\' >>$@
endif
ifdef GIT_PERF_MAKE_OPTS
@echo GIT_PERF_MAKE_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_MAKE_OPTS)))'\' >>$@
endif

### Detect Tck/Tk interpreter path changes
ifndef NO_TCLTK
Expand Down Expand Up @@ -2405,6 +2420,11 @@ export NO_SVN_TESTS
test: all
$(MAKE) -C t/ all

perf: all
$(MAKE) -C t/perf/ all

.PHONY: test perf

test-ctype$X: ctype.o

test-date$X: date.o ctype.o
Expand Down
43 changes: 42 additions & 1 deletion t/Makefile
Expand Up @@ -73,4 +73,45 @@ gitweb-test:
valgrind:
$(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"

.PHONY: pre-clean $(T) aggregate-results clean valgrind
perf:
$(MAKE) -C perf/ all

# Smoke testing targets
-include ../GIT-VERSION-FILE
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo unknown')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo unknown')

test-results:
mkdir -p test-results

test-results/git-smoke.tar.gz: test-results
$(PERL_PATH) ./harness \
--archive="test-results/git-smoke.tar.gz" \
$(T)

smoke: test-results/git-smoke.tar.gz

SMOKE_UPLOAD_FLAGS =
ifdef SMOKE_USERNAME
SMOKE_UPLOAD_FLAGS += -F username="$(SMOKE_USERNAME)" -F password="$(SMOKE_PASSWORD)"
endif
ifdef SMOKE_COMMENT
SMOKE_UPLOAD_FLAGS += -F comments="$(SMOKE_COMMENT)"
endif
ifdef SMOKE_TAGS
SMOKE_UPLOAD_FLAGS += -F tags="$(SMOKE_TAGS)"
endif

smoke_report: smoke
curl \
-H "Expect: " \
-F project=Git \
-F architecture="$(uname_M)" \
-F platform="$(uname_S)" \
-F revision="$(GIT_VERSION)" \
-F report_file=@test-results/git-smoke.tar.gz \
$(SMOKE_UPLOAD_FLAGS) \
http://smoke.git.nix.is/app/projects/process_add_report/1 \
| grep -v ^Redirecting

.PHONY: pre-clean $(T) aggregate-results clean valgrind perf
2 changes: 2 additions & 0 deletions t/perf/.gitignore
@@ -0,0 +1,2 @@
build/
test-results/
15 changes: 15 additions & 0 deletions t/perf/Makefile
@@ -0,0 +1,15 @@
-include ../../config.mak
export GIT_TEST_OPTIONS

all: perf

perf: pre-clean
./run

pre-clean:
rm -rf test-results

clean:
rm -rf build "trash directory".* test-results

.PHONY: all perf pre-clean clean
146 changes: 146 additions & 0 deletions t/perf/README
@@ -0,0 +1,146 @@
Git performance tests
=====================

This directory holds performance testing scripts for git tools. The
first part of this document describes the various ways in which you
can run them.

When fixing the tools or adding enhancements, you are strongly
encouraged to add tests in this directory to cover what you are
trying to fix or enhance. The later part of this short document
describes how your test scripts should be organized.


Running Tests
-------------

The easiest way to run tests is to say "make". This runs all
the tests on the current git repository.

=== Running 2 tests in this tree ===
[...]
Test this tree
---------------------------------------------------------
0001.1: rev-list --all 0.54(0.51+0.02)
0001.2: rev-list --all --objects 6.14(5.99+0.11)
7810.1: grep worktree, cheap regex 0.16(0.16+0.35)
7810.2: grep worktree, expensive regex 7.90(29.75+0.37)
7810.3: grep --cached, cheap regex 3.07(3.02+0.25)
7810.4: grep --cached, expensive regex 9.39(30.57+0.24)

You can compare multiple repositories and even git revisions with the
'run' script:

$ ./run . origin/next /path/to/git-tree p0001-rev-list.sh

where . stands for the current git tree. The full invocation is

./run [<revision|directory>...] [--] [<test-script>...]

A '.' argument is implied if you do not pass any other
revisions/directories.

You can also manually test this or another git build tree, and then
call the aggregation script to summarize the results:

$ ./p0001-rev-list.sh
[...]
$ GIT_BUILD_DIR=/path/to/other/git ./p0001-rev-list.sh
[...]
$ ./aggregate.perl . /path/to/other/git ./p0001-rev-list.sh

aggregate.perl has the same invocation as 'run', it just does not run
anything beforehand.

You can set the following variables (also in your config.mak):

GIT_PERF_REPEAT_COUNT
Number of times a test should be repeated for best-of-N
measurements. Defaults to 5.

GIT_PERF_MAKE_OPTS
Options to use when automatically building a git tree for
performance testing. E.g., -j6 would be useful.

GIT_PERF_REPO
GIT_PERF_LARGE_REPO
Repositories to copy for the performance tests. The normal
repo should be at least git.git size. The large repo should
probably be about linux-2.6.git size for optimal results.
Both default to the git.git you are running from.

You can also pass the options taken by ordinary git tests; the most
useful one is:

--root=<directory>::
Create "trash" directories used to store all temporary data during
testing under <directory>, instead of the t/ directory.
Using this option with a RAM-based filesystem (such as tmpfs)
can massively speed up the test suite.


Naming Tests
------------

The performance test files are named as:

pNNNN-commandname-details.sh

where N is a decimal digit. The same conventions for choosing NNNN as
for normal tests apply.


Writing Tests
-------------

The perf script starts much like a normal test script, except it
sources perf-lib.sh:

#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
#

test_description='xxx performance test'
. ./perf-lib.sh

After that you will want to use some of the following:

test_perf_default_repo # sets up a "normal" repository
test_perf_large_repo # sets up a "large" repository

test_perf_default_repo sub # ditto, in a subdir "sub"

test_checkout_worktree # if you need the worktree too

At least one of the first two is required!

You can use test_expect_success as usual. For actual performance
tests, use

test_perf 'descriptive string' '
command1 &&
command2
'

test_perf spawns a subshell, for lack of better options. This means
that

* you _must_ export all variables that you need in the subshell

* you _must_ flag all variables that you want to persist from the
subshell with 'test_export':

test_perf 'descriptive string' '
foo=$(git rev-parse HEAD) &&
test_export foo
'

The so-exported variables are automatically marked for export in the
shell executing the perf test. For your convenience, test_export is
the same as export in the main shell.

This feature relies on a bit of magic using 'set' and 'source'.
While we have tried to make sure that it can cope with embedded
whitespace and other special characters, it will not work with
multi-line data.

0 comments on commit 342e9ef

Please sign in to comment.