11#! /bin/bash
22
3- # Script to run benchmarks for all Python SDK E2E instrumentation tests serially.
4- # Each instrumentation runs with BENCHMARKS=1, producing a comparison of
3+ # Script to run benchmarks for all Python SDK E2E instrumentation and stack tests serially.
4+ # Each test runs with BENCHMARKS=1, producing a comparison of
55# SDK disabled vs enabled (RECORD mode) with Go-style ns/op stats.
66#
7+ # Test types:
8+ # - Instrumentation: Single instrumentation benchmarks (e.g., flask, fastapi, django)
9+ # - Stack: Multi-instrumentation integration benchmarks (e.g., django-postgres, fastapi-postgres)
10+ #
711# Usage:
812# ./run-all-benchmarks.sh # Run all, 10s per endpoint
913# ./run-all-benchmarks.sh -d 20 # Run all, 20s per endpoint
1014# ./run-all-benchmarks.sh -f flask,fastapi # Run only flask and fastapi
15+ # ./run-all-benchmarks.sh --stack-only # Run only stack-test benchmarks
16+ # ./run-all-benchmarks.sh -f stack:django-postgres # Run a single stack benchmark
1117# ./run-all-benchmarks.sh -h # Show help
1218
1319set -e
1622BENCHMARK_DURATION=${BENCHMARK_DURATION:- 10}
1723BENCHMARK_WARMUP=${BENCHMARK_WARMUP:- 3}
1824FILTER=" "
25+ RUN_INSTRUMENTATION=true
26+ RUN_STACK=true
1927
2028# Colors for output
2129GREEN=' \033[0;32m'
@@ -27,13 +35,15 @@ NC='\033[0m' # No Color
2735usage () {
2836 echo " Usage: $0 [OPTIONS]"
2937 echo " "
30- echo " Run SDK benchmarks for all (or selected) instrumentations serially."
38+ echo " Run SDK benchmarks for all (or selected) instrumentations and stack tests serially."
3139 echo " "
3240 echo " Options:"
3341 echo " -d, --duration N Seconds per endpoint for timed loop (default: 10)"
3442 echo " -w, --warmup N Seconds of warmup per endpoint before timing (default: 3)"
35- echo " -f, --filter LIST Comma-separated list of instrumentations to benchmark"
36- echo " e.g. flask,fastapi,django"
43+ echo " -f, --filter LIST Comma-separated list of benchmarks to run"
44+ echo " e.g. flask,fastapi,stack:django-postgres"
45+ echo " --instrumentation-only Run only single-instrumentation benchmarks"
46+ echo " --stack-only Run only stack-test benchmarks"
3747 echo " -h, --help Show this help message"
3848 echo " "
3949 echo " Environment variables:"
@@ -42,10 +52,12 @@ usage() {
4252 echo " TUSK_CLI_VERSION CLI version to use in Docker builds"
4353 echo " "
4454 echo " Examples:"
45- echo " $0 # Benchmark all instrumentations"
55+ echo " $0 # Benchmark all instrumentations and stack tests "
4656 echo " $0 -d 20 # 20s per endpoint"
4757 echo " $0 -d 30 -w 5 # 30s timed, 5s warmup"
4858 echo " $0 -f flask,fastapi # Only benchmark flask and fastapi"
59+ echo " $0 --stack-only # Only benchmark stack tests"
60+ echo " $0 -f stack:django-postgres # Only benchmark django-postgres stack test"
4961}
5062
5163# Parse arguments
@@ -75,6 +87,16 @@ while [[ $# -gt 0 ]]; do
7587 FILTER=" $2 "
7688 shift 2
7789 ;;
90+ --instrumentation-only)
91+ RUN_INSTRUMENTATION=true
92+ RUN_STACK=false
93+ shift
94+ ;;
95+ --stack-only)
96+ RUN_INSTRUMENTATION=false
97+ RUN_STACK=true
98+ shift
99+ ;;
78100 -h|--help)
79101 usage
80102 exit 0
100122# Get the directory where this script is located (SDK root)
101123SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
102124
103- # Discover all e2e test run.sh scripts
104- ALL_SCRIPTS=($( find " $SCRIPT_DIR /drift/instrumentation" -path " */e2e-tests/run.sh" -type f | sort) )
125+ # Discover test scripts based on flags
126+ E2E_SCRIPTS=()
127+ STACK_SCRIPTS=()
128+
129+ if [ " $RUN_INSTRUMENTATION " = true ]; then
130+ E2E_SCRIPTS=($( find " $SCRIPT_DIR /drift/instrumentation" -path " */e2e-tests/run.sh" -type f | sort) )
131+ fi
132+
133+ if [ " $RUN_STACK " = true ]; then
134+ STACK_SCRIPTS=($( find " $SCRIPT_DIR /drift/stack-tests" -mindepth 2 -maxdepth 2 -name " run.sh" -type f 2> /dev/null | sort) )
135+ fi
136+
137+ ALL_SCRIPTS=(" ${E2E_SCRIPTS[@]} " " ${STACK_SCRIPTS[@]} " )
105138
106139if [ ${# ALL_SCRIPTS[@]} -eq 0 ]; then
107- echo -e " ${RED} No e2e test scripts found!${NC} "
140+ echo -e " ${RED} No benchmark scripts found!${NC} "
108141 exit 1
109142fi
110143
111- # Apply filter if provided
144+ # Extract names and apply filter
112145RUN_SCRIPTS=()
113146RUN_NAMES=()
114147for script in " ${ALL_SCRIPTS[@]} " ; do
115- NAME=$( echo " $script " | sed -E ' s|.*/instrumentation/([^/]+)/e2e-tests/run.sh|\1|' )
148+ if [[ " $script " == * " /stack-tests/" * ]]; then
149+ NAME=$( echo " $script " | sed -E ' s|.*/stack-tests/([^/]+)/run.sh|stack:\1|' )
150+ else
151+ NAME=$( echo " $script " | sed -E ' s|.*/instrumentation/([^/]+)/e2e-tests/run.sh|\1|' )
152+ fi
116153 if [ -n " $FILTER " ]; then
117154 # Check if NAME is in the comma-separated filter list
118155 if echo " ,$FILTER ," | grep -q " ,$NAME ," ; then
@@ -128,19 +165,28 @@ done
128165NUM_TESTS=${# RUN_SCRIPTS[@]}
129166
130167if [ $NUM_TESTS -eq 0 ]; then
131- echo -e " ${RED} No matching instrumentations found for filter: $FILTER ${NC} "
132- echo " Available: $( printf ' %s\n' " ${ALL_SCRIPTS[@]} " | sed -E ' s|.*/instrumentation/([^/]+)/e2e-tests/run.sh|\1|' | tr ' \n' ' ' ) "
168+ echo -e " ${RED} No matching benchmarks found for filter: $FILTER ${NC} "
169+ # Show all available names
170+ ALL_NAMES=()
171+ for script in " ${ALL_SCRIPTS[@]} " ; do
172+ if [[ " $script " == * " /stack-tests/" * ]]; then
173+ ALL_NAMES+=($( echo " $script " | sed -E ' s|.*/stack-tests/([^/]+)/run.sh|stack:\1|' ) )
174+ else
175+ ALL_NAMES+=($( echo " $script " | sed -E ' s|.*/instrumentation/([^/]+)/e2e-tests/run.sh|\1|' ) )
176+ fi
177+ done
178+ echo " Available: ${ALL_NAMES[*]} "
133179 exit 1
134180fi
135181
136182echo " "
137183echo -e " ${BLUE} ========================================${NC} "
138184echo -e " ${BLUE} Python SDK Benchmarks${NC} "
139185echo -e " ${BLUE} ========================================${NC} "
140- echo " Instrumentations : ${RUN_NAMES[*]} "
186+ echo " Benchmarks : ${RUN_NAMES[*]} "
141187echo " Warmup per endpoint: ${BENCHMARK_WARMUP} s"
142188echo " Duration per endpoint: ${BENCHMARK_DURATION} s"
143- echo " Total instrumentations : $NUM_TESTS "
189+ echo " Total benchmarks : $NUM_TESTS "
144190echo -e " ${BLUE} ========================================${NC} "
145191echo " "
146192
0 commit comments