Skip to content

Commit

Permalink
Merge pull request #853 from Cysharp/feature/benchmark_nuget
Browse files Browse the repository at this point in the history
chore: Run benchmark with specific Client/Server NuGet version
  • Loading branch information
guitarrapc authored Oct 15, 2024
2 parents 276be0d + ac4ed5c commit 555c036
Show file tree
Hide file tree
Showing 30 changed files with 704 additions and 244 deletions.
188 changes: 106 additions & 82 deletions .github/scripts/benchmark-client-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,107 +8,131 @@ set -euo pipefail
# $ echo $?

function usage {
echo "usage: $(basename $0) --args <string> [options]"
echo "Required:"
echo " --args string Arguments to pass when running the built binary (default: \"\")"
echo "Options:"
echo " --help Show this help message"
cat <<EOF
usage: $(basename $0) --run-args <string> [options]
Required:
--run-args string Arguments to pass when running the built binary (default: \"\")
Options:
--build-args string Arguments to pass when building the project (default: \"\")
--help Show this help message
EOF
}

while [ $# -gt 0 ]; do
case $1 in
# required
--args) _ARGS=$2; shift 2; ;;
--run-args) _RUN_ARGS=$2; shift 2; ;;
# optional
--build-args) _BUILD_ARGS=$2; shift 2; ;;
--help) usage; exit 1; ;;
*) shift ;;
esac
done

function print() {
function print {
echo "$(date "+%Y-%m-%d %H:%M:%S") INFO(${FUNCNAME[1]:-unknown}): $*"
}
function title {
echo ""
echo "$*"
echo "$(date "+%Y-%m-%d %H:%M:%S") INFO(${FUNCNAME[1]:-unknown}): # $*"
}
function error {
echo "$(date "+%Y-%m-%d %H:%M:%S") ERROR(${FUNCNAME[1]:-unknown}): # $*" >&2
}

# parameter setup
repo="MagicOnion"
build_config="Release"
args="${_ARGS:=""}"
build_csproj="perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj"
env_settings=""

binary_name=$(basename "$(dirname "$build_csproj")")
publish_dir="artifacts/$binary_name"
clone_path="$HOME/github/$repo"
output_dir="$clone_path/$publish_dir"
full_process_path="$output_dir/$binary_name"

# show machine name
print "MACHINE_NAME: $(hostname)"
title "Arguments:"
print "--run-args=${_RUN_ARGS:=""}"
print "--build-args=${_BUILD_ARGS:=""}"

title "Constants:"
print " * repo=${repo:="MagicOnion"}"
print " * build_config=${build_config:="Release"}"
print " * build_csproj=${build_csproj:="perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj"}"
print " * env_settings=${env_settings:=""}"
print " * binary_name=${binary_name:=$(basename "$(dirname "$build_csproj")")}"
print " * publish_dir=${publish_dir:="artifacts/$binary_name"}"
print " * clone_path=${clone_path:="$HOME/github/$repo"}"
print " * output_dir=${output_dir:="$clone_path/$publish_dir"}"
print " * full_process_path=${full_process_path:="$output_dir/$binary_name"}"

# machine name
title "Show this machine name"
print " * MACHINE_NAME=$(hostname)"

# is dotnet installed?
print "# Show installed dotnet sdk versions"
echo "dotnet sdk versions (list): $(dotnet --list-sdks)"
echo "dotnet sdk version (default): $(dotnet --version)"

# is already clones?
print "# Check if already cloned $repo"
if [[ ! -d "$clone_path" ]]; then
echop "Failed to find $clone_path, not yet git cloned?"
exit 1
fi

# get branch name and set to environment variables
print "# Set branch name as Environment variable"
pushd "$clone_path"
print " ## get current git branch name"
git_branch=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$git_branch" ]; then
echo "Failed to get branch name, exiting..."
title "Show installed dotnet sdk versions"
print " * dotnet sdk versions (list): $(dotnet --list-sdks)"
print " * dotnet sdk version (default): $(dotnet --version)"

echo "::group::Is already cloned?"
title "Check if already cloned $repo"
if [[ ! -d "$clone_path" ]]; then
error "Failed to find $clone_path, not yet git cloned?"
exit 1
fi

print " ## set branch name to environment variables $git_branch"
export BRANCH_NAME="$git_branch"
popd

# setup env
print "# Setup environment"
IFS=';' read -ra env_array <<< "$env_settings"
for item in "${env_array[@]}"; do
if [[ -n "$item" ]]; then
export "${item?}"
fi
done

# dotnet publish
print "# dotnet publish $build_csproj"
pushd "$clone_path"
print " ## list current files under $(pwd)"
ls -l

print " ## dotnet publish $build_csproj"
dotnet publish -c "$build_config" -p:PublishSingleFile=true --runtime linux-x64 --self-contained false "$build_csproj" -o "$publish_dir"

print " ## list published files under $publish_dir"
ls "$publish_dir"

print " ## add +x permission to published file $full_process_path"
chmod +x "$full_process_path"
popd

# process check
print "# Checking process $binary_name already runnning, kill if exists"
ps -eo pid,cmd | while read -r pid cmd; do
if echo "$cmd" | grep -E "^./$binary_name" >/dev/null 2>&1; then
echo "Found & killing process $pid ($cmd)"
kill "$pid"
fi
done
echo "::endgroup::"

echo "::group::Get branch name and set to environment variables"
title "Set branch name as Environment variable"
pushd "$clone_path" > /dev/null
print "Get current git branch name"
git_branch=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$git_branch" ]; then
error "Failed to get branch name, exiting..."
exit 1
fi

print "Set branch name to environment variables $git_branch"
export BRANCH_NAME="$git_branch"
popd > /dev/null
echo "::endgroup::"

echo "::group::Setup environment variables"
title "Setup environment"
IFS=';' read -ra env_array <<< "$env_settings"
for item in "${env_array[@]}"; do
if [[ -n "$item" ]]; then
export "${item?}"
fi
done
echo "::endgroup::"

echo "::group::Kill existing process"
title "Checking process $binary_name already runnning, kill if exists"
ps -eo pid,cmd | while read -r pid cmd; do
if echo "$cmd" | grep -E "^./$binary_name" >/dev/null 2>&1; then
print "Found & killing process $pid ($cmd)"
kill "$pid"
fi
done
echo "::endgroup::"

echo "::group::dotnet publish"
title "dotnet publish $build_csproj"
pushd "$clone_path" > /dev/null
print "List current files under $(pwd)"
ls -l

print "Remove all files under $publish_dir"
if [[ -d "./$publish_dir" ]]; then
rm -rf "./$publish_dir"
fi

print "dotnet publish $build_csproj $_BUILD_ARGS"
dotnet publish -c "$build_config" -p:PublishSingleFile=true --runtime linux-x64 --self-contained false "$build_csproj" -o "$publish_dir" $_BUILD_ARGS

print "List published files under $publish_dir"
ls "$publish_dir"

print "Add +x permission to published file $full_process_path"
chmod +x "$full_process_path"
popd > /dev/null
echo "::endgroup::"

# run dotnet app
print "# Run $full_process_path $args"
pushd "$output_dir"
title "Run $full_process_path $_RUN_ARGS"
pushd "$output_dir" > /dev/null
# run foreground
"./$binary_name" $args
popd
"./$binary_name" $_RUN_ARGS
popd > /dev/null
Loading

0 comments on commit 555c036

Please sign in to comment.