]> git.ipfire.org Git - thirdparty/git.git/blob - t/perf/p7519-fsmonitor.sh
doc/git-branch: fix awkward wording for "-c"
[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
36 test_perf_large_repo
37 test_checkout_worktree
38
39 test_lazy_prereq UNTRACKED_CACHE '
40 { git update-index --test-untracked-cache; ret=$?; } &&
41 test $ret -ne 1
42 '
43
44 test_lazy_prereq WATCHMAN '
45 command -v watchman
46 '
47
48 if test_have_prereq WATCHMAN
49 then
50 # Convert unix style paths to escaped Windows style paths for Watchman
51 case "$(uname -s)" in
52 MSYS_NT*)
53 GIT_WORK_TREE="$(cygpath -aw "$PWD" | sed 's,\\,/,g')"
54 ;;
55 *)
56 GIT_WORK_TREE="$PWD"
57 ;;
58 esac
59 fi
60
61 if test -n "$GIT_PERF_7519_DROP_CACHE"
62 then
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
67 then
68 echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
69 GIT_PERF_REPEAT_COUNT=1
70 fi
71 fi
72
73 test_expect_success "one time repo setup" '
74 # set untrackedCache depending on the environment
75 if test -n "$GIT_PERF_7519_UNTRACKED_CACHE"
76 then
77 git config core.untrackedCache "$GIT_PERF_7519_UNTRACKED_CACHE"
78 else
79 if test_have_prereq UNTRACKED_CACHE
80 then
81 git config core.untrackedCache true
82 else
83 git config core.untrackedCache false
84 fi
85 fi &&
86
87 # set core.splitindex depending on the environment
88 if test -n "$GIT_PERF_7519_SPLIT_INDEX"
89 then
90 git config core.splitIndex "$GIT_PERF_7519_SPLIT_INDEX"
91 fi &&
92
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" &&
100
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"
105 fi
106 '
107
108 setup_for_fsmonitor() {
109 # set INTEGRATION_SCRIPT depending on the environment
110 if test -n "$INTEGRATION_PATH"
111 then
112 INTEGRATION_SCRIPT="$INTEGRATION_PATH"
113 else
114 #
115 # Choose integration script based on existence of Watchman.
116 # Fall back to an empty integration script.
117 #
118 mkdir .git/hooks &&
119 if test_have_prereq WATCHMAN
120 then
121 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-watchman" &&
122 cp "$TEST_DIRECTORY/../templates/hooks--fsmonitor-watchman.sample" "$INTEGRATION_SCRIPT"
123 else
124 INTEGRATION_SCRIPT=".git/hooks/fsmonitor-empty" &&
125 write_script "$INTEGRATION_SCRIPT"<<-\EOF
126 EOF
127 fi
128 fi &&
129
130 git config core.fsmonitor "$INTEGRATION_SCRIPT" &&
131 git update-index --fsmonitor 2>error &&
132 test_must_be_empty error # ensure no silent error
133 }
134
135 test_perf_w_drop_caches () {
136 if test -n "$GIT_PERF_7519_DROP_CACHE"; then
137 test-tool drop-caches
138 fi
139
140 test_perf "$@"
141 }
142
143 test_fsmonitor_suite() {
144 if test -n "$INTEGRATION_SCRIPT"; then
145 DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)"
146 else
147 DESC="fsmonitor=disabled"
148 fi
149
150 test_expect_success "test_initialization" '
151 git reset --hard &&
152 git status # Warm caches
153 '
154
155 test_perf_w_drop_caches "status ($DESC)" '
156 git status
157 '
158
159 test_perf_w_drop_caches "status -uno ($DESC)" '
160 git status -uno
161 '
162
163 test_perf_w_drop_caches "status -uall ($DESC)" '
164 git status -uall
165 '
166
167 test_perf_w_drop_caches "status (dirty) ($DESC)" '
168 git ls-files | head -100000 | xargs -d "\n" touch -h &&
169 git status
170 '
171
172 test_perf_w_drop_caches "diff ($DESC)" '
173 git diff
174 '
175
176 test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
177 git diff -- 1_file
178 '
179
180 test_perf_w_drop_caches "diff -- 10_files ($DESC)" '
181 git diff -- 10_files
182 '
183
184 test_perf_w_drop_caches "diff -- 100_files ($DESC)" '
185 git diff -- 100_files
186 '
187
188 test_perf_w_drop_caches "diff -- 1000_files ($DESC)" '
189 git diff -- 1000_files
190 '
191
192 test_perf_w_drop_caches "diff -- 10000_files ($DESC)" '
193 git diff -- 10000_files
194 '
195
196 test_perf_w_drop_caches "add ($DESC)" '
197 git add --all
198 '
199 }
200
201 if test -n "$GIT_PERF_7519_FSMONITOR"; then
202 for INTEGRATION_PATH in $GIT_PERF_7519_FSMONITOR; do
203 test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor'
204 test_fsmonitor_suite
205 done
206 else
207 test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor'
208 test_fsmonitor_suite
209 fi
210
211 test_expect_success "setup without fsmonitor" '
212 unset INTEGRATION_SCRIPT &&
213 git config --unset core.fsmonitor &&
214 git update-index --no-fsmonitor
215 '
216
217 test_fsmonitor_suite
218
219 if test_have_prereq WATCHMAN
220 then
221 watchman watch-del "$GIT_WORK_TREE" >/dev/null 2>&1 &&
222
223 # Work around Watchman bug on Windows where it holds on to handles
224 # preventing the removal of the trash directory
225 watchman shutdown-server >/dev/null 2>&1
226 fi
227
228 test_done