]> git.ipfire.org Git - thirdparty/git.git/blame - t/perf/p7519-fsmonitor.sh
Merge branch 'jc/do-not-just-explain-but-update-your-patch'
[thirdparty/git.git] / t / perf / p7519-fsmonitor.sh
CommitLineData
14527b30
BP
1#!/bin/sh
2
3test_description="Test core.fsmonitor"
4
5. ./perf-lib.sh
6
7#
8# Performance test for the fsmonitor feature which enables git to talk to a
9# file system change monitor and avoid having to scan the working directory
10# for new or modified files.
11#
12# By default, the performance test will utilize the Watchman file system
13# monitor if it is installed. If Watchman is not installed, it will use a
14# dummy integration script that does not report any new or modified files.
15# The dummy script has very little overhead which provides optimistic results.
16#
17# The performance test will also use the untracked cache feature if it is
18# available as fsmonitor uses it to speed up scanning for untracked files.
19#
20# There are 3 environment variables that can be used to alter the default
21# behavior of the performance test:
22#
23# GIT_PERF_7519_UNTRACKED_CACHE: used to configure core.untrackedCache
24# GIT_PERF_7519_SPLIT_INDEX: used to configure core.splitIndex
a948864a
NK
25# GIT_PERF_7519_FSMONITOR: used to configure core.fsMonitor. May be an
26# absolute path to an integration. May be a space delimited list of
27# absolute paths to integrations.
14527b30
BP
28#
29# The big win for using fsmonitor is the elimination of the need to scan the
30# working directory looking for changed and untracked files. If the file
31# information is all cached in RAM, the benefits are reduced.
32#
33# GIT_PERF_7519_DROP_CACHE: if set, the OS caches are dropped between tests
34#
35
36test_perf_large_repo
37test_checkout_worktree
38
39test_lazy_prereq UNTRACKED_CACHE '
40 { git update-index --test-untracked-cache; ret=$?; } &&
41 test $ret -ne 1
42'
43
44test_lazy_prereq WATCHMAN '
b4f61b7f 45 command -v watchman
14527b30
BP
46'
47
48if test_have_prereq WATCHMAN
49then
50 # Convert unix style paths to escaped Windows style paths for Watchman
51 case "$(uname -s)" in
52 MSYS_NT*)
53 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
54 ;;
55 *)
56 GIT_WORK_TREE="$PWD"
57 ;;
58 esac
59fi
60
61if test -n "$GIT_PERF_7519_DROP_CACHE"
62then
63 # When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to
64 # generate valid results. Otherwise the caching that happens for the nth
65 # run will negate the validity of the comparisons.
66 if test "$GIT_PERF_REPEAT_COUNT" -ne 1
67 then
68 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
69 GIT_PERF_REPEAT_COUNT=1
70 fi
71fi
72
bb7cc7e7 73test_expect_success "one time repo setup" '
14527b30
BP
74 # set untrackedCache depending on the environment
75 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
76 then
77 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
78 else
79 if test_have_prereq UNTRACKED_CACHE
80 then
81 git config core.untrackedCache true
82 else
83 git config core.untrackedCache false
84 fi
85 fi &&
86
87 # set core.splitindex depending on the environment
88 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
89 then
90 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
91 fi &&
92
bb7cc7e7
NK
93 mkdir 1_file 10_files 100_files 1000_files 10000_files &&
94 for i in $(test_seq 1 10); do touch 10_files/$i; done &&
95 for i in $(test_seq 1 100); do touch 100_files/$i; done &&
96 for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
97 for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
98 git add 1_file 10_files 100_files 1000_files 10000_files &&
78ff8b32 99 git commit -qm "Add files" &&
0288b932
NK
100
101 # If Watchman exists, watch the work tree and attempt a query.
102 if test_have_prereq WATCHMAN; then
103 watchman watch "$GIT_WORK_TREE" &&
104 watchman watch-list | grep -q -F "$GIT_WORK_TREE"
105 fi
bb7cc7e7
NK
106'
107
a05b71ab 108setup_for_fsmonitor() {
14527b30 109 # set INTEGRATION_SCRIPT depending on the environment
a948864a 110 if test -n "$INTEGRATION_PATH"
14527b30 111 then
a948864a 112 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
14527b30
BP
113 else
114 #
115 # Choose integration script based on existence of Watchman.
0288b932 116 # Fall back to an empty integration script.
14527b30
BP
117 #
118 mkdir .git/hooks &&
119 if test_have_prereq WATCHMAN
120 then
121 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
0288b932 122 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
14527b30
BP
123 else
124 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
125 write_script "$INTEGRATION_SCRIPT"<<-\EOF
126 EOF
127 fi
128 fi &&
129
130 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
33226af4
NK
131 git update-index --fsmonitor 2>error &&
132 cat error &&
6cba4234 133 [ ! -s error ] # ensure no silent error
a05b71ab 134}
14527b30 135
471b1157
NK
136test_perf_w_drop_caches () {
137 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
138 test-tool drop-caches
139 fi
14527b30 140
471b1157
NK
141 test_perf "$@"
142}
14527b30 143
471b1157 144test_fsmonitor_suite() {
dd79c167
NK
145 if test -n "$INTEGRATION_SCRIPT"; then
146 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
147 else
148 DESC="fsmonitor=disabled"
149 fi
3d53ebcd 150
6cba4234
NK
151 test_expect_success "test_initialization" '
152 git reset --hard &&
153 git status # Warm caches
154 '
155
3d53ebcd 156 test_perf_w_drop_caches "status ($DESC)" '
471b1157
NK
157 git status
158 '
14527b30 159
3d53ebcd 160 test_perf_w_drop_caches "status -uno ($DESC)" '
471b1157
NK
161 git status -uno
162 '
14527b30 163
3d53ebcd 164 test_perf_w_drop_caches "status -uall ($DESC)" '
471b1157
NK
165 git status -uall
166 '
14527b30 167
1c6833c8
NK
168 test_perf_w_drop_caches "status (dirty) ($DESC)" '
169 git ls-files | head -100000 | xargs -d "\n" touch -h &&
170 git status
171 '
172
3d53ebcd 173 test_perf_w_drop_caches "diff ($DESC)" '
471b1157
NK
174 git diff
175 '
89afd5f5 176
3d53ebcd 177 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
471b1157
NK
178 git diff -- 1_file
179 '
89afd5f5 180
3d53ebcd 181 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
471b1157
NK
182 git diff -- 10_files
183 '
89afd5f5 184
3d53ebcd 185 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
471b1157
NK
186 git diff -- 100_files
187 '
89afd5f5 188
3d53ebcd 189 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
471b1157
NK
190 git diff -- 1000_files
191 '
89afd5f5 192
3d53ebcd 193 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
471b1157
NK
194 git diff -- 10000_files
195 '
2bfa953e 196
3d53ebcd 197 test_perf_w_drop_caches "add ($DESC)" '
2bfa953e
NK
198 git add --all
199 '
471b1157 200}
89afd5f5 201
a948864a
NK
202if test -n "$GIT_PERF_7519_FSMONITOR"; then
203 for INTEGRATION_PATH in $GIT_PERF_7519_FSMONITOR; do
204 test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor'
205 test_fsmonitor_suite
206 done
207else
208 test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor'
209 test_fsmonitor_suite
210fi
89afd5f5 211
14527b30
BP
212test_expect_success "setup without fsmonitor" '
213 unset INTEGRATION_SCRIPT &&
214 git config --unset core.fsmonitor &&
215 git update-index --no-fsmonitor
216'
217
471b1157 218test_fsmonitor_suite
89afd5f5 219
14527b30
BP
220if test_have_prereq WATCHMAN
221then
222 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
223
224 # Work around Watchman bug on Windows where it holds on to handles
225 # preventing the removal of the trash directory
226 watchman shutdown-server >/dev/null 2>&1
227fi
228
229test_done