]> git.ipfire.org Git - thirdparty/git.git/blame - t/perf/p7519-fsmonitor.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[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#
4f2009dc
JH
35# GIT_PERF_7519_TRACE: if set, enable trace logging during the test.
36# Trace logs will be grouped by fsmonitor provider.
14527b30
BP
37
38test_perf_large_repo
39test_checkout_worktree
40
41test_lazy_prereq UNTRACKED_CACHE '
42 { git update-index --test-untracked-cache; ret=$?; } &&
43 test $ret -ne 1
44'
45
46test_lazy_prereq WATCHMAN '
b4f61b7f 47 command -v watchman
14527b30
BP
48'
49
50if test_have_prereq WATCHMAN
51then
52 # Convert unix style paths to escaped Windows style paths for Watchman
53 case "$(uname -s)" in
54 MSYS_NT*)
55 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
56 ;;
57 *)
58 GIT_WORK_TREE="$PWD"
59 ;;
60 esac
61fi
62
63if test -n "$GIT_PERF_7519_DROP_CACHE"
64then
65 # When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to
66 # generate valid results. Otherwise the caching that happens for the nth
67 # run will negate the validity of the comparisons.
68 if test "$GIT_PERF_REPEAT_COUNT" -ne 1
69 then
70 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
71 GIT_PERF_REPEAT_COUNT=1
72 fi
73fi
74
4f2009dc
JH
75trace_start() {
76 if test -n "$GIT_PERF_7519_TRACE"
77 then
78 name="$1"
79 TEST_TRACE_DIR="$TEST_OUTPUT_DIRECTORY/test-trace/p7519/"
80 echo "Writing trace logging to $TEST_TRACE_DIR"
81
82 mkdir -p "$TEST_TRACE_DIR"
83
84 # Start Trace2 logging and any other GIT_TRACE_* logs that you
85 # want for this named test case.
86
87 GIT_TRACE2_PERF="$TEST_TRACE_DIR/$name.trace2perf"
88 export GIT_TRACE2_PERF
89
90 >"$GIT_TRACE2_PERF"
91 fi
92}
93
94trace_stop() {
95 if test -n "$GIT_PERF_7519_TRACE"
96 then
97 unset GIT_TRACE2_PERF
98 fi
99}
100
bb7cc7e7 101test_expect_success "one time repo setup" '
14527b30
BP
102 # set untrackedCache depending on the environment
103 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
104 then
105 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
106 else
107 if test_have_prereq UNTRACKED_CACHE
108 then
109 git config core.untrackedCache true
110 else
111 git config core.untrackedCache false
112 fi
113 fi &&
114
115 # set core.splitindex depending on the environment
116 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
117 then
118 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
119 fi &&
120
bb7cc7e7 121 mkdir 1_file 10_files 100_files 1000_files 10000_files &&
db5875aa
ES
122 for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done &&
123 for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done &&
124 for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done &&
125 for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done &&
bb7cc7e7 126 git add 1_file 10_files 100_files 1000_files 10000_files &&
78ff8b32 127 git commit -qm "Add files" &&
0288b932
NK
128
129 # If Watchman exists, watch the work tree and attempt a query.
130 if test_have_prereq WATCHMAN; then
131 watchman watch "$GIT_WORK_TREE" &&
0917763d 132 watchman watch-list | grep -q -F "p7519-fsmonitor"
0288b932 133 fi
bb7cc7e7
NK
134'
135
a05b71ab 136setup_for_fsmonitor() {
14527b30 137 # set INTEGRATION_SCRIPT depending on the environment
a948864a 138 if test -n "$INTEGRATION_PATH"
14527b30 139 then
a948864a 140 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
14527b30
BP
141 else
142 #
143 # Choose integration script based on existence of Watchman.
0288b932 144 # Fall back to an empty integration script.
14527b30
BP
145 #
146 mkdir .git/hooks &&
147 if test_have_prereq WATCHMAN
148 then
149 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
0288b932 150 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
14527b30
BP
151 else
152 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
153 write_script "$INTEGRATION_SCRIPT"<<-\EOF
154 EOF
155 fi
156 fi &&
157
158 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
33226af4 159 git update-index --fsmonitor 2>error &&
cc2d43be
TB
160 if test_have_prereq WATCHMAN
161 then
162 test_must_be_empty error # ensure no silent error
163 else
164 grep "Empty last update token" error
165 fi
a05b71ab 166}
14527b30 167
471b1157
NK
168test_perf_w_drop_caches () {
169 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
170 test-tool drop-caches
171 fi
14527b30 172
471b1157
NK
173 test_perf "$@"
174}
14527b30 175
471b1157 176test_fsmonitor_suite() {
dd79c167
NK
177 if test -n "$INTEGRATION_SCRIPT"; then
178 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
179 else
180 DESC="fsmonitor=disabled"
181 fi
3d53ebcd 182
6cba4234
NK
183 test_expect_success "test_initialization" '
184 git reset --hard &&
185 git status # Warm caches
186 '
187
3d53ebcd 188 test_perf_w_drop_caches "status ($DESC)" '
471b1157
NK
189 git status
190 '
14527b30 191
3d53ebcd 192 test_perf_w_drop_caches "status -uno ($DESC)" '
471b1157
NK
193 git status -uno
194 '
14527b30 195
3d53ebcd 196 test_perf_w_drop_caches "status -uall ($DESC)" '
471b1157
NK
197 git status -uall
198 '
14527b30 199
eb10e637
JH
200 # Update the mtimes on upto 100k files to make status think
201 # that they are dirty. For simplicity, omit any files with
202 # LFs (i.e. anything that ls-files thinks it needs to dquote).
203 # Then fully backslash-quote the paths to capture any
204 # whitespace so that they pass thru xargs properly.
205 #
1c6833c8 206 test_perf_w_drop_caches "status (dirty) ($DESC)" '
eb10e637
JH
207 git ls-files | \
208 head -100000 | \
209 grep -v \" | \
210 sed '\''s/\(.\)/\\\1/g'\'' | \
211 xargs test-tool chmtime -300 &&
1c6833c8
NK
212 git status
213 '
214
3d53ebcd 215 test_perf_w_drop_caches "diff ($DESC)" '
471b1157
NK
216 git diff
217 '
89afd5f5 218
7e5aa13d
NK
219 test_perf_w_drop_caches "diff HEAD ($DESC)" '
220 git diff HEAD
221 '
222
3d53ebcd 223 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
471b1157
NK
224 git diff -- 1_file
225 '
89afd5f5 226
3d53ebcd 227 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
471b1157
NK
228 git diff -- 10_files
229 '
89afd5f5 230
3d53ebcd 231 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
471b1157
NK
232 git diff -- 100_files
233 '
89afd5f5 234
3d53ebcd 235 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
471b1157
NK
236 git diff -- 1000_files
237 '
89afd5f5 238
3d53ebcd 239 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
471b1157
NK
240 git diff -- 10000_files
241 '
2bfa953e 242
3d53ebcd 243 test_perf_w_drop_caches "add ($DESC)" '
2bfa953e
NK
244 git add --all
245 '
471b1157 246}
89afd5f5 247
a7556c3b
JH
248#
249# Run a full set of perf tests using each Hook-based fsmonitor provider,
250# such as Watchman.
251#
252
4f2009dc 253trace_start fsmonitor-watchman
a948864a
NK
254if test -n "$GIT_PERF_7519_FSMONITOR"; then
255 for INTEGRATION_PATH in $GIT_PERF_7519_FSMONITOR; do
256 test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor'
257 test_fsmonitor_suite
258 done
259else
260 test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor'
261 test_fsmonitor_suite
262fi
89afd5f5 263
14527b30
BP
264if test_have_prereq WATCHMAN
265then
266 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
267
268 # Work around Watchman bug on Windows where it holds on to handles
269 # preventing the removal of the trash directory
270 watchman shutdown-server >/dev/null 2>&1
271fi
4f2009dc 272trace_stop
14527b30 273
a7556c3b
JH
274#
275# Run a full set of perf tests with the fsmonitor feature disabled.
276#
277
4f2009dc 278trace_start fsmonitor-disabled
a7556c3b
JH
279test_expect_success "setup without fsmonitor" '
280 unset INTEGRATION_SCRIPT &&
281 git config --unset core.fsmonitor &&
282 git update-index --no-fsmonitor
283'
284
285test_fsmonitor_suite
4f2009dc 286trace_stop
14527b30
BP
287
288test_done