|
| 1 | +# E2E Profiling Tools |
| 2 | + |
| 3 | +Automated profiling and analysis for operator-controller e2e tests. Collect heap and CPU profiles during test runs, analyze memory usage patterns, and compare optimizations. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### Simple Start/Stop Workflow |
| 8 | + |
| 9 | +```bash |
| 10 | +# Start profiling (auto-generated name or specify custom name) |
| 11 | +make start-profiling |
| 12 | +make start-profiling/baseline |
| 13 | + |
| 14 | +# Run your tests |
| 15 | +make test-e2e |
| 16 | + |
| 17 | +# Stop and analyze |
| 18 | +make stop-profiling |
| 19 | +``` |
| 20 | + |
| 21 | +The profiler: |
| 22 | +- Waits for cluster components to be ready |
| 23 | +- Collects profiles every 10 seconds (configurable) |
| 24 | +- Handles cluster teardown automatically |
| 25 | +- Generates analysis reports |
| 26 | + |
| 27 | +### Automated Test Runner |
| 28 | + |
| 29 | +```bash |
| 30 | +# Run baseline |
| 31 | +./hack/tools/e2e-profiling/e2e-profile.sh run baseline |
| 32 | + |
| 33 | +# Make changes, then run optimized version |
| 34 | +./hack/tools/e2e-profiling/e2e-profile.sh run optimized |
| 35 | + |
| 36 | +# Compare results |
| 37 | +./hack/tools/e2e-profiling/e2e-profile.sh compare baseline optimized |
| 38 | +``` |
| 39 | + |
| 40 | +View reports: |
| 41 | +```bash |
| 42 | +cat e2e-profiles/baseline/analysis.md |
| 43 | +cat e2e-profiles/comparisons/baseline-vs-optimized.md |
| 44 | +``` |
| 45 | + |
| 46 | +## Commands |
| 47 | + |
| 48 | +### `run <name> [test-target]` |
| 49 | +Run e2e test with profiling. |
| 50 | + |
| 51 | +```bash |
| 52 | +./hack/tools/e2e-profiling/e2e-profile.sh run my-test [test-e2e|test-experimental-e2e|...] |
| 53 | +``` |
| 54 | + |
| 55 | +Output: |
| 56 | +- `e2e-profiles/<name>/operator-controller/*.pprof` - Profile snapshots |
| 57 | +- `e2e-profiles/<name>/catalogd/*.pprof` - Catalogd profiles |
| 58 | +- `e2e-profiles/<name>/analysis.md` - Analysis report |
| 59 | + |
| 60 | +### `analyze <name>` |
| 61 | +Analyze collected profiles. |
| 62 | + |
| 63 | +```bash |
| 64 | +./hack/tools/e2e-profiling/e2e-profile.sh analyze my-test |
| 65 | +``` |
| 66 | + |
| 67 | +### `compare <test1> <test2>` |
| 68 | +Compare two test runs. |
| 69 | + |
| 70 | +```bash |
| 71 | +./hack/tools/e2e-profiling/e2e-profile.sh compare baseline optimized |
| 72 | +``` |
| 73 | + |
| 74 | +Output: `e2e-profiles/comparisons/<test1>-vs-<test2>.md` |
| 75 | + |
| 76 | +### `collect` |
| 77 | +Manually collect a single heap profile. |
| 78 | + |
| 79 | +```bash |
| 80 | +./hack/tools/e2e-profiling/e2e-profile.sh collect |
| 81 | +``` |
| 82 | + |
| 83 | +## Configuration |
| 84 | + |
| 85 | +```bash |
| 86 | +# Namespace (default: olmv1-system) |
| 87 | +export E2E_PROFILE_NAMESPACE=olmv1-system |
| 88 | + |
| 89 | +# Collection interval in seconds (default: 10) |
| 90 | +export E2E_PROFILE_INTERVAL=10 |
| 91 | + |
| 92 | +# CPU profiling duration in seconds (default: 10) |
| 93 | +export E2E_PROFILE_CPU_DURATION=10 |
| 94 | + |
| 95 | +# Profile mode: both, heap, cpu (default: both) |
| 96 | +export E2E_PROFILE_MODE=both |
| 97 | + |
| 98 | +# Output directory (default: ./e2e-profiles) |
| 99 | +export E2E_PROFILE_DIR=./e2e-profiles |
| 100 | + |
| 101 | +# Test target (default: test-experimental-e2e) |
| 102 | +export E2E_PROFILE_TEST_TARGET=test-experimental-e2e |
| 103 | +``` |
| 104 | + |
| 105 | +**Note:** If `CPU_DURATION >= INTERVAL`, CPU profiling runs continuously. |
| 106 | + |
| 107 | +## Output Structure |
| 108 | + |
| 109 | +``` |
| 110 | +e2e-profiles/ |
| 111 | +├── baseline/ |
| 112 | +│ ├── operator-controller/ |
| 113 | +│ │ ├── heap*.pprof # Heap snapshots |
| 114 | +│ │ └── cpu*.pprof # CPU profiles |
| 115 | +│ ├── catalogd/ |
| 116 | +│ │ ├── heap*.pprof |
| 117 | +│ │ └── cpu*.pprof |
| 118 | +│ ├── test.log |
| 119 | +│ ├── collection.log |
| 120 | +│ └── analysis.md |
| 121 | +└── comparisons/ |
| 122 | + └── baseline-vs-optimized.md |
| 123 | +``` |
| 124 | + |
| 125 | +## Examples |
| 126 | + |
| 127 | +### Profile Optimization |
| 128 | + |
| 129 | +```bash |
| 130 | +# Baseline |
| 131 | +make start-profiling/baseline |
| 132 | +make test-e2e |
| 133 | +make stop-profiling |
| 134 | + |
| 135 | +# Implement changes, then profile optimized version |
| 136 | +make start-profiling/optimized |
| 137 | +make test-e2e |
| 138 | +make stop-profiling |
| 139 | + |
| 140 | +# Compare |
| 141 | +./hack/tools/e2e-profiling/e2e-profile.sh compare baseline optimized |
| 142 | +``` |
| 143 | + |
| 144 | +### Heap-Only Profiling |
| 145 | + |
| 146 | +```bash |
| 147 | +# Reduced overhead for memory-focused analysis |
| 148 | +E2E_PROFILE_MODE=heap make start-profiling/memory-test |
| 149 | +make test-e2e |
| 150 | +make stop-profiling |
| 151 | +``` |
| 152 | + |
| 153 | +### Different Test Suites |
| 154 | + |
| 155 | +```bash |
| 156 | +./hack/tools/e2e-profiling/e2e-profile.sh run standard test-e2e |
| 157 | +./hack/tools/e2e-profiling/e2e-profile.sh run upgrade test-upgrade-e2e |
| 158 | +./hack/tools/e2e-profiling/e2e-profile.sh compare standard upgrade |
| 159 | +``` |
| 160 | + |
| 161 | +## Interactive Analysis |
| 162 | + |
| 163 | +```bash |
| 164 | +cd e2e-profiles/my-test/operator-controller |
| 165 | + |
| 166 | +# Top allocators |
| 167 | +go tool pprof -top heap23.pprof |
| 168 | + |
| 169 | +# Interactive mode |
| 170 | +go tool pprof heap23.pprof |
| 171 | +# Commands: top, list, web, pdf |
| 172 | + |
| 173 | +# Compare snapshots |
| 174 | +go tool pprof -base=heap0.pprof -top heap23.pprof |
| 175 | + |
| 176 | +# Filter specific patterns |
| 177 | +go tool pprof -text heap23.pprof | grep -i openapi |
| 178 | +``` |
| 179 | + |
| 180 | +## Troubleshooting |
| 181 | + |
| 182 | +**No profiles collected:** |
| 183 | +- Check deployment is ready: `kubectl get deployment -n olmv1-system` |
| 184 | +- Verify pprof endpoint: `curl http://localhost:6060/debug/pprof/` |
| 185 | +- Review `collection.log` for connection errors |
| 186 | + |
| 187 | +**Test exits early:** |
| 188 | +- Run test manually first to verify it works |
| 189 | +- Check `test.log` for errors |
| 190 | + |
| 191 | +**Analysis fails:** |
| 192 | +- Verify files exist: `find e2e-profiles -name "*.pprof"` |
| 193 | +- Check `go tool pprof --help` works |
| 194 | + |
| 195 | +**Port-forward issues:** |
| 196 | +- Test manually: `kubectl port-forward -n olmv1-system deployment/operator-controller-controller-manager 6060:6060` |
| 197 | +- Kill stuck processes: `pkill -f "kubectl port-forward.*6060"` |
| 198 | + |
| 199 | +## Requirements |
| 200 | + |
| 201 | +- kubectl (cluster access) |
| 202 | +- go (for `go tool pprof`) |
| 203 | +- make |
| 204 | +- curl |
| 205 | +- bash 4.0+ |
| 206 | + |
| 207 | +## Real-World Results |
| 208 | + |
| 209 | +OpenAPI caching optimization: |
| 210 | +- **Memory:** 49.6 MB → 41.2 MB (-16.9%) |
| 211 | +- **OpenAPI allocations:** 13 MB → 3.5 MB (-73%) |
| 212 | +- **Key insight:** Repeated schema fetching was #1 memory consumer |
| 213 | + |
| 214 | +## Architecture |
| 215 | + |
| 216 | +**Scripts:** |
| 217 | +- `profile-collector-daemon.sh` - Background collection process |
| 218 | +- `start-profiling.sh` - Start daemon mode profiling |
| 219 | +- `stop-profiling.sh` - Stop daemon and cleanup |
| 220 | +- `run-profiled-test.sh` - Orchestrate test + profiling |
| 221 | +- `analyze-profiles.sh` - Generate analysis reports |
| 222 | +- `compare-profiles.sh` - Create comparison reports |
| 223 | +- `common.sh` - Shared utilities and logging |
| 224 | + |
| 225 | +**Key Features:** |
| 226 | +- Deployment-based port-forwarding (survives pod restarts) |
| 227 | +- Automatic retry with 30s timeout |
| 228 | +- Graceful cleanup on exit/interrupt |
| 229 | +- Multi-component support (operator-controller + catalogd) |
| 230 | + |
| 231 | +## See Also |
| 232 | + |
| 233 | +- [Go pprof documentation](https://pkg.go.dev/net/http/pprof) |
| 234 | +- [Profiling Go Programs](https://go.dev/blog/pprof) |
0 commit comments