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
27 # The big win for using fsmonitor is the elimination of the need to scan the
28 # working directory looking for changed and untracked files. If the file
29 # information is all cached in RAM, the benefits are reduced.
31 # GIT_PERF_7519_DROP_CACHE: if set, the OS caches are dropped between tests
35 test_checkout_worktree
37 test_lazy_prereq UNTRACKED_CACHE '
38 { git update-index --test-untracked-cache; ret=$?; } &&
42 test_lazy_prereq WATCHMAN '
46 if test_have_prereq WATCHMAN
48 # Convert unix style paths to escaped Windows style paths for Watchman
51 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
59 if test -n "$GIT_PERF_7519_DROP_CACHE"
61 # When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to
62 # generate valid results. Otherwise the caching that happens for the nth
63 # run will negate the validity of the comparisons.
64 if test "$GIT_PERF_REPEAT_COUNT" -ne 1
66 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
67 GIT_PERF_REPEAT_COUNT=1
71 test_expect_success "setup for fsmonitor" '
72 # set untrackedCache depending on the environment
73 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
75 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
77 if test_have_prereq UNTRACKED_CACHE
79 git config core.untrackedCache true
81 git config core.untrackedCache false
85 # set core.splitindex depending on the environment
86 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
88 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
91 # set INTEGRATION_SCRIPT depending on the environment
92 if test -n "$GIT_PERF_7519_FSMONITOR"
94 INTEGRATION_SCRIPT="$GIT_PERF_7519_FSMONITOR"
97 # Choose integration script based on existence of Watchman.
98 # If Watchman exists, watch the work tree and attempt a query.
99 # If everything succeeds, use Watchman integration script,
100 # else fall back to an empty integration script.
103 if test_have_prereq WATCHMAN
105 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
106 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT" &&
107 watchman watch "$GIT_WORK_TREE" &&
108 watchman watch-list | grep -q -F "$GIT_WORK_TREE"
110 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
111 write_script "$INTEGRATION_SCRIPT"<<-\EOF
116 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
117 git update-index --fsmonitor
120 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
121 test-tool drop-caches
124 test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
128 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
129 test-tool drop-caches
132 test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
136 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
137 test-tool drop-caches
140 test_perf "status -uall (fsmonitor=$INTEGRATION_SCRIPT)" '
144 test_expect_success "setup without fsmonitor" '
145 unset INTEGRATION_SCRIPT &&
146 git config --unset core.fsmonitor &&
147 git update-index --no-fsmonitor
150 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
151 test-tool drop-caches
154 test_perf "status (fsmonitor=$INTEGRATION_SCRIPT)" '
158 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
159 test-tool drop-caches
162 test_perf "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
166 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
167 test-tool drop-caches
170 test_perf "status -uall (fsmonitor=$INTEGRATION_SCRIPT)" '
174 if test_have_prereq WATCHMAN
176 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
178 # Work around Watchman bug on Windows where it holds on to handles
179 # preventing the removal of the trash directory
180 watchman shutdown-server >/dev/null 2>&1