eprofiler package
Submodules
eprofiler.performance module
- class eprofiler.performance.Timer(label: str = 'Execution')[source]
Bases:
objectA multipurpose tool used as a context manager or a decorator to measure timing.
- Variables:
label (str) – Label for the measurement.
stats (dict) – Dictionary containing the results (label and duration).
start (float) – The timestamp when the timer started.
Example
- with Timer(“Heavy Task”) as t:
do_work()
print(f”Total time: {t.stats[‘duration’]}”)
@Timer(“My Function”) def my_func():
pass
- eprofiler.performance.memit(_func: Callable | None = None, *, label: str = 'Execution Memory', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator that measures memory usage (current and peak) during function execution.
Can be used without parentheses @memit or with arguments @memit(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @memit.
label (str) – A custom tag to identify the output (default: “Execution Memory”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.performance.profile(_func: Callable | None = None, *, label: str = 'Profile', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A comprehensive decorator that measures wall time, CPU time, and memory usage.
Can be used without parentheses @profile or with arguments @profile(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @profile.
label (str) – A custom tag to identify the output (default: “Profile”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.performance.profile_cpu(_func: Callable | None = None, *, label: str = 'Execution Time', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator for CPU time and execution efficiency.
On Unix, this provides a breakdown of ‘user_time’ and ‘system_time’. On Windows, it falls back to total CPU time. It calculates Efficiency as (cpu_time / duration * 100).
- Parameters:
_func (Callable, optional) – Internal parameter to support @profile_cpu.
label (str) – Custom tag for the profiling run (default: “CPU Profile”).
callback (Callable, optional) – Custom function to handle the stats dictionary.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.performance.timeit(_func: Callable | None = None, *, label: str = 'Execution Time', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator that measures the execution time of a function.
Can be used without parentheses @timeit or with arguments @timeit(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @timeit.
label (str) – A custom tag to identify the output (default: “Execution Time”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The wrapped function or the decorator itself.
- Return type:
Callable
eprofiler.auditor module
- eprofiler.auditor.audit(_func=None, *, label='AUDIT', level=20, include_args=False, callback=None)[source]
A decorator that captures function execution metadata and logs the results.
It can be used without parentheses @audit or with arguments @audit(label=”TASK”). If no callback function passed, by default it logs to the ‘eprofiler.auditor’ logger.
- Parameters:
_func (callable, optional) – Internal parameter to support use as @audit decorator
label (str) – A custom tag to identify the audit entry (default: “AUDIT”).
level (int) – The logging level to use (default: logging.INFO).
include_args (bool) – If True, captures function arguments and keyword arguments.
callback (callable, optional) – A custom function to handle the audit payload. If provided, logging is bypassed in favor of this function.
- Returns:
The decorated function wrapper.
- Return type:
callable
Example
@audit(include_args=True) def process_data(data):
return data.upper()
Module contents
- class eprofiler.Timer(label: str = 'Execution')[source]
Bases:
objectA multipurpose tool used as a context manager or a decorator to measure timing.
- Variables:
label (str) – Label for the measurement.
stats (dict) – Dictionary containing the results (label and duration).
start (float) – The timestamp when the timer started.
Example
- with Timer(“Heavy Task”) as t:
do_work()
print(f”Total time: {t.stats[‘duration’]}”)
@Timer(“My Function”) def my_func():
pass
- eprofiler.audit(_func=None, *, label='AUDIT', level=20, include_args=False, callback=None)[source]
A decorator that captures function execution metadata and logs the results.
It can be used without parentheses @audit or with arguments @audit(label=”TASK”). If no callback function passed, by default it logs to the ‘eprofiler.auditor’ logger.
- Parameters:
_func (callable, optional) – Internal parameter to support use as @audit decorator
label (str) – A custom tag to identify the audit entry (default: “AUDIT”).
level (int) – The logging level to use (default: logging.INFO).
include_args (bool) – If True, captures function arguments and keyword arguments.
callback (callable, optional) – A custom function to handle the audit payload. If provided, logging is bypassed in favor of this function.
- Returns:
The decorated function wrapper.
- Return type:
callable
Example
@audit(include_args=True) def process_data(data):
return data.upper()
- eprofiler.memit(_func: Callable | None = None, *, label: str = 'Execution Memory', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator that measures memory usage (current and peak) during function execution.
Can be used without parentheses @memit or with arguments @memit(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @memit.
label (str) – A custom tag to identify the output (default: “Execution Memory”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.profile(_func: Callable | None = None, *, label: str = 'Profile', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A comprehensive decorator that measures wall time, CPU time, and memory usage.
Can be used without parentheses @profile or with arguments @profile(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @profile.
label (str) – A custom tag to identify the output (default: “Profile”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.profile_cpu(_func: Callable | None = None, *, label: str = 'Execution Time', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator for CPU time and execution efficiency.
On Unix, this provides a breakdown of ‘user_time’ and ‘system_time’. On Windows, it falls back to total CPU time. It calculates Efficiency as (cpu_time / duration * 100).
- Parameters:
_func (Callable, optional) – Internal parameter to support @profile_cpu.
label (str) – Custom tag for the profiling run (default: “CPU Profile”).
callback (Callable, optional) – Custom function to handle the stats dictionary.
- Returns:
The decorated function or a decorator factory.
- Return type:
Callable
- eprofiler.timeit(_func: Callable | None = None, *, label: str = 'Execution Time', callback: Callable[[Dict[str, Any]], None] | None = None)[source]
A decorator that measures the execution time of a function.
Can be used without parentheses @timeit or with arguments @timeit(label=”TASK”).
- Parameters:
_func (Callable, optional) – Internal parameter to support use as @timeit.
label (str) – A custom tag to identify the output (default: “Execution Time”).
callback (Callable, optional) – A custom function to handle the stats’ dictionary. If provided, printing to stdout is bypassed.
- Returns:
The wrapped function or the decorator itself.
- Return type:
Callable