11#! /usr/bin/env bash
22
3- # This script runs Go tests with CPU profiling enabled for all test packages in the test/integration directory.
4- # It saves the CPU profiles in the profiles directory with the format <package-name>_<test_type>.pprof
5- # Usage: ./scripts/performance/profiling.sh
6- #
7- # Variables:
8- # - TEST_ENV: The test environment (default: "local")
9- # - CONTAINER_OS_TYPE: The container OS type (default: "linux")
10- # - BUILD_TARGET: The build target (default: "agent")
11- # - PACKAGES_REPO: The packages repository (default: "packages.nginx.org")
12- # - PACKAGE_NAME: The package name (default: "nginx-agent
13- # - BASE_IMAGE: The base image (default: "ubuntu")
14- # - OS_VERSION: The OS version (default: "20.04")
15- # - OS_RELEASE: The OS release (default: "focal")
16- # - DOCKERFILE_PATH: The Dockerfile path (default: "Dockerfile")
17- # - IMAGE_PATH: The image path (default: "nginxinc/nginx-agent")
18- # - TAG: The image tag (default: "latest")
19- # - CONTAINER_NGINX_IMAGE_REGISTRY: The container registry (default: "docker.io")
20- # Example:
21- # 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
22-
23- # # Print all variables in the environment
24- # echo "TEST_ENV=$TEST_ENV"
25- # echo "CONTAINER_OS_TYPE=$CONTAINER_OS_TYPE"
26- # echo "BUILD_TARGET=$BUILD_TARGET"
27- # echo "PACKAGES_REPO=$PACKAGES_REPO"
28- # echo "PACKAGE_NAME=$PACKAGE_NAME"
29- # echo "BASE_IMAGE=$BASE_IMAGE"
30- # echo "OS_VERSION=$OS_VERSION"
31- # echo "OS_RELEASE=$OS_RELEASE"
32- # echo "DOCKERFILE_PATH=$DOCKERFILE_PATH"
33- # echo "IMAGE_PATH=$IMAGE_PATH"
34- # echo "TAG=$TAG"
35- # echo "CONTAINER_NGINX_IMAGE_REGISTRY=$CONTAINER_NGINX_IMAGE_REGISTRY"
3+ # This script runs Go tests with CPU profiling enabled for all test packages found under the directories:
4+ # - internal/watcher
5+ # - test/integration
6+ # It saves the CPU profiles in the $PROFILES_DIR directory with the format <package-name>_<test_type>.pprof
7+ # e.g. <package-name>_watcher_cpu.pprof or <package-name>_integration_cpu.pprof
8+
9+ # The variables below can be set to customize the environment for the integration tests:
10+ # Example using variables defined in our Makefile:
11+ # TEST_ENV=ci CONTAINER_OS_TYPE=linux BUILD_TARGET=agent PACKAGES_REPO=nginxinc \
12+ # PACKAGE_NAME=nginx-agent BASE_IMAGE=ubuntu OS_VERSION=20.04 OS_RELEASE=focal \
13+ # DOCKERFILE_PATH=Dockerfile IMAGE_PATH=nginxinc/nginx-agent TAG=latest CONTAINER_NGINX_IMAGE_REGISTRY=docker.io \
14+ # ./scripts/performance/profiling.sh
3615
3716set -e
3817set -o pipefail
@@ -48,7 +27,7 @@ echo "$packages"
4827for pkg in $packages ; do
4928 echo " Running tests in package: ${pkg} "
5029 go test \
51- -count 10 -timeout 1m \
30+ -count 10 -timeout 3m \
5231 -cpuprofile " ${PROFILES_DIR} /$( basename $pkg ) _watcher_cpu.pprof" \
5332 " ./${pkg} " || { echo " Tests failed in package: ${pkg} , but continuing..." ; continue ; }
5433 echo " Profile saved to: ${PROFILES_DIR} /$( basename $pkg ) _watcher_cpu.pprof"
@@ -62,18 +41,14 @@ echo "$packages"
6241for pkg in $packages ; do
6342 echo " Running tests in package: ${pkg} "
6443 go test -v \
65- -count 3 -timeout 1m \
66- -cpuprofile " profiles /$( basename $pkg ) _integration_cpu.pprof" \
44+ -count 3 -timeout 3m \
45+ -cpuprofile " ${PROFILES_DIR} /$( basename $pkg ) _integration_cpu.pprof" \
6746 " ./${pkg} " || { echo " Tests failed in package: ${pkg} , but continuing..." ; continue ; }
68- mv $( basename $pkg ) .test profiles/$( basename $pkg ) _integration_cpu.test
69- echo " Profile saved to: profiles/${profile_name} "
47+ echo " Profile saved to: ${PROFILES_DIR} /$( basename $pkg ) _integration_cpu.pprof"
7048done
7149
7250# # Merge all CPU profiles
7351files=$( ls ${PROFILES_DIR} /* .pprof)
7452echo " Merging CPU profiles: $files "
7553go tool pprof -proto -output=${PROFILES_DIR} /merged.pgo $files
76- echo " Merged CPU profile saved to: default.pgo"
77-
78- # # Cleanup
79- rm * .pprof
54+ echo " Merged CPU profile saved to: ${PROFILES_DIR} /merged.pgo"
0 commit comments