Skip to main content

A small utility library that wraps cProfile and makes it easy to debug performance problems in your Python code.

Project description

Profiling Helpers

A small python package that wraps Python's own cProfile library to make it more user friendly.

When developing Python programs, you'll sometimes have functions that take a long time to execute and you are really not sure why. Profiling helps to find and analyze these bottlenecks and guides you into fixing performance problems. Uses snakeviz for interactive visualizations.

Install it with pip install profiling-helpers. Visualize profile files with snakeviz profile_xyz.prof.

There are two decorators, time_it and profile_it. Use them anywhere in your code, like this:

from profiling_helpers import time_it, profile_it
from time import sleep

@time_it
def my_slow_function(x):
    sleep(10)
    return x

my_slow_function(42)  # Prints: Function "my_slow_function" took 10.01061 s to run
@profile_it("my/profile/save/dir", open_visualization=True)
def my_slow_function(x):
    sleep(10)
    return x

my_slow_function(42)  # Opens snakeviz after this function is completed

Profiles are normally saved on the local file system. If you have other save targets, you can either use included FileSavers (currently only for AWS S3) or implement your own one by inheriting from the BaseFileSaver class. Here is a variant with S3:

from profiling_helpers import profile_it, S3FileSaver

@profile_it(S3FileSaver("s3://my-bucket/my/path/to/profiles/", kms_key_id="..."))
def my_slow_function(x):
    sleep(10)
    return x

my_slow_function(42)

Project details


Download files

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

Source Distribution

profiling-helpers-0.2.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

profiling_helpers-0.2.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file profiling-helpers-0.2.0.tar.gz.

File metadata

  • Download URL: profiling-helpers-0.2.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for profiling-helpers-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fcc86e80d7ca9f3fbdd8f208cd69758f34a385809b18d91413919a192647b348
MD5 509980852ee375bd92eb563e32b7a29d
BLAKE2b-256 d41c9c14f1b52cb252ce6754fb687b225dcce0935bad918ac7a491f9568cbbf0

See more details on using hashes here.

File details

Details for the file profiling_helpers-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for profiling_helpers-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 05a21a978a2c698e3c01aa4ff1329b64c5537a9308e670e4efe04ad516ebcd73
MD5 84d59e33987f1ddd1decdfff0cebc75f
BLAKE2b-256 acb27b2d9ff7ba8bf93d99a6fe17ac0cb8e8841f6e423989d5e9188934bd1ef8

See more details on using hashes here.

Supported by

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