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.
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.
33 # GIT_PERF_7519_DROP_CACHE: if set, the OS caches are dropped between tests
37 test_checkout_worktree
39 test_lazy_prereq UNTRACKED_CACHE '
40 { git update-index --test-untracked-cache; ret=$?; } &&
44 test_lazy_prereq WATCHMAN '
48 if test_have_prereq WATCHMAN
50 # Convert unix style paths to escaped Windows style paths for Watchman
53 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
61 if test -n "$GIT_PERF_7519_DROP_CACHE"
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
68 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
69 GIT_PERF_REPEAT_COUNT=1
73 test_expect_success "one time repo setup" '
74 # set untrackedCache depending on the environment
75 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
77 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
79 if test_have_prereq UNTRACKED_CACHE
81 git config core.untrackedCache true
83 git config core.untrackedCache false
87 # set core.splitindex depending on the environment
88 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
90 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
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 &&
99 git commit -qm "Add files" &&
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"
108 setup_for_fsmonitor() {
109 # set INTEGRATION_SCRIPT depending on the environment
110 if test -n "$INTEGRATION_PATH"
112 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
115 # Choose integration script based on existence of Watchman.
116 # Fall back to an empty integration script.
119 if test_have_prereq WATCHMAN
121 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
122 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
124 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
125 write_script "$INTEGRATION_SCRIPT"<<-\EOF
130 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
131 git update-index --fsmonitor 2>error &&
133 [ ! -s error ] # ensure no silent error
136 test_perf_w_drop_caches () {
137 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
138 test-tool drop-caches
144 test_fsmonitor_suite() {
145 if test -n "$INTEGRATION_SCRIPT"; then
146 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
148 DESC="fsmonitor=disabled"
151 test_expect_success "test_initialization" '
153 git status # Warm caches
156 test_perf_w_drop_caches "status ($DESC)" '
160 test_perf_w_drop_caches "status -uno ($DESC)" '
164 test_perf_w_drop_caches "status -uall ($DESC)" '
168 test_perf_w_drop_caches "status (dirty) ($DESC)" '
169 git ls-files | head -100000 | xargs -d "\n" touch -h &&
173 test_perf_w_drop_caches "diff ($DESC)" '
177 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
181 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
185 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
186 git diff -- 100_files
189 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
190 git diff -- 1000_files
193 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
194 git diff -- 10000_files
197 test_perf_w_drop_caches "add ($DESC)" '
202 if 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'
208 test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor'
212 test_expect_success "setup without fsmonitor" '
213 unset INTEGRATION_SCRIPT &&
214 git config --unset core.fsmonitor &&
215 git update-index --no-fsmonitor
220 if test_have_prereq WATCHMAN
222 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
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