Merge branch 'cw/ci-ghwf-check-ws-errors'
[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
26 #
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.
30 #
31 # GIT_PERF_7519_DROP_CACHE: if set, the OS caches are dropped between tests
32 #
33
34 test_perf_large_repo
35 test_checkout_worktree
36
37 test_lazy_prereq UNTRACKED_CACHE '
38         { git update-index --test-untracked-cache; ret=$?; } &&
39         test $ret -ne 1
40 '
41
42 test_lazy_prereq WATCHMAN '
43         command -v watchman
44 '
45
46 if test_have_prereq WATCHMAN
47 then
48         # Convert unix style paths to escaped Windows style paths for Watchman
49         case "$(uname -s)" in
50         MSYS_NT*)
51           GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
52           ;;
53         *)
54           GIT_WORK_TREE="$PWD"
55           ;;
56         esac
57 fi
58
59 if test -n "$GIT_PERF_7519_DROP_CACHE"
60 then
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
65         then
66                 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
67                 GIT_PERF_REPEAT_COUNT=1
68         fi
69 fi
70
71 test_expect_success "setup for fsmonitor" '
72         # set untrackedCache depending on the environment
73         if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
74         then
75                 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
76         else
77                 if test_have_prereq UNTRACKED_CACHE
78                 then
79                         git config core.untrackedCache true
80                 else
81                         git config core.untrackedCache false
82                 fi
83         fi &&
84
85         # set core.splitindex depending on the environment
86         if test -n "$GIT_PERF_7519_SPLIT_INDEX"
87         then
88                 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
89         fi &&
90
91         # set INTEGRATION_SCRIPT depending on the environment
92         if test -n "$GIT_PERF_7519_FSMONITOR"
93         then
94                 INTEGRATION_SCRIPT="$GIT_PERF_7519_FSMONITOR"
95         else
96                 #
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.
101                 #
102                 mkdir .git/hooks &&
103                 if test_have_prereq WATCHMAN
104                 then
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"
109                 else
110                         INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
111                         write_script "$INTEGRATION_SCRIPT"<<-\EOF
112                         EOF
113                 fi
114         fi &&
115
116         git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
117         git update-index --fsmonitor &&
118         mkdir 1_file 10_files 100_files 1000_files 10000_files &&
119         for i in $(test_seq 1 10); do touch 10_files/$i; done &&
120         for i in $(test_seq 1 100); do touch 100_files/$i; done &&
121         for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
122         for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
123         git add 1_file 10_files 100_files 1000_files 10000_files &&
124         git commit -m "Add files" &&
125         git status  # Warm caches
126 '
127
128 test_perf_w_drop_caches () {
129         if test -n "$GIT_PERF_7519_DROP_CACHE"; then
130                 test-tool drop-caches
131         fi
132
133         test_perf "$@"
134 }
135
136 test_fsmonitor_suite() {
137         test_perf_w_drop_caches "status (fsmonitor=$INTEGRATION_SCRIPT)" '
138                 git status
139         '
140
141         test_perf_w_drop_caches "status -uno (fsmonitor=$INTEGRATION_SCRIPT)" '
142                 git status -uno
143         '
144
145         test_perf_w_drop_caches "status -uall (fsmonitor=$INTEGRATION_SCRIPT)" '
146                 git status -uall
147         '
148
149         test_perf_w_drop_caches "diff (fsmonitor=$INTEGRATION_SCRIPT)" '
150                 git diff
151         '
152
153         test_perf_w_drop_caches "diff -- 0_files (fsmonitor=$INTEGRATION_SCRIPT)" '
154                 git diff -- 1_file
155         '
156
157         test_perf_w_drop_caches "diff -- 10_files (fsmonitor=$INTEGRATION_SCRIPT)" '
158                 git diff -- 10_files
159         '
160
161         test_perf_w_drop_caches "diff -- 100_files (fsmonitor=$INTEGRATION_SCRIPT)" '
162                 git diff -- 100_files
163         '
164
165         test_perf_w_drop_caches "diff -- 1000_files (fsmonitor=$INTEGRATION_SCRIPT)" '
166                 git diff -- 1000_files
167         '
168
169         test_perf_w_drop_caches "diff -- 10000_files (fsmonitor=$INTEGRATION_SCRIPT)" '
170                 git diff -- 10000_files
171         '
172
173         test_perf_w_drop_caches "add (fsmonitor=$INTEGRATION_SCRIPT)" '
174                 git add  --all
175         '
176 }
177
178 test_fsmonitor_suite
179
180 test_expect_success "setup without fsmonitor" '
181         unset INTEGRATION_SCRIPT &&
182         git config --unset core.fsmonitor &&
183         git update-index --no-fsmonitor
184 '
185
186 test_fsmonitor_suite
187
188 if test_have_prereq WATCHMAN
189 then
190         watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
191
192         # Work around Watchman bug on Windows where it holds on to handles
193         # preventing the removal of the trash directory
194         watchman shutdown-server >/dev/null 2>&1
195 fi
196
197 test_done