]> git.ipfire.org Git - thirdparty/git.git/blob - t/perf/p7519-fsmonitor.sh
Merge branch 'ns/batch-fsync'
[thirdparty/git.git] / t / perf / p7519-fsmonitor.sh
1 #!/bin/sh
2
3 test_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
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.
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 # GIT_PERF_7519_TRACE: if set, enable trace logging during the test.
36 # Trace logs will be grouped by fsmonitor provider.
37
38 test_perf_large_repo
39 test_checkout_worktree
40
41 test_lazy_prereq UNTRACKED_CACHE '
42 { git update-index --test-untracked-cache; ret=$?; } &&
43 test $ret -ne 1
44 '
45
46 test_lazy_prereq WATCHMAN '
47 command -v watchman
48 '
49
50 if test_have_prereq WATCHMAN
51 then
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
61 fi
62
63 trace_start () {
64 if test -n "$GIT_PERF_7519_TRACE"
65 then
66 name="$1"
67 TEST_TRACE_DIR="$TEST_OUTPUT_DIRECTORY/test-trace/p7519/"
68 echo "Writing trace logging to $TEST_TRACE_DIR"
69
70 mkdir -p "$TEST_TRACE_DIR"
71
72 # Start Trace2 logging and any other GIT_TRACE_* logs that you
73 # want for this named test case.
74
75 GIT_TRACE2_PERF="$TEST_TRACE_DIR/$name.trace2perf"
76 export GIT_TRACE2_PERF
77
78 >"$GIT_TRACE2_PERF"
79 fi
80 }
81
82 trace_stop () {
83 if test -n "$GIT_PERF_7519_TRACE"
84 then
85 unset GIT_TRACE2_PERF
86 fi
87 }
88
89 touch_files () {
90 n=$1 &&
91 d="$n"_files &&
92
93 (cd $d && test_seq 1 $n | xargs touch )
94 }
95
96 test_expect_success "one time repo setup" '
97 # set untrackedCache depending on the environment
98 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
99 then
100 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
101 else
102 if test_have_prereq UNTRACKED_CACHE
103 then
104 git config core.untrackedCache true
105 else
106 git config core.untrackedCache false
107 fi
108 fi &&
109
110 # set core.splitindex depending on the environment
111 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
112 then
113 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
114 fi &&
115
116 mkdir 1_file 10_files 100_files 1000_files 10000_files &&
117 : 1_file directory should be left empty &&
118 touch_files 10 &&
119 touch_files 100 &&
120 touch_files 1000 &&
121 touch_files 10000 &&
122 git add 1_file 10_files 100_files 1000_files 10000_files &&
123 git commit -qm "Add files" &&
124
125 # If Watchman exists, watch the work tree and attempt a query.
126 if test_have_prereq WATCHMAN; then
127 watchman watch "$GIT_WORK_TREE" &&
128 watchman watch-list | grep -q -F "p7519-fsmonitor"
129 fi
130 '
131
132 setup_for_fsmonitor_hook () {
133 # set INTEGRATION_SCRIPT depending on the environment
134 if test -n "$INTEGRATION_PATH"
135 then
136 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
137 else
138 #
139 # Choose integration script based on existence of Watchman.
140 # Fall back to an empty integration script.
141 #
142 mkdir .git/hooks &&
143 if test_have_prereq WATCHMAN
144 then
145 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
146 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
147 else
148 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
149 write_script "$INTEGRATION_SCRIPT"<<-\EOF
150 EOF
151 fi
152 fi &&
153
154 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
155 git update-index --fsmonitor 2>error &&
156 if test_have_prereq WATCHMAN
157 then
158 test_must_be_empty error # ensure no silent error
159 else
160 grep "Empty last update token" error
161 fi
162 }
163
164 test_perf_w_drop_caches () {
165 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
166 test_perf "$1" --setup "test-tool drop-caches" "$2"
167 else
168 test_perf "$@"
169 fi
170 }
171
172 test_fsmonitor_suite () {
173 if test -n "$USE_FSMONITOR_DAEMON"
174 then
175 DESC="builtin fsmonitor--daemon"
176 elif test -n "$INTEGRATION_SCRIPT"
177 then
178 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
179 else
180 DESC="fsmonitor=disabled"
181 fi
182
183 test_expect_success "test_initialization" '
184 git reset --hard &&
185 git status # Warm caches
186 '
187
188 test_perf_w_drop_caches "status ($DESC)" '
189 git status
190 '
191
192 test_perf_w_drop_caches "status -uno ($DESC)" '
193 git status -uno
194 '
195
196 test_perf_w_drop_caches "status -uall ($DESC)" '
197 git status -uall
198 '
199
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 # and any files with whitespace so that they pass thru xargs
204 # properly.
205 #
206 test_perf_w_drop_caches "status (dirty) ($DESC)" '
207 git ls-files | \
208 head -100000 | \
209 grep -v \" | \
210 grep -v " ." | \
211 xargs test-tool chmtime -300 &&
212 git status
213 '
214
215 test_perf_w_drop_caches "diff ($DESC)" '
216 git diff
217 '
218
219 test_perf_w_drop_caches "diff HEAD ($DESC)" '
220 git diff HEAD
221 '
222
223 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
224 git diff -- 1_file
225 '
226
227 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
228 git diff -- 10_files
229 '
230
231 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
232 git diff -- 100_files
233 '
234
235 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
236 git diff -- 1000_files
237 '
238
239 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
240 git diff -- 10000_files
241 '
242
243 test_perf_w_drop_caches "add ($DESC)" '
244 git add --all
245 '
246 }
247
248 #
249 # Run a full set of perf tests using each Hook-based fsmonitor provider,
250 # such as Watchman.
251 #
252
253 trace_start fsmonitor-watchman
254 if 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_hook'
257 test_fsmonitor_suite
258 done
259 else
260 test_expect_success "setup for fsmonitor hook" 'setup_for_fsmonitor_hook'
261 test_fsmonitor_suite
262 fi
263
264 if test_have_prereq WATCHMAN
265 then
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
271 fi
272 trace_stop
273
274 #
275 # Run a full set of perf tests with the fsmonitor feature disabled.
276 #
277
278 trace_start fsmonitor-disabled
279 test_expect_success "setup without fsmonitor" '
280 unset INTEGRATION_SCRIPT &&
281 git config --unset core.fsmonitor &&
282 git update-index --no-fsmonitor
283 '
284
285 test_fsmonitor_suite
286 trace_stop
287
288 #
289 # Run a full set of perf tests using the built-in fsmonitor--daemon.
290 # It does not use the Hook API, so it has a different setup.
291 # Explicitly start the daemon here and before we start client commands
292 # so that we can later add custom tracing.
293 #
294 if test_have_prereq FSMONITOR_DAEMON
295 then
296 USE_FSMONITOR_DAEMON=t
297
298 test_expect_success "setup for builtin fsmonitor" '
299 trace_start fsmonitor--daemon--server &&
300 git fsmonitor--daemon start &&
301
302 trace_start fsmonitor--daemon--client &&
303
304 git config core.fsmonitor true &&
305 git update-index --fsmonitor
306 '
307
308 test_fsmonitor_suite
309
310 git fsmonitor--daemon stop
311 trace_stop
312 fi
313
314 test_done