summaryrefslogtreecommitdiffstats
path: root/t/perf/p7527-builtin-fsmonitor.sh
blob: c3f9a4caa4caadca271982c2e9f872d977c3610b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/sh

test_description="Perf test for the builtin FSMonitor"

. ./perf-lib.sh

if ! test_have_prereq FSMONITOR_DAEMON
then
	skip_all="fsmonitor--daemon is not supported on this platform"
	test_done
fi

test_lazy_prereq UNTRACKED_CACHE '
	{ git update-index --test-untracked-cache; ret=$?; } &&
	test $ret -ne 1
'

# Lie to perf-lib and ask for a new empty repo and avoid
# the complaints about GIT_PERF_REPO not being big enough
# the perf hit when GIT_PERF_LARGE_REPO is copied into
# the trash directory.
#
# NEEDSWORK: It would be nice if perf-lib had an option to
# "borrow" an existing large repo (especially for gigantic
# monorepos) and use it in-place.  For now, fake it here.
#
test_perf_fresh_repo


# Use a generated synthetic monorepo.  If it doesn't exist, we will
# generate it.  If it does exist, we will put it in a known state
# before we start our timings.
#
PARAM_D=5
PARAM_W=10
PARAM_F=9

PARAMS="$PARAM_D"."$PARAM_W"."$PARAM_F"

BALLAST_BR=p0006-ballast
export BALLAST_BR

TMP_BR=tmp_br
export TMP_BR

REPO=../repos/gen-many-files-"$PARAMS".git
export REPO

if ! test -d $REPO
then
	(cd ../repos; ./many-files.sh -d $PARAM_D -w $PARAM_W -f $PARAM_F)
fi


enable_uc () {
	git -C $REPO config core.untrackedcache true
	git -C $REPO update-index --untracked-cache
	git -C $REPO status >/dev/null 2>&1
}

disable_uc () {
	git -C $REPO config core.untrackedcache false
	git -C $REPO update-index --no-untracked-cache
	git -C $REPO status >/dev/null 2>&1
}

start_fsm () {
	git -C $REPO fsmonitor--daemon start
	git -C $REPO fsmonitor--daemon status
	git -C $REPO config core.fsmonitor true
	git -C $REPO update-index --fsmonitor
	git -C $REPO status >/dev/null 2>&1
}

stop_fsm () {
	git -C $REPO config --unset core.fsmonitor
	git -C $REPO update-index --no-fsmonitor
	test_might_fail git -C $REPO fsmonitor--daemon stop 2>/dev/null
	git -C $REPO status >/dev/null 2>&1
}


# Ensure that FSMonitor is turned off on the borrowed repo.
#
test_expect_success "Setup borrowed repo (fsm+uc)" "
	stop_fsm &&
	disable_uc
"

# Also ensure that it starts in a known state.
#
# Because we assume that $GIT_PERF_REPEAT_COUNT > 1, we are not going to time
# the ballast checkout, since only the first invocation does any work and the
# subsequent ones just print "already on branch" and quit, so the reported
# time is not useful.
#
# Create a temp branch and do all work relative to it so that we don't
# accidentially alter the real ballast branch.
#
test_expect_success "Setup borrowed repo (temp ballast branch)" "
	test_might_fail git -C $REPO checkout $BALLAST_BR &&
	test_might_fail git -C $REPO reset --hard &&
	git -C $REPO clean -d -f &&
	test_might_fail git -C $REPO branch -D $TMP_BR &&
	git -C $REPO branch $TMP_BR $BALLAST_BR &&
	git -C $REPO checkout $TMP_BR
"


echo Data >data.txt

# NEEDSWORK: We assume that $GIT_PERF_REPEAT_COUNT > 1.  With
# FSMonitor enabled, we can get a skewed view of status times, since
# the index MAY (or may not) be updated after the first invocation
# which will update the FSMonitor Token, so the subsequent invocations
# may get a smaller response from the daemon.
#
do_status () {
	msg=$1

	test_perf "$msg" "
		git -C $REPO status >/dev/null 2>&1
	"
}

do_matrix () {
	uc=$1
	fsm=$2

	t="[uc $uc][fsm $fsm]"
	MATRIX_BR="$TMP_BR-$uc-$fsm"

	test_expect_success "$t Setup matrix branch" "
		git -C $REPO clean -d -f &&
		git -C $REPO checkout $TMP_BR &&
		test_might_fail git -C $REPO branch -D $MATRIX_BR &&
		git -C $REPO branch $MATRIX_BR $TMP_BR &&
		git -C $REPO checkout $MATRIX_BR
	"

	if test $uc = true
	then
		enable_uc
	else
		disable_uc
	fi

	if test $fsm = true
	then
		start_fsm
	else
		stop_fsm
	fi

	do_status "$t status after checkout"

	# Modify many files in the matrix branch.
	# Stage them.
	# Commit them.
	# Rollback.
	#
	test_expect_success "$t modify tracked files" "
		find $REPO -name file1 -exec cp data.txt {} \\;
	"

	do_status "$t status after big change"

	# Don't bother timing the "add" because _REPEAT_COUNT
	# issue described above.
	#
	test_expect_success "$t add all" "
		git -C $REPO add -A
	"

	do_status "$t status after add all"

	test_expect_success "$t add dot" "
		git -C $REPO add .
	"

	do_status "$t status after add dot"

	test_expect_success "$t commit staged" "
		git -C $REPO commit -a -m data
	"

	do_status "$t status after commit"

	test_expect_success "$t reset HEAD~1 hard" "
		git -C $REPO reset --hard HEAD~1 >/dev/null 2>&1
	"

	do_status "$t status after reset hard"

	# Create some untracked files.
	#
	test_expect_success "$t create untracked files" "
		cp -R $REPO/ballast/dir1 $REPO/ballast/xxx1
	"

	do_status "$t status after create untracked files"

	# Remove the new untracked files.
	#
	test_expect_success "$t clean -df" "
		git -C $REPO clean -d -f
	"

	do_status "$t status after clean"

	if test $fsm = true
	then
		stop_fsm
	fi
}

# Begin testing each case in the matrix that we care about.
#
uc_values="false"
test_have_prereq UNTRACKED_CACHE && uc_values="false true"

fsm_values="false true"

for uc_val in $uc_values
do
	for fsm_val in $fsm_values
	do
		do_matrix $uc_val $fsm_val
	done
done

cleanup () {
	uc=$1
	fsm=$2

	MATRIX_BR="$TMP_BR-$uc-$fsm"

	test_might_fail git -C $REPO branch -D $MATRIX_BR
}


# We're borrowing this repo.  We should leave it in a clean state.
#
test_expect_success "Cleanup temp and matrix branches" "
	git -C $REPO clean -d -f &&
	test_might_fail git -C $REPO checkout $BALLAST_BR &&
	test_might_fail git -C $REPO branch -D $TMP_BR &&
	for uc_val in $uc_values
	do
		for fsm_val in $fsm_values
		do
			cleanup $uc_val $fsm_val || return 1
		done
	done
"

test_done