Skip to main content

Decorators for profiling/timing/tracing individual functions

Project description

profilehooks

https://travis-ci.org/mgedmin/profilehooks.svg?branch=master https://ci.appveyor.com/api/projects/status/github/mgedmin/profilehooks?branch=master&svg=true https://coveralls.io/repos/mgedmin/profilehooks/badge.svg?branch=master

It’s a collection of decorators for profiling functions. E.g. to profile a single function:

from profilehooks import profile

@profile
def my_function(args, etc):
    pass

The results will be printed when the program exits (or you can use @profile(immediate=True)).

If you’re interested in coarse timings and don’t want to pay for the overhead of profiling, use

from profilehooks import timecall

@timecall       # or @timecall(immediate=True)
def my_function(args, etc):
    pass

Finally, you may be interested in seeing line coverage for a single function

from profilehooks import coverage

@coverage
def my_function(args, etc):
    pass

Also functions can be available in Python console or module if run it with -m arg

$ python -m profilehooks
>>> profile
<function profile at 0x1005c6488>

$ python -m profilehooks yourmodule

Full documentation is available through pydoc profilehooks after installation.

The home page for this module is https://mg.pov.lt/profilehooks. It has screensho, uh, that is, more examples.

Changelog

1.12.0 (2020-08-20)

1.11.2 (2020-03-03)

1.11.1 (2020-01-30)

1.11.0 (2019-04-23)

1.10.0 (2017-12-09)

1.9.0 (2017-01-02)

  • Drop claim of Python 3.2 compatibility. Everything still works, except I’m no longer running automated tests on 3.2, so things might regress.

  • Drop Python 2.6 compatibility.

  • Add Python 3.6 compatibility.

1.8.1 (2015-11-21)

1.8.0 (2015-03-25)

  • New option: @profile(stdout=False) to suppress output to sys.stdout.

1.7.1 (2014-12-02)

  • Make @profile(profiler='hotshot') work again. This was probably broken in 1.0 or 1.1, but nobody complained.

  • Fix missing space in the output of @profile(skip=N).

  • Make @coverage_with_hotshot output match @coverage output precisely.

  • 100% test coverage.

  • Claim Python 3.4 and PyPy compatibility.

1.7 (2013-10-16)

1.6 (2012-06-05)

1.5 (2010-08-13)

  • New argument to @timecall: timer (defaults to time.time). Example: @timecall(timer=time.clock)

  • Better documentation.

1.4 (2009-03-31)

  • Added support for cProfile, make it the default profiler when available. Previously profilehooks supported profile and hotshot only.

1.3 (2008-06-10)

  • Store profile results (when you pass filename to @profile) in pstats format instead of pickles. Contributed by Florian Schulze.

1.2 (2008-03-07)

  • New argument to: @timecall: immediate (defaults to False).

  • Added a test suite.

1.1 (2007-11-07)

  • First release to PyPI, with a setup.py and everything.

  • New arguments to @profile: dirs, sort, entries. Contributed by Hanno Schlichting.

  • Preserve function attributes such as __doc__ and __module__ when decorating them.

  • Pydoc-friendly docstring wrapping and other docstring improvements.

1.0 (2006-12-06)

  • Changed licence from GPL to MIT.

  • New decorator: @timecall

  • New arguments to @profile: skip, filename, immediate.

  • Added support for profile, after becoming convinced hotshot was unreliable. Made it the default profiler.

0.1 (2004-12-30)

  • First public release (it didn’t actually have a version number), announced on my blog: https://mg.pov.lt/blog/profiling.html

  • @profile and @coverage decorators that didn’t accept any arguments.

  • hotshot was the only profiler supported for @profile, while @coverage used trace.py

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

profilehooks-1.12.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

profilehooks-1.12.0-py2.py3-none-any.whl (12.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file profilehooks-1.12.0.tar.gz.

File metadata

  • Download URL: profilehooks-1.12.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for profilehooks-1.12.0.tar.gz
Algorithm Hash digest
SHA256 05b87589df8a8c630fd701bae6008cc1cfff4457bd0064887ad25248327a5ba3
MD5 74af869dffe22c9443186bc71e8295a0
BLAKE2b-256 f77325ef2a50d78a463297228e85e0b1e34099a774c54ec169c21b1f5e5152c6

See more details on using hashes here.

File details

Details for the file profilehooks-1.12.0-py2.py3-none-any.whl.

File metadata

  • Download URL: profilehooks-1.12.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for profilehooks-1.12.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dc87f319c9596b8c50fd374e3c08c51fa29a61553f1d9281482e4ca31829b021
MD5 5965a1d20459bbcfd77d97dbd3e345ae
BLAKE2b-256 118d6b2f22d7b41b5dfcad388c08f337ea299ae6863737083888e9e3bd94273b

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