Skip to main content

Scalene: A high-resolution, low-overhead CPU and memory profiler for Python

Project description

scalene

scalene: a high-performance CPU and memory profiler for Python

by Emery Berger


About Scalene

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.

  1. Scalene is fast. It uses sampling instead of instrumentation or relying on Python's tracing facilities.
  2. 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.
  3. 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.

Installation

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.

Usage

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 make:

  % make

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

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scalene-0.4.0.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

scalene-0.4.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page