|
1 | 1 | #!/bin/bash |
2 | 2 | # Profile test durations to diagnose slow tests (Issue #1633) |
3 | | -# Usage: ./scripts/profile_tests.sh [marker_filter] |
| 3 | +# |
| 4 | +# Usage: ./scripts/profile_tests.sh [options] |
| 5 | +# |
| 6 | +# Options: |
| 7 | +# -m MARKER Pytest marker filter (default: "not production_server and not test_server") |
| 8 | +# -d DURATION Number of slowest durations to show, 0 for all (default: 20) |
| 9 | +# -t TIMEOUT Per-test timeout in seconds (default: 300) |
| 10 | +# -o OUTPUT Output file path for the report (default: test_durations_report.txt) |
4 | 11 | # |
5 | 12 | # Examples: |
6 | | -# ./scripts/profile_tests.sh # non-server tests |
7 | | -# ./scripts/profile_tests.sh "production_server" # production server tests only |
8 | | -# ./scripts/profile_tests.sh "sklearn" # sklearn tests only |
| 13 | +# ./scripts/profile_tests.sh |
| 14 | +# ./scripts/profile_tests.sh -m "production_server" -d 0 -t 600 |
| 15 | +# ./scripts/profile_tests.sh -m "sklearn" -o sklearn_report.txt |
9 | 16 |
|
10 | 17 | set -euo pipefail |
11 | 18 |
|
12 | | -MARKER_FILTER="${1:-not production_server and not test_server}" |
| 19 | +# Default values |
| 20 | +MARKER_FILTER="not production_server and not test_server" |
| 21 | +DURATIONS=20 |
| 22 | +TIMEOUT=300 |
| 23 | +OUTPUT_FILE="test_durations_report.txt" |
| 24 | + |
| 25 | +# Parse command line arguments |
| 26 | +while getopts "m:d:t:o:" opt; do |
| 27 | + case $opt in |
| 28 | + m) MARKER_FILTER="$OPTARG" ;; |
| 29 | + d) DURATIONS="$OPTARG" ;; |
| 30 | + t) TIMEOUT="$OPTARG" ;; |
| 31 | + o) OUTPUT_FILE="$OPTARG" ;; |
| 32 | + *) echo "Usage: $0 [-m marker] [-d durations] [-t timeout] [-o output_file]" && exit 1 ;; |
| 33 | + esac |
| 34 | +done |
13 | 35 |
|
14 | 36 | echo "=== OpenML Test Duration Profiler ===" |
15 | 37 | echo "Marker filter: $MARKER_FILTER" |
16 | | -echo "Timeout per test: 300s" |
| 38 | +echo "Durations to show: $DURATIONS" |
| 39 | +echo "Timeout per test: ${TIMEOUT}s" |
| 40 | +echo "Output file: $OUTPUT_FILE" |
17 | 41 | echo "" |
18 | 42 |
|
19 | 43 | pytest \ |
20 | | - --durations=0 \ |
21 | | - --timeout=300 \ |
| 44 | + --durations="$DURATIONS" \ |
| 45 | + --timeout="$TIMEOUT" \ |
22 | 46 | -q \ |
23 | 47 | -m "$MARKER_FILTER" \ |
24 | | - 2>&1 | tee test_durations_report.txt |
| 48 | + 2>&1 | tee "$OUTPUT_FILE" |
25 | 49 |
|
26 | 50 | echo "" |
27 | | -echo "=== Report saved to test_durations_report.txt ===" |
| 51 | +echo "=== Report saved to $OUTPUT_FILE ===" |
0 commit comments