Repolode
plasma-umass

plasma-umass/scalene

A Python profiler that reports CPU, GPU, and memory usage per line, with optional AI-generated optimization suggestions.

Stars
13,551
Forks
445
Open issues
154
Last commit
6 days ago

What is it?

Scalene is a profiler for Python programs that measures CPU time, NVIDIA GPU time, and memory allocation at both the line and function level. It separates time spent in Python code from time spent in native code such as C/C++ libraries, and it also reports system time to help locate I/O bottlenecks. Scalene uses sampling rather than tracing, so its overhead is kept low compared with instrumenting profilers.

Beyond timing, Scalene tracks memory growth and copy volume, flags lines that likely leak memory, and supports async code by attributing time spent awaiting coroutines. Results can be viewed in a web GUI that works offline, in the terminal, or as a standalone HTML file. It can also be run from VS Code or Jupyter, and it supports free-threaded Python 3.13t and 3.14t.

Scalene can send profiled hotspots to AI providers such as OpenAI, Azure, Amazon Bedrock, or local Ollama models to propose code optimizations. These suggestions are generated on demand from the GUI and require you to supply your own credentials.

Key features

  • 01Reports CPU time split between Python code, native code, and system time per line.
  • 02Profiles NVIDIA GPU time and memory allocation, including per-line memory growth.
  • 03Detects likely memory leaks and measures copy volume between Python and libraries.
  • 04Attributes async await time per line along with concurrency levels.
  • 05Offers an offline web GUI, terminal output, and standalone HTML export.

Use cases

  • Finding which lines of a slow Python script consume the most CPU or memory.
  • Diagnosing whether a slowdown comes from Python code, native libraries, or I/O.
  • Tracking down memory leaks or unnecessary numpy-to-list conversions in data pipelines.
  • Profiling async services to see whether awaits are serialized or running concurrently.

Quick start

  1. 1

    Install Scalene with pip

    python3 -m pip install -U scalene
  2. 2

    Profile your program

    scalene run your_prog.py
  3. 3

    View the profile in your browser

    scalene view

Things to know

  • GPU profiling is currently limited to NVIDIA-based systems.
  • AI optimization suggestions require your own credentials for a provider such as OpenAI, Azure, Amazon Bedrock, or a local Ollama model.

In collections

Topics

#python#profiling#performance-analysis#memory-profiling#cpu-profiling#gpu#async#cpu#gpu-programming#memory-allocation

FAQ

What is scalene?
A Python profiler that reports CPU, GPU, and memory usage per line, with optional AI-generated optimization suggestions. Scalene is a profiler for Python programs that measures CPU time, NVIDIA GPU time, and memory allocation at both the line and function level. It separates time spent in Python code from time spent in native code such as C/C++ libraries, and it also reports system time to help locate I/O bottlenecks. Scalene uses sampling rather than tracing, so its overhead is kept low compared with instrumenting profilers.
Is scalene free to use? What license does it have?
scalene is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is scalene still maintained?
Actively maintained. The last commit to scalene was on Nov 1, 2026.
What can I use scalene for?
Finding which lines of a slow Python script consume the most CPU or memory. Diagnosing whether a slowdown comes from Python code, native libraries, or I/O. Tracking down memory leaks or unnecessary numpy-to-list conversions in data pipelines. Profiling async services to see whether awaits are serialized or running concurrently.
How do I install scalene?
Install Scalene with pip: python3 -m pip install -U scalene Profile your program: scalene run your_prog.py View the profile in your browser: scalene view
Where can I get scalene?
The source code and installation instructions are on GitHub: https://github.com/plasma-umass/scalene

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects