Profile Python agent workloads with Scalene
Use Scalene when a Python agent, tool server, or retrieval pipeline needs line-level CPU, GPU, and memory profiling before targeted optimization.
Prerequisites
Python project or script that reproduces the workload; Scalene CLI; local or staging permission to run profiling
Installation
Use the upstream install or setup path that matches your environment:
- conda install -c conda-forge scalene
Requirements and caveats from upstream:
- (tweet from Ian Ozsvald, author of High Performance Python)
- Python Profiler Links to AI to Improve Code Scalene identifies inefficiencies and asks GPT-4 for suggestions, IEEE Spectrum
- Episode 172: Measuring Multiple Facets of Python Performance With Scalene, The Real Python podcast
Basic usage or getting-started notes:
python3 -m pip install -U scalene
Extracted from upstream docs: https://raw.githubusercontent.com/plasma-umass/scalene/HEAD/README.md