Skip to main content

A flexible profiling utility for Python.

Project description

flexprofiler

A flexible profiling utility for Python.

Installation

pip install flexprofiler

Usage Examples

1. Tracking a Simple Function

import time
from flexprofiler import FlexProfiler

profiler = FlexProfiler(max_depth=5, detailed=True, record_each_call=True)

@profiler.track
def simple_func():
    for i in range(3):
        time.sleep(0.1)

simple_func()
simple_func()

profiler.stats()

Output

<title>stdin</title>
Detailed Function Call Statistics:
simple_func: 2 calls, Total: 0.6008s, Avg: 0.3004s, Std: 0.0000s, Median: 0.3004s

2. Tracking All Methods in a Class

import time
from flexprofiler import FlexProfiler

profiler = FlexProfiler(max_depth=5, detailed=True, record_each_call=True)

@profiler.track_all_recursive()
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()

profiler.stats()

output:

<title>stdin</title>
Detailed Function Call Statistics:
Foo.example_method: 1 calls, Total: 0.3003s, Avg: 0.3003s
  └──Foo.another_method:      1 calls, Total: 0.2002s, Avg: 0.2002s
Foo.another_method: 1 calls, Total: 0.2001s, Avg: 0.2001s

3. Tracking All Methods in a Class Recursively

import time
from flexprofiler import FlexProfiler

profiler = FlexProfiler(max_depth=5, detailed=True, record_each_call=True)

@profiler.track_all_recursive()
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()

profiler.stats()

output:

<title>stdin</title>
Detailed Function Call Statistics:
Foo.__init__: 2 calls, Total: 0.0001s, Avg: 0.0000s, Std: 0.0001s, Median: 0.0000s
Foo.example_method: 1 calls, Total: 0.3003s, Avg: 0.3003s
  └──Foo.another_method:      1 calls, Total: 0.2001s, Avg: 0.2001s
Foo.calling_subclass_method: 1 calls, Total: 0.3326s, Avg: 0.3326s
  ├──Bar.subclass_method_1:  │   3 calls, Total: 0.1504s, Avg: 0.0501s, Std: 0.0001s, Median: 0.0501s
  ├──Bar.subclass_method_2:  │   3 calls, Total: 0.0910s, Avg: 0.0303s, Std: 0.0001s, Median: 0.0303s
  │    ├──Bar.a:       │   3 calls, Total: 0.0604s, Avg: 0.0201s, Std: 0.0001s, Median: 0.0201s
  │    └──Bar.b:           3 calls, Total: 0.0303s, Avg: 0.0101s, Std: 0.0000s, Median: 0.0101s
  └──Bar.subclass_method_3:      3 calls, Total: 0.0910s, Avg: 0.0303s, Std: 0.0002s, Median: 0.0303s
       ├──Bar.a:       │   3 calls, Total: 0.0604s, Avg: 0.0201s, Std: 0.0001s, Median: 0.0201s
       └──Bar.b:           3 calls, Total: 0.0304s, Avg: 0.0101s, Std: 0.0001s, Median: 0.0102s

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

flexprofiler-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

flexprofiler-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file flexprofiler-0.1.0.tar.gz.

File metadata

  • Download URL: flexprofiler-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.11

File hashes

Hashes for flexprofiler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bdc19bb5f7ec22ce97782526ae85a4838eb26f50758c1a34aef7089fe74b274e
MD5 b806afd2e4c9f08ace223dd510d20c69
BLAKE2b-256 65f03a5b2e391c4520f7fc92fd12c439d0e69cb6d700180438d482f8bbc3dc1d

See more details on using hashes here.

File details

Details for the file flexprofiler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flexprofiler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.11

File hashes

Hashes for flexprofiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b19ca8d7674b21cfcbce74ca37f4d52b86df1b8905a1b69fbc72d6305db7fbe
MD5 86acf91918e326e2f9c3cdac748c9551
BLAKE2b-256 dc0464ea287f9bbc2713f3907823d0630b76d5ea27f9825a6d5694ac012ab476

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