Scalene: A high-resolution, low-overhead CPU and memory profiler for Python
scalene: a high-performance CPU and memory profiler for Python
by Emery Berger
Scalene is a high-performance CPU and memory profiler for Python that does a few things that other Python profilers do not and cannot do.
- Scalene is fast. It uses sampling instead of instrumentation or relying on Python's tracing facilities.
- Scalene is precise. Unlike most other Python profilers, Scalene performs CPU profiling at the line level, pointing to the specific lines of code that are responsible for the execution time in your program. This level of detail can be much more useful information than the function-level profiles returned by most profilers.
- Scalene profiles memory usage. In addition to tracking CPU usage, Scalene also points to the specific lines of code responsible for memory growth. It accomplishes this via an included specialized memory allocator.
Scalene is distributed as a pip package. You can install it as follows:
% pip install scalene
NOTE: Currently, installing Scalene in this way does not install its memory profiling library, so you will only be able to use it to perform CPU profiling. To take advantage of its memory profiling capability, you will need to download this repository.
The following command will run Scalene to only perform line-level CPU profiling on a provided example program.
% python -m scalene test/testme.py
To perform both line-level CPU and memory profiling, you first need to build the specialized memory allocator by running
Profiling on a Mac OS X system:
% DYLD_INSERT_LIBRARIES=$PWD/libscalene.dylib PYTHONMALLOC=malloc python -m scalene test/testme.py
Profiling on a Linux system:
% LD_PRELOAD=$PWD/libscalene.so PYTHONMALLOC=malloc python -m scalene test/testme.py
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size scalene-0.5.1-py3-none-any.whl (9.8 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size scalene-0.5.1.tar.gz (5.5 kB)||File type Source||Python version None||Upload date||Hashes View hashes|