A flexible profiling utility for Python.
Project description
flexprofiler
:rocket: About
A flexible profiling utility for Python.
:package: Installation
pip install flexprofiler
:computer: Usage
A lightweight summary showing the most common ways to use flexprofiler.
Basic concepts:
@track()- decorate a function to collect call counts and timing statistics. Args:lines: boolean, collect per-line timing inside the function.
@track_all()- Decorate a class to profile all its methods. Args:max_depth: integer, how deep to recursively profile composed objects (default: 10).include: list of method names to track (default: None to track all).exclude: list of method names to skip (default: None to skip none).arg_sensitive: list of method names to track argument values (default: None).
stats()- print aggregated profiling statistics (function-level and, when enabled, line-level). Args:unit: the time unit to use for displaying statistics (default: "ms").
:arrow_down: Examples
1. Tracking a Simple Function
import time
from flexprofiler import stats, track
@track() # Use @track() decorator to profile the function
def simple_func():
time.sleep(0.1)
simple_func()
simple_func()
stats() # display the profiling statistics
output:
2. Tracking All Methods in a Class
import time
from flexprofiler import track_all, stats
@track_all() # Use @track_all() decorator to profile all methods in the class
class Foo:
def example_method(self):
self.another_method()
time.sleep(0.1)
def another_method(self):
time.sleep(0.2)
Foo().example_method()
Foo().another_method()
stats()
output:
3. Tracking All Methods in a Class Recursively
import time
from flexprofiler import track_all, stats
@track_all(max_depth=3)
class Foo:
def __init__(self):
self.sub_class = Bar()
def example_method(self):
self.another_method()
time.sleep(0.1)
def another_method(self):
time.sleep(0.2)
def calling_subclass_method(self):
for i in range(3):
self.sub_class.subclass_method_1()
self.sub_class.subclass_method_2()
self.sub_class.subclass_method_3()
class Bar:
def subclass_method_1(self):
time.sleep(0.05)
def subclass_method_2(self):
self.a()
self.b()
def subclass_method_3(self):
self.a()
self.b()
def a(self):
time.sleep(0.02)
def b(self):
time.sleep(0.01)
obj = Foo()
obj.example_method()
obj.calling_subclass_method()
stats()
output:
4. Track All lines in a function
import time
from flexprofiler import track, stats
@track(lines=True) # with line tracking
def bar(n):
total = 0
for i in range(n):
total += i
if i % 2 == 0:
time.sleep(0.001)
else:
time.sleep(0.0005)
return total
@track() # no line tracking
def baz():
time.sleep(0.1)
@track() # no line tracking
def foo():
for _ in range(3):
bar(50)
baz()
foo()
stats() # display the profiling statistics
outputs:
:handshake: Feedback and Contributions
Contributions, suggestions, and feedback are welcome! Feel free to open issues or submit pull requests on GitHub.
Author
Arthur Bucker (abucker@andrew.cmu.edu)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexprofiler-0.1.2.tar.gz.
File metadata
- Download URL: flexprofiler-0.1.2.tar.gz
- Upload date:
- Size: 411.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a045a68966595ec41d0485be107aeec90c2c3a49e6a21d5d3e37fb956cf8f2e6
|
|
| MD5 |
5f5b05e21e48bdda719e892b312a9932
|
|
| BLAKE2b-256 |
c637e1f30aebb19a6833807aee9aaecefc7139cd42eaf3f8cfea28e5800d2913
|
File details
Details for the file flexprofiler-0.1.2-py3-none-any.whl.
File metadata
- Download URL: flexprofiler-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da238900200450fd0333e50dc072ef42c9ff52ccfd17b7d55ed36c06c4c89e98
|
|
| MD5 |
e05b83b8650ef886fa83a9e380ffbe1f
|
|
| BLAKE2b-256 |
77b5cead6c131087054a8d8bde36bc264b4d96cb9d3f4a40fe33691cc478488f
|