-
Notifications
You must be signed in to change notification settings - Fork 101
CPU Profiling #1242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CPU Profiling #1242
Changes from 48 commits
633a3e3
40b2448
6943112
bc35b5b
03aa8a3
ccba02c
225d5c9
ae1b891
6b07712
8424529
332e9ed
81ea24f
32b15f3
b5dda8c
d2419ba
9f12816
b0fd625
15af15a
027d295
9909566
afcac2e
4312e1c
8d7dfdc
79363d0
078906e
162b7be
1622d7e
3eaaa73
eb4ce92
48d625e
2968fb2
dc37e5d
c864158
d5f79af
2b9a75d
c941c9c
69d6b9c
099b835
5fd8cbe
b406089
182ee1f
4d2b360
994d2ef
1c46c47
bcc0153
7c4d8a9
062421f
64dc928
5ce82c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script runs Go tests with CPU profiling enabled for all test packages found under the directories: | ||
# - internal/watcher | ||
# - test/integration | ||
# It saves the CPU profiles in the $PROFILES_DIR directory with the format <package-name>_<test_type>.pprof | ||
# e.g. <package-name>_watcher_cpu.pprof or <package-name>_integration_cpu.pprof | ||
|
||
# The variables below can be set to customize the environment for the integration tests: | ||
# Example using variables defined in our Makefile: | ||
# TEST_ENV=ci CONTAINER_OS_TYPE=linux BUILD_TARGET=agent PACKAGES_REPO=nginxinc \ | ||
# PACKAGE_NAME=nginx-agent BASE_IMAGE=ubuntu OS_VERSION=20.04 OS_RELEASE=focal \ | ||
# DOCKERFILE_PATH=Dockerfile IMAGE_PATH=nginxinc/nginx-agent TAG=latest CONTAINER_NGINX_IMAGE_REGISTRY=docker.io \ | ||
# ./scripts/performance/profiling.sh | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
PROFILES_DIR="build/test/profiles" | ||
mkdir -p ${PROFILES_DIR} | ||
|
||
# Run watcher tests with CPU profiling for each package | ||
echo "Starting watcher tests with cpu profiling..." | ||
packages=$(find internal/watcher -type f -name '*_test.go' -exec dirname {} \; | sort -u) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add a script? Could this be done in the make file ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably could but it's much nicer to do it in bash vs Makefile. If we expand our profiling later I don't want to bloat these Makefiles There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I'm just not the biggest fan of adding scripts |
||
echo "Found packages:" | ||
echo "$packages" | ||
for pkg in $packages; do | ||
echo "Running tests in package: ${pkg}" | ||
go test \ | ||
-count 10 -timeout 3m \ | ||
-cpuprofile "${PROFILES_DIR}/$(basename $pkg)_watcher_cpu.pprof" \ | ||
"./${pkg}" || { echo "Tests failed in package: ${pkg}, but continuing..."; continue; } | ||
echo "Profile saved to: ${PROFILES_DIR}/$(basename $pkg)_watcher_cpu.pprof" | ||
done | ||
|
||
### Run integration tests with CPU profiling for each package | ||
aphralG marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#echo "Starting integration tests cpu profiling tests..." | ||
#packages=$(find test/integration -type f -name '*_test.go' -exec dirname {} \; | sort -u) | ||
#echo "Found packages:" | ||
#echo "$packages" | ||
#for pkg in $packages; do | ||
# echo "Running tests in package: ${pkg}" | ||
# go test \ | ||
# -count 3 -timeout 3m \ | ||
# -cpuprofile "${PROFILES_DIR}/$(basename $pkg)_integration_cpu.pprof" \ | ||
# "./${pkg}" || { echo "Tests failed in package: ${pkg}, but continuing..."; continue; } | ||
# echo "Profile saved to: ${PROFILES_DIR}/$(basename $pkg)_integration_cpu.pprof" | ||
#done | ||
|
||
## Merge all CPU profiles | ||
files=$(ls ${PROFILES_DIR}/*.pprof) | ||
echo "Merging CPU profiles: $files" | ||
go tool pprof -proto -output=${PROFILES_DIR}/merged.pprof $files | ||
echo "Merged CPU profile saved to: ${PROFILES_DIR}/merged.pprof" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
PROFILE=${PROFILE:-"false"} | ||
BENCHMARKS_DIR="/agent/performance/load" | ||
|
||
load_test() { | ||
echo "Running load tests..." | ||
pushd test/load | ||
go test -v -timeout 1m ./... | ||
cp benchmarks.json ${BENCHMARKS_DIR} | ||
cp -r results ${BENCHMARKS_DIR} | ||
popd | ||
} | ||
|
||
load_test_with_profile() { | ||
echo "Running load tests with CPU Profiling enabled..." | ||
pushd test/load | ||
go test -v -timeout 1m ./... \ | ||
-cpuprofile metrics_load_cpu.pprof | ||
cp benchmarks.json ${BENCHMARKS_DIR} | ||
cp -r results ${BENCHMARKS_DIR} | ||
cp *.pprof ${BENCHMARKS_DIR} | ||
popd | ||
} | ||
|
||
## Main script execution starts here | ||
mkdir -p ${BENCHMARKS_DIR} | ||
echo "Running in $(pwd)" | ||
if [[ "$PROFILE" == "true" ]]; then | ||
echo "CPU Profiling is enabled." | ||
load_test_with_profile || { echo "Load tests with cpu profiling failed"; exit 1; } | ||
else | ||
load_test || { echo "Load tests failed"; exit 1; } | ||
fi | ||
echo "Done." |
Uh oh!
There was an error while loading. Please reload this page.