profilehooks
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.13.0 (2024-10-09)
Add support for Python 3.9, 3.10, 3.11, 3.12, and 3.13.
Drop support for Python 2.7, 3.5 and 3.6.
Drop support for hotshot (which was only available for Python 2.7).
1.12.0 (2020-08-20)
Added the ability to pass a text-mode file object to the stdout kwarg of the @profile() decorator and FuncProfiler() constructor for capturing output: https://github.com/mgedmin/profilehooks/pull/26.
1.11.2 (2020-03-03)
Fix breakage with @functools.lru_cache(): https://github.com/mgedmin/profilehooks/issues/25.
Use @functools.wraps() so decorated functions now correctly set the __wrapped__ attribute.
1.11.1 (2020-01-30)
Add support for Python 3.8.
Detect Python source file encoding correctly in @coverage. https://github.com/mgedmin/profilehooks/issues/24.
1.11.0 (2019-04-23)
New options: @timecall(log_name='logger', log_level=DEBUG). https://github.com/mgedmin/profilehooks/pull/20.
Add Python 3.7 support.
Drop Python 3.3 and 3.4 support.
1.10.0 (2017-12-09)
@timecall() now defaults to the highest-precision timer (timeit.default_timer()) instead of time.time(): https://github.com/mgedmin/profilehooks/pull/11
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)
Include PID in temporary filenames: https://github.com/mgedmin/profilehooks/issues/6.
Claim Python 3.5 compatibility.
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)
Explicitly claim Python 3.3 compatibility.
Fix Python 3.x bug with @coverage (stop using sys.maxint): https://github.com/mgedmin/profilehooks/issues/2.
1.6 (2012-06-05)
Added Python 3.2 compatibility, dropped Python 2.3, 2.4 and 2.5 compatibility.
Migrated the source repository to https://github.com/mgedmin/profilehooks
Added a changelog.
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
Metadata
Release files for profilehooks 1.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| profilehooks-1.13.0.tar.gz | 17.7 kB | Without provenance | Details for profilehooks-1.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| profilehooks-1.13.0-py3-none-any.whl | Python 3 | none | any | Details for profilehooks-1.13.0-py3-none-any.whl |
Total release size: 28.5 kB
Release files / profilehooks-1.13.0.tar.gz
| Download URL | profilehooks-1.13.0.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54a541cad49ddccee97b61a617404d7d736bf0bf79d36fbe2ac7caa3a1d9daaf
|
|
BLAKE2b-256 checksum How to use checksums |
185ac69fdf542b730c74b9de1cc2cc02692cd5d6a34a9d95e29217262937f91e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / profilehooks-1.13.0-py3-none-any.whl
| Download URL | profilehooks-1.13.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
869f63862b3d85e8af44ad7eb01a00203cc7a27a376ed3a51e409399062659c6
|
|
BLAKE2b-256 checksum How to use checksums |
bc281c526d6cdbeb56aec99c5ec3920ffd7c5b002dbbafb387ebfb33678a1b95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Security for profilehooks 1.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.