Scalene profiles Python programs at line and function granularity for CPU, GPU, and memory, with a local web GUI and optional AI-suggested optimizations from several providers.
Overview
Scalene is a profiler for Python that separates time spent in Python, native libraries, system calls, and on NVIDIA GPUs when available. It uses sampling rather than heavy instrumentation so overhead stays comparatively low while still reporting detailed per-line figures.
The tool highlights hotspots in the report, tracks memory allocation and copying volume per line, flags likely leaks, and attributes async await time to the lines where coroutines suspend. Optional stack views stitch Python and native frames into flame charts, memory-weighted charts, and a timeline with GC, I/O, and GIL markers.
After a run, Scalene can open an interactive browser UI that works fully offline, with sorting, hover breakdowns, and standalone HTML export for sharing. A Visual Studio Code extension runs profiling from the editor command palette and shows results in a webview.
The command-line interface uses run, view, and config verbs, supports YAML configuration files, @profile decorators, pytest integration, and optional AI optimization suggestions when you configure keys for providers such as OpenAI, Azure, Bedrock, or local Ollama models.
Key features
- Per-line CPU profiling
- Python vs native vs system time
- GPU time on NVIDIA systems
- Per-line memory and copy volume
- Async await attribution
- Stitched Python and native stacks
- Offline web GUI
- AI optimization suggestions
Use cases
- Finding Python performance bottlenecks
- Debugging memory growth and leaks
- Profiling async I/O concurrency
- Sharing standalone profile HTML reports