git_update/performance_tests.sh

167 lines
4.5 KiB
Bash
Raw Normal View History

#!/bin/bash
. driglibash-base
2024-06-27 17:26:06 +00:00
#prerequisite: creation_repo.sh has been run
2024-07-02 16:00:35 +00:00
FILES_TO_KEEP='sample0'
REPO_NAME='performance_testing'
Help()
{
echo "
NAME
performance_tests.sh
SYNOPSIS
performance_tests.sh [-h] [-a] [-n number] [SSH LINK to en empty remote git repository] OPTIONS
-a excutes all the tests.
-n [number] executes test [number]
-h prints the help.
DESCRIPTION
This script is in writing. It allows you to measure memory and bandwidth usage for different method of cloning on the remote repository given.
TEST0: classic cloning
TEST1: --single-branch "
}
2024-07-02 16:00:35 +00:00
#TESTS ON THE INITIAL CLONING
test0(){
section TEST0
echo "TEST 0 : case of classic cloning."
git clone --progress $1 2> cloning_text
2024-07-02 16:00:35 +00:00
mem0=$(du ./$REPO_NAME | tail -n1 | tr -cd [:digit:])
bw0=$(grep -e "Receiving objects:" cloning_text| grep -o "[[:digit:].]* MiB " | tail -n1)
echo "memory usage in a classic cloning : $mem0"
echo "bandwidth usage : $bw0"
2024-07-02 16:00:35 +00:00
run rm -rf $REPO_NAME
}
test1(){
section TEST1
echo "TEST 1 : case of --single-branch cloning."
git clone --progress --single-branch $1 2> cloning_text
2024-07-02 16:00:35 +00:00
mem1=$(du ./$REPO_NAME| tail -n1 | tr -cd [:digit:])
bw1=$(grep -e "Receiving objects:" cloning_text| grep -o "[[:digit:].]* MiB " | tail -n1)
echo "memory usage in a --single-branch cloning : $mem1"
echo "bandwidth usage : $bw1"
run
2024-07-02 16:00:35 +00:00
rm -rf $REPO_NAME
2024-06-28 16:29:11 +00:00
}
test2(){
section TEST2
echo "TEST 2 : case of --depth=1 --no-single-branch"
git clone --progress --depth=1 --no-single-branch $1 2> cloning_text
2024-07-02 16:00:35 +00:00
mem2=$(du ./$REPO_NAME| tail -n1 | tr -cd [:digit:])
2024-06-28 16:29:11 +00:00
bw2=$(grep -e "Receiving objects:" cloning_text| grep -o "[[:digit:].]* MiB " | tail -n1)
echo "memory usage in a --depth=1 --no-single-branch cloning : $mem2"
echo "bandwidth usage : $bw2"
run
2024-07-02 16:00:35 +00:00
rm -rf $REPO_NAME
2024-06-28 16:29:11 +00:00
}
test3(){
section TEST3
echo "TEST 3 : case of --depth=1 with single-branch (default))"
git clone --progress --single-branch --depth=1 $1 2> cloning_text
2024-07-02 16:00:35 +00:00
mem3=$(du ./$REPO_NAME| tail -n1 | tr -cd [:digit:])
2024-06-28 16:29:11 +00:00
bw3=$(grep -e "Receiving objects:" cloning_text| grep -o "[[:digit:].]* MiB " | tail -n1)
echo "memory usage in a --depth=1 with single-branch cloning : $mem3"
echo "bandwidth usage : $bw3"
2024-07-02 16:00:35 +00:00
rm -rf $REPO_NAME
}
2024-07-01 15:57:28 +00:00
test4(){
section TEST4
2024-07-02 16:00:35 +00:00
run mkdir $REPO_NAME
2024-07-01 15:57:28 +00:00
run echo 'TEST 4 : case of sparse-checking only some files with depth=1'
2024-07-02 16:00:35 +00:00
run cd $REPO_NAME
2024-07-01 15:57:28 +00:00
run git init -q
run git config core.sparsecheckout true
2024-07-02 16:00:35 +00:00
run echo $FILES_TO_KEEP >> .git/info/sparse-checkout
run git remote add -f origin $1 &> /dev/null
run git pull origin main &> /dev/null
2024-07-01 15:57:28 +00:00
mem4=$(du . | tail -n1 | tr -cd [:digit:])
2024-07-02 16:00:35 +00:00
echo "memory usage with sparse checking only $FILES_TO_KEEP : $mem4"
echo "The bandwidth usage is not available through the Git commands."
2024-07-01 15:57:28 +00:00
cd ..
2024-07-02 16:00:35 +00:00
run rm -rf $REPO_NAME
}
#TESTS ON THE UPDATING OF THE REPOSITORY
#WITHOUT CHANGING ANYTHING
test5(){
section TEST5
run echo 'TEST 5 : case of classic fetching and merging'
run git clone $1 &> /dev/null
cd $REPO_NAME
mem5temp=$(du . | tail -n1 | tr -cd [:digit:])
run git fetch -v origin &> fetching_text
run git merge -v &> merging_text
mem5=$(du . | tail -n1 | tr -cd [:digit:])
echo "memory usage in a classic fetching and merging : $mem5"
echo "bandwidth usage : $bw5"
2024-07-01 15:57:28 +00:00
}
2024-07-02 16:00:35 +00:00
#test 6 : shallow exclude
2024-07-01 15:57:28 +00:00
while getopts ":hn:a" option; do
case $option in
h) # display Help
Help
exit;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
n)
TEST_NUM=$OPTARG;;
a)
ALL_TESTS=true;;
esac
done
shift "$(($OPTIND -1))" #so that the cloning link is in $1 no matter how many options were used
if [ -z "$1" ]; then
echo "Error: No repository link provided"
Help
die
else
REPO_LINK=$1
fi
if [ "$ALL_TESTS" = true ]; then
test0 $REPO_LINK
test1 $REPO_LINK
2024-06-28 16:29:11 +00:00
test2 $REPO_LINK
test3 $REPO_LINK
2024-07-01 15:57:28 +00:00
test4 $REPO_LINK
2024-07-02 16:00:35 +00:00
test5 $REPO_LINK
2024-06-28 16:29:11 +00:00
elif [ -n "$TEST_NUM" ]; then
case $TEST_NUM in
0)
test0 $REPO_LINK;;
1)
test1 $REPO_LINK;;
2024-06-28 16:29:11 +00:00
2)
test2 $REPO_LINK;;
3)
test3 $REPO_LINK;;
2024-07-01 15:57:28 +00:00
4)
test4 $REPO_LINK;;
2024-07-02 16:00:35 +00:00
5)
test5 $REPO_LINK;;
*)
echo "Error: Invalid test number"
die;;
esac
else
Help
fi
2024-07-02 16:00:35 +00:00
#to do : use a local remote
#optimize in case all tests are run