Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 771ec30

Browse files
committed
benchmarks: introduce --admin flag for admin benchmarks
Some benchmarks require administrative privileges, namely the ones that blow up the disk cache. Don't run them by default, to avoid obnoxious sudo password prompts, etc. Users can specify `--admin` to run them.
1 parent 8d8ab0b commit 771ec30

8 files changed

+47
-5
lines changed

tests/benchmarks/benchmark.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -eo pipefail
66
# parse the command line
77
#
88

9-
usage() { echo "usage: $(basename "$0") [--cli <path>] [--name <cli-name>] [--baseline-cli <path>] [--suite <suite>] [--json <path>] [--flamegraph] [--zip <path>] [--verbose] [--debug]"; }
9+
usage() { echo "usage: $(basename "$0") [--cli <path>] [--name <cli-name>] [--baseline-cli <path>] [--suite <suite>] [--admin] [--json <path>] [--flamegraph] [--zip <path>] [--verbose] [--debug]"; }
1010

1111
TEST_CLI="git"
1212
TEST_CLI_NAME=
@@ -16,6 +16,7 @@ JSON_RESULT=
1616
FLAMEGRAPH=
1717
ZIP_RESULT=
1818
OUTPUT_DIR=
19+
ADMIN=
1920
VERBOSE=
2021
DEBUG=
2122
NEXT=
@@ -58,6 +59,8 @@ for a in "$@"; do
5859
NEXT="suite"
5960
elif [[ "${a}" == "-s"* ]]; then
6061
SUITE="${a/-s/}"
62+
elif [ "${a}" == "--admin" ]; then
63+
ADMIN=1
6164
elif [ "${a}" = "-v" ] || [ "${a}" == "--verbose" ]; then
6265
VERBOSE=1
6366
elif [ "${a}" == "--debug" ]; then
@@ -223,14 +226,18 @@ for TEST_PATH in "${BENCHMARK_DIR}"/*; do
223226
SHOW_OUTPUT="--show-output"
224227
fi
225228

229+
if [ "${ADMIN}" = "1" ]; then
230+
ALLOW_ADMIN="--admin"
231+
fi
232+
226233
OUTPUT_FILE="${OUTPUT_DIR}/${TEST_FILE}.out"
227234
ERROR_FILE="${OUTPUT_DIR}/${TEST_FILE}.err"
228235
JSON_FILE="${OUTPUT_DIR}/${TEST_FILE}.json"
229236
FLAMEGRAPH_FILE="${OUTPUT_DIR}/${TEST_FILE}.svg"
230237

231238
FAILED=
232239
{
233-
${TEST_PATH} --cli "${TEST_CLI}" --baseline-cli "${BASELINE_CLI}" --json "${JSON_FILE}" ${SHOW_OUTPUT} >"${OUTPUT_FILE}" 2>"${ERROR_FILE}";
240+
${TEST_PATH} --cli "${TEST_CLI}" --baseline-cli "${BASELINE_CLI}" --json "${JSON_FILE}" ${ALLOW_ADMIN} ${SHOW_OUTPUT} >"${OUTPUT_FILE}" 2>"${ERROR_FILE}";
234241
FAILED=$?
235242
} || true
236243

@@ -311,6 +318,8 @@ for TEST_PATH in "${BENCHMARK_DIR}"/*; do
311318
ANY_FAILED=1
312319
fi
313320
fi
321+
else
322+
echo ""
314323
fi
315324
done
316325

tests/benchmarks/benchmark_helpers.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ set -eo pipefail
77
# command-line parsing
88
#
99

10-
usage() { echo "usage: $(basename "$0") [--cli <path>] [--baseline-cli <path>] [--output-style <style>] [--json <path>] [--profile] [--flamegraph <path>]"; }
10+
usage() { echo "usage: $(basename "$0") [--cli <path>] [--baseline-cli <path>] [--admin] [--output-style <style>] [--json <path>] [--show-output] [--output-style <style>] [--profile] [--flamegraph <path>]"; }
1111

1212
NEXT=
1313
BASELINE_CLI=
1414
TEST_CLI="git"
15+
ADMIN=
1516
SHOW_OUTPUT=
1617
JSON=
1718
PROFILE=
@@ -69,6 +70,8 @@ for a in "$@"; do
6970
JSON="${a/-j/}"
7071
elif [ "${a}" = "-p" ] || [ "${a}" = "--profile" ]; then
7172
PROFILE=1
73+
elif [ "${a}" = "--admin" ]; then
74+
ADMIN=1
7275
elif [ "${a}" = "-F" ] || [ "${a}" = "--flamegraph" ]; then
7376
NEXT="flamegraph"
7477
elif [[ "${a}" == "-F"* ]]; then
@@ -335,6 +338,9 @@ parse_arguments() {
335338
# this test should run `n` warmups
336339
WARMUP=0
337340

341+
# this test requires administrative privileges
342+
REQUIRES_ADMIN=0
343+
338344
if [ "$*" = "" ]; then
339345
gitbench_usage 1>&2
340346
exit 1
@@ -356,6 +362,8 @@ parse_arguments() {
356362
NEXT="prepare"
357363
elif [ "${a}" = "--chdir" ]; then
358364
NEXT="chdir"
365+
elif [ "${a}" = "--requires-admin" ]; then
366+
REQUIRES_ADMIN=1
359367
elif [[ "${a}" == "--" ]]; then
360368
shift
361369
break
@@ -379,6 +387,7 @@ parse_arguments() {
379387
echo "PREPARE=\"${PREPARE}\""
380388
echo "CHDIR=\"${CHDIR}\""
381389
echo "WARMUP=\"${WARMUP}\""
390+
echo "REQUIRES_ADMIN=\"${REQUIRES_ADMIN}\""
382391

383392
echo -n "GIT_ARGUMENTS=("
384393

@@ -388,7 +397,7 @@ parse_arguments() {
388397
echo " )"
389398
}
390399

391-
gitbench_usage() { echo "usage: gitbench command..."; }
400+
gitbench_usage() { echo "usage: gitbench [--requires-admin] [--warmup <count>] [--prepare <command>] [--chdir <directory>] command..."; }
392401

393402
exec_profiler() {
394403
if [ "${BASELINE_CLI}" != "" ]; then
@@ -490,7 +499,8 @@ exec_hyperfine() {
490499
# invocation of hyperfine.
491500
#
492501
gitbench() {
493-
eval $(parse_arguments "$@")
502+
argument_data=$(parse_arguments "$@")
503+
eval ${argument_data}
494504

495505
# sanity check
496506

@@ -515,6 +525,17 @@ gitbench() {
515525
# rm -rf "${SANDBOX_DIR:?}"
516526
}
517527

528+
# helper script to ensure that --admin is specified
529+
needs_admin() {
530+
if [ "${ADMIN}" != "1" ]; then
531+
echo "$0: skipping administrator test" 1>&2
532+
echo "" 1>&2
533+
echo "This benchmark needs administrative (root) privileges. To run it," 1>&2
534+
echo "specify '--admin' to the benchmark." 1>&2
535+
exit 2
536+
fi
537+
}
538+
518539
# helper script to give useful error messages about configuration
519540
needs_repo() {
520541
REPO="${1}"

tests/benchmarks/hash-object__text_nocache_100kb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "create_text_file text_100kb 102400 &&
68
flush_disk_cache" \
79
hash-object "text_100kb"

tests/benchmarks/hash-object__text_nocache_10mb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "create_text_file text_10mb 10485760 &&
68
flush_disk_cache" \
79
hash-object "text_10mb"

tests/benchmarks/hash-object__text_nocache_1kb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "create_text_file text_1kb 1024 &&
68
flush_disk_cache" \
79
hash-object "text_1kb"

tests/benchmarks/hash-object__write_text_nocache_100kb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "sandbox_repo empty_standard_repo &&
68
create_text_file text_100kb 102400 &&
79
flush_disk_cache" \

tests/benchmarks/hash-object__write_text_nocache_10mb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "sandbox_repo empty_standard_repo &&
68
create_text_file text_10mb 10485760 &&
79
flush_disk_cache" \

tests/benchmarks/hash-object__write_text_nocache_1kb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_admin
6+
57
gitbench --prepare "sandbox_repo empty_standard_repo &&
68
create_text_file text_1kb 1024 &&
79
flush_disk_cache" \

0 commit comments

Comments
 (0)