Easily profile time taken for methods to complete.
Project description
timeprofiles
This library is designed to assist in quickly debugging bottlenecks in both single-threaded and multi-threaded operations.
Installation
python -m pip install timeprofiles
Overview
It contains a class called TimeProfileCollection for easily storing the time taken for each method to complete, and displaying it as either a table or a diagram. The TimeProfiler class provides two decorator methods for profiling: one for profiling the entire class, and one for profiling individual methods.
@timeprofiles.profile_class_methods
@timeprofiles.profile_method
The display_profiles method is used to display all time profiles, ordered by a specified column.
Name Calls Average (ms) Longest (ms) Bottleneck (ms)
-------- ------- -------------- -------------- -----------------
method_a 1 203.50 203.50 203.50
method_b 5 104.82 155.19 155.40
method_c 5 58.86 78.35 140.00
method_d 1 45.83 45.83 45.83
method_e 1 93.76 93.76 93.76
The plot_profiles and plot_merged methods are used to plot all time profiles as ranges, ordered by earliest method call.
Example usages
The profile_method decorator is applied on individual methods or functions.
import timeprofiles as tp
class ExampleClass:
@tp.profile_method
def my_method():
# Method content
@tp.profile_method
def my_other_method():
# Method content
Alternatively, the profile_class_methods decorator can be used to apply the profile_method decorator on all class methods. This can be used in conjunction with profile_ignore to filter out methods you don't want to profile.
import timeprofiles as tp
@tp.profile_class_methods
class ExampleClass:
def my_method():
# Method content
@tp.profile_ignore
def my_other_method():
# Method content
Another way of using the profiling decorators is to apply it directly onto an object. In the following example, only the methods called from the example_object will be profiled.
example_obj = tp.profile_class_methods(ExampleClass())
After adding the decorators and calling the methods, the display_profiles, plot_profiles, or plot_merged methods can be called to visualize the time profiles.
tp.display_profiles(order_by=tp.ORDER_BY_AVERAGE, reverse=False, full_name=True)
tp.plot_profiles()
tp.plot_merged()
Known issues
Despite being able to add profile_class_methods to an object, profile_ignore cannot be used since its implementation relies on attributes, which cannot be updated on objects.
# THIS WILL NOT WORK
tp.profile_ignore(example_obj)
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
File details
Details for the file timeprofiles-0.0.6.tar.gz
.
File metadata
- Download URL: timeprofiles-0.0.6.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e56245e53fc88f57c64e2edab917a1bf64c9938f63e02a24debe4c37d6359766 |
|
MD5 | ef825d864403aefb630a508b907bb1c6 |
|
BLAKE2b-256 | 9ff0042f452d65710ba92d1b98b27769b3bd11f8390a17e730c6d4344811a87b |
File details
Details for the file timeprofiles-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: timeprofiles-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc43f3ae8702829c3b10d720e349c9bd99b073bd44c49f372cdd441ae01889d4 |
|
MD5 | 9ccde0a82621b3962cfcb78c93a4bb63 |
|
BLAKE2b-256 | 66fb4cc4abce059fff494bd4ee756078d02143c41b2b31598d0628f29cc699bd |