Skip to main content

Simple Python decorator to dump cProfile stats

Project description

dull

This is a plain and boring package providing one decorator for dumping profile stats to console or to a file for further inspections.

There are a million of nice packages providing decorators and context managers that can dump cProfile stats and generate visual stuff from them. But usually that is a little too much for just taking a peek at performance of a function. I found myself writing this wrapper again and again or copypasting it around, so why not package it for convenience?

Install with pip:

pip install dull

Wrap a function with profiler:

from dull import profile


@profile()
def foo():
    print("well hello")


print("hello there")
foo()
print("goodbye")

Output:

hello there
well hello
---------------------------------------profile foo---------------------------------------
         3 function calls in 0.000 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 joku.py:4(foo)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.print}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}


-----------------------------------------------------------------------------------------
goodbye

Dump profile to file:

@profile(to_file=True)  # output defaults to profile/foo.dat
def foo():
    print("well hello")

Output:

hello there
well hello
--------------------------foo: profile saved to profile/foo.dat--------------------------
goodbye

Files are plain pstat dumps, get fancy with snakeviz or similar visualizers:

snakeviz profile/foo.dat

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

dull-1.0.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

dull-1.0.0-py3-none-any.whl (2.6 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