Skip to main content

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.

plot_profiles example figure

plot_merged example figure

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 or the plot_profiles and 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

timeprofiles-0.0.5.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

timeprofiles-0.0.5-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file timeprofiles-0.0.5.tar.gz.

File metadata

  • Download URL: timeprofiles-0.0.5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for timeprofiles-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6f58bd27e24c560a1f90dc893a16358dbd9a14a9802b8e4560943e5b98743f45
MD5 2c52c0096e58737d48c962c31a180689
BLAKE2b-256 b16a19321c1db0ffb977f69b74859868e3a6f99dcf79a0d2c86e0c2cfce5dfd6

See more details on using hashes here.

File details

Details for the file timeprofiles-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for timeprofiles-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5f8271895dfcb71f2f597b84e9686b2a2f135c681547975d9957cfb1d23fe279
MD5 8034396c4735b165b8d6e7f4fe5fa739
BLAKE2b-256 96f687e0b51a233c21cb018c74198f8bae6c0c660108a296e30864232c323313

See more details on using hashes here.

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