3 test_description="Test core.fsmonitor"
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.
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.
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.
20 # There are 3 environment variables that can be used to alter the default
21 # behavior of the performance test:
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. (This hook or list of hooks does not
28 # include the built-in fsmonitor--daemon.)
30 # The big win for using fsmonitor is the elimination of the need to scan the
31 # working directory looking for changed and untracked files. If the file
32 # information is all cached in RAM, the benefits are reduced.
34 # GIT_PERF_7519_DROP_CACHE: if set, the OS caches are dropped between tests
36 # GIT_PERF_7519_TRACE: if set, enable trace logging during the test.
37 # Trace logs will be grouped by fsmonitor provider.
40 test_checkout_worktree
42 test_lazy_prereq UNTRACKED_CACHE '
43 { git update-index --test-untracked-cache; ret=$?; } &&
47 test_lazy_prereq WATCHMAN '
51 if test_have_prereq WATCHMAN
53 # Convert unix style paths to escaped Windows style paths for Watchman
56 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
64 if test -n "$GIT_PERF_7519_DROP_CACHE"
66 # When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to
67 # generate valid results. Otherwise the caching that happens for the nth
68 # run will negate the validity of the comparisons.
69 if test "$GIT_PERF_REPEAT_COUNT" -ne 1
71 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
72 GIT_PERF_REPEAT_COUNT=1
77 if test -n "$GIT_PERF_7519_TRACE"
80 TEST_TRACE_DIR="$TEST_OUTPUT_DIRECTORY/test-trace/p7519/"
81 echo "Writing trace logging to $TEST_TRACE_DIR"
83 mkdir -p "$TEST_TRACE_DIR"
85 # Start Trace2 logging and any other GIT_TRACE_* logs that you
86 # want for this named test case.
88 GIT_TRACE2_PERF="$TEST_TRACE_DIR/$name.trace2perf"
89 export GIT_TRACE2_PERF
96 if test -n "$GIT_PERF_7519_TRACE"
102 test_expect_success "one time repo setup" '
103 # set untrackedCache depending on the environment
104 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
106 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
108 if test_have_prereq UNTRACKED_CACHE
110 git config core.untrackedCache true
112 git config core.untrackedCache false
116 # set core.splitindex depending on the environment
117 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
119 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
122 mkdir 1_file 10_files 100_files 1000_files 10000_files &&
123 for i in $(test_seq 1 10); do touch 10_files/$i; done &&
124 for i in $(test_seq 1 100); do touch 100_files/$i; done &&
125 for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
126 for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
127 git add 1_file 10_files 100_files 1000_files 10000_files &&
128 git commit -qm "Add files" &&
130 # If Watchman exists, watch the work tree and attempt a query.
131 if test_have_prereq WATCHMAN; then
132 watchman watch "$GIT_WORK_TREE" &&
133 watchman watch-list | grep -q -F "p7519-fsmonitor"
137 setup_for_fsmonitor() {
138 # set INTEGRATION_SCRIPT depending on the environment
139 if test -n "$USE_FSMONITOR_DAEMON"
141 git config core.useBuiltinFSMonitor true &&
142 INTEGRATION_SCRIPT=false
143 elif test -n "$INTEGRATION_PATH"
145 git config core.useBuiltinFSMonitor false &&
146 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
148 git config core.useBuiltinFSMonitor false &&
150 # Choose integration script based on existence of Watchman.
151 # Fall back to an empty integration script.
154 if test_have_prereq WATCHMAN
156 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
157 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
159 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
160 write_script "$INTEGRATION_SCRIPT"<<-\EOF
165 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
166 git update-index --fsmonitor 2>error &&
167 if test_have_prereq WATCHMAN
169 test_must_be_empty error # ensure no silent error
171 grep "Empty last update token" error
175 test_perf_w_drop_caches () {
176 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
177 test-tool drop-caches
183 test_fsmonitor_suite() {
184 if test -n "$USE_FSMONITOR_DAEMON"
186 DESC="builtin fsmonitor--daemon"
187 elif test -n "$INTEGRATION_SCRIPT"; then
188 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
190 DESC="fsmonitor=disabled"
193 test_expect_success "test_initialization" '
195 git status # Warm caches
198 test_perf_w_drop_caches "status ($DESC)" '
202 test_perf_w_drop_caches "status -uno ($DESC)" '
206 test_perf_w_drop_caches "status -uall ($DESC)" '
210 # Update the mtimes on upto 100k files to make status think
211 # that they are dirty. For simplicity, omit any files with
212 # LFs (i.e. anything that ls-files thinks it needs to dquote).
213 # Then fully backslash-quote the paths to capture any
214 # whitespace so that they pass thru xargs properly.
216 test_perf_w_drop_caches "status (dirty) ($DESC)" '
220 sed '\''s/\(.\)/\\\1/g'\'' | \
221 xargs test-tool chmtime -300 &&
225 test_perf_w_drop_caches "diff ($DESC)" '
229 test_perf_w_drop_caches "diff HEAD ($DESC)" '
233 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
237 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
241 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
242 git diff -- 100_files
245 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
246 git diff -- 1000_files
249 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
250 git diff -- 10000_files
253 test_perf_w_drop_caches "add ($DESC)" '
259 # Run a full set of perf tests using each Hook-based fsmonitor provider,
263 trace_start fsmonitor-watchman
264 if test -n "$GIT_PERF_7519_FSMONITOR"; then
265 for INTEGRATION_PATH in $GIT_PERF_7519_FSMONITOR; do
266 test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor'
270 test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor'
274 if test_have_prereq WATCHMAN
276 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
278 # Work around Watchman bug on Windows where it holds on to handles
279 # preventing the removal of the trash directory
280 watchman shutdown-server >/dev/null 2>&1
285 # Run a full set of perf tests with the fsmonitor feature disabled.
288 trace_start fsmonitor-disabled
289 test_expect_success "setup without fsmonitor" '
290 unset INTEGRATION_SCRIPT &&
291 git config --unset core.fsmonitor &&
292 git update-index --no-fsmonitor
299 # Run a full set of perf tests using the built-in fsmonitor--daemon.
300 # It does not use the Hook API, so it has a different setup.
301 # Explicitly start the daemon here and before we start client commands
302 # so that we can later add custom tracing.
305 test_lazy_prereq HAVE_FSMONITOR_DAEMON '
306 git version --build-options | grep "feature:" | grep "fsmonitor--daemon"
309 if test_have_prereq HAVE_FSMONITOR_DAEMON
311 USE_FSMONITOR_DAEMON=t
313 trace_start fsmonitor--daemon--server
314 git fsmonitor--daemon start
316 trace_start fsmonitor--daemon--client
317 test_expect_success "setup for fsmonitor--daemon" 'setup_for_fsmonitor'
320 git fsmonitor--daemon stop