debugtoolkit package

Submodules

debugtoolkit.decorators module

debugtoolkit.decorators.log_garbage_collection(func)[source]

This is a decorator function that logs the garbage collection counts before and after the execution of the decorated function.

It checks the garbage collection counts before and after the function execution. If the counts have changed, it logs the counts before and after the execution.

Parameters:

func (function) – The function to be decorated.

Returns:

The decorated function which logs its garbage collection counts when called.

Return type:

function

Example

@log_garbage_collection def add(a, b):

return a + b

add(1, 2) # The above call will log the garbage collection counts before and after the function execution if they have changed.

debugtoolkit.decorators.log_inputs(func)[source]

This is a decorator function that logs the input arguments of the decorated function.

It logs the function call with its arguments and keyword arguments, using a safe_repr function to convert the arguments to a string representation. The log message is in the format of “Calling {function_name}({arguments})”.

Parameters:

func (function) – The function to be decorated.

Returns:

The decorated function which logs its input arguments when called.

Return type:

function

Example

@log_inputs def add(a, b):

return a + b

add(1, 2) # The above call will log “Calling add(1, 2)”

debugtoolkit.decorators.log_time_execution(n=1)[source]

This is a decorator function that logs the execution time of the decorated function.

It runs the function n times, and logs the execution time for each run. If n is greater than 1, it also logs the average execution time.

Parameters:

n (int, optional) – The number of times to run the decorated function. Defaults to 1.

Returns:

The decorated function which logs its execution time when called.

Return type:

function

Example

@log_time_execution(n=3) def add(a, b):

return a + b

add(1, 2) # The above call will log the execution time for each of the 3 runs, # and the average execution time.

debugtoolkit.decorators.monitor_detailed_resources(func)[source]

This is a decorator function that logs the detailed resource usage of the decorated function.

It calculates and logs the CPU usage, execution time, memory usage, disk I/O, and network I/O before and after the function execution.

Parameters:

func (function) – The function to be decorated.

Returns:

The decorated function which logs its detailed resource usage when called.

Return type:

function

Example

@monitor_detailed_resources def add(a, b):

return a + b

add(1, 2) # The above call will log the detailed resource usage of the function execution.

debugtoolkit.decorators.monitor_resources(func)[source]

This is a decorator function that logs the CPU and memory usage of the decorated function.

It calculates the CPU usage and memory usage before and after the function execution, and logs the difference. The CPU usage is logged as a percentage, and the memory usage is logged in bytes.

Parameters:

func (function) – The function to be decorated.

Returns:

The decorated function which logs its CPU and memory usage when called.

Return type:

function

Example

@monitor_resources def add(a, b):

return a + b

add(1, 2) # The above call will log the CPU and memory usage of the function execution.

debugtoolkit.decorators.safe_repr(obj)[source]

Generate a safe representation of the object for logging. Avoids calling the __repr__ method of the object directly.

Module contents