Skip to main content

A lightweight tool to monitor execution of functions.

Project description

eprofiler

A lightweight, zero-dependency toolkit to monitor execution of functions or code blocks.

PyPI Build Status License Documentation

eprofiler provides decorators and context managers to observe execution time, cpu time, peak memory and arguments used for a function.

for a function or code block you can monitor and log;

  • execution time
  • peak memory usage
  • CPU time
  • parameters passed to a function

Installation

pip install eprofiler

Core Tools

  • @audit: Execution logging with SUCCESS/FAIL status and error capturing.
  • @timeit: Execution timing (microsecond precision).
  • @memit: Tracks current and peak memory usage.
  • @profile: The "All-in-One": Wall time, CPU time, and Memory.
  • @profile_cpu: User vs System time (Unix) & Efficiency %.
  • Timer: Context manager and/or decorator for granular blocks.

Usage

1. Function Auditing (@audit)

Good for monitoring what parameters are passed to a function/method. where you need to know if a function finished, how long it took, and why it failed and with which parameters.

⚠ Warning:
if parameters passed to function are not printable like str, int or a python object without __str__ or __repr__ that can be used in fstrings its better to use callback to handle them in logging

from eprofiler import audit

@audit(label="Audit", include_args=True)
def create_user(username, email):
    return f"User {username} created."

Output:

INFO: {'timestamp': '2026-03-05T18:33:37.651931', 'function': 'create_user', 'label': 'Audit', 'args': ('jdoe', 'jane@example.com'), 'kwargs': {}, 'status': 'SUCCESS', 'elapsed_seconds': '0.000003'}

2. Basic Timing (@timeit)

For quick performance checks during development. By default, results are printed to the console.

from eprofiler import timeit

@timeit(label="Computation")
def my_func():
    return sum(i**2 for i in range(100000))

my_func()

Output:

{'label': 'Computation', 'function': 'my_func', 'duration': '0.000074'}

3. Comprehensive Profiling (@profile & @profile_cpu)

Track wall-clock time, actual CPU usage, and memory (current and peak) simultaneously.

from eprofiler import profile, profile_cpu

# Standard profile (Wall Time + CPU Time + Memory)
@profile(label="Data Batch")
def process_data():
    return [x for x in range(1000000)]

# CPU profile (User/System breakdown + Efficiency)
@profile_cpu(label="Heavy Computation")
def compute_pi():
    return sum(1/i**2 for i in range(1, 1000000))

process_data()
compute_pi()

Output:

{'label': 'Data Batch', 'function': 'process_data', 'duration': '0.241128', 'cpu_time': '0.241104', 'peak': 40440488, 'current': 40440448}

{'label': 'Heavy Computation', 'function': 'compute_pi', 'user_time': '0.048526', 'system_time': '0.000074', 'cpu_time': '0.048600', 'duration': '0.048610', 'efficiency': '99.98%'}

4. Using Callback

Instead of printing to the console, you can pass a callback function to any decorator to handle the results programmatically (e.g., sending metrics to a database, Slack, or a logging service).

from eprofiler import profile_cpu

def metrics_handler(stats):
    """Custom function to process profiling data."""
    # Send to Datadog, CloudWatch, or an ELK stack
    print(f"TELEMETRY: {stats['function']} ran with {stats['efficiency']} efficiency.")

@profile_cpu(label="Production_Task", callback=metrics_handler)
def sync_data():
    # Logic here...
    return "Done"

sync_data()

Using your own metrics_handler you can do anything you want with stats.

5. Timer class for codeblocks

Timer can be used as a decoator, or can be used for code blocks for part of a function rather than whole function Note that Timer class does not have a callback

from eprofiler import Timer
import time

# Use as a Context Manager
with Timer(label="External API Call") as t:
    time.sleep(0.5)  # Simulate a network delay

print(f"Result: {t.stats['label']} took {t.stats['duration']:.6f}s")

# Also works as a decorator for simple timing
@Timer(label="Quick Check")
def short_task():
    pass

Links


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

eprofiler-0.1.0b1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

eprofiler-0.1.0b1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file eprofiler-0.1.0b1.tar.gz.

File metadata

  • Download URL: eprofiler-0.1.0b1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for eprofiler-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 8dbe4e2eebb144c52f97667e6a96eee4b11bd154449d218590735133899cbac5
MD5 db6a64907b97ac13fc4a356ece8712a2
BLAKE2b-256 5fe71389f52becd6bf8f29dfd948c1147a4319301d19e9c5a59f2e2ea3dad90e

See more details on using hashes here.

File details

Details for the file eprofiler-0.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: eprofiler-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for eprofiler-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ab41629d46a1dc21c39983944b319147a37b265e51d4f3826e9c466605fbf0a
MD5 2d98fc6d91323b3be38325f020907e03
BLAKE2b-256 a7aa22e2b4b8ba557ca0defcb5c8d405b369406b70dc94e43dc79c559e962d78

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