haive.core.utils.debugkit.profiling.performance¶

Performance Profiling Utilities

Provides comprehensive performance analysis including line-by-line profiling, memory analysis, CPU profiling, and execution optimization insights.

Classes¶

CPUProfiler

CPU profiling utilities.

LineProfiler

Line-by-line performance profiler.

MemoryProfiler

Memory usage profiler.

ProfilingUtilities

Comprehensive profiling utilities.

TimingProfiler

Simple timing profiler for function execution.

Module Contents¶

class haive.core.utils.debugkit.profiling.performance.CPUProfiler[source]¶

CPU profiling utilities.

profile_cpu(func, duration=10)[source]¶

Profile CPU usage with pyinstrument.

Parameters:
Return type:

collections.abc.Callable

profile_with_scalene(script_path, output_dir='scalene_profiles')[source]¶

Profile a script with Scalene.

Parameters:
  • script_path (str)

  • output_dir (str)

Return type:

None

class haive.core.utils.debugkit.profiling.performance.LineProfiler[source]¶

Line-by-line performance profiler.

profile_lines(func)[source]¶

Profile function line by line.

Parameters:

func (collections.abc.Callable)

Return type:

collections.abc.Callable

show_stats(filename=None)[source]¶

Show line profiling statistics.

Parameters:

filename (str | None)

Return type:

None

class haive.core.utils.debugkit.profiling.performance.MemoryProfiler[source]¶

Memory usage profiler.

get_current_usage()[source]¶

Get current memory usage statistics.

Return type:

dict[str, float]

memory_line_by_line(func)[source]¶

Profile memory usage line by line using memory_profiler.

Parameters:

func (collections.abc.Callable)

Return type:

collections.abc.Callable

profile_memory(func)[source]¶

Decorator to profile memory usage.

Parameters:

func (collections.abc.Callable)

Return type:

collections.abc.Callable

class haive.core.utils.debugkit.profiling.performance.ProfilingUtilities[source]¶

Comprehensive profiling utilities.

benchmark(func, iterations=1000, warmup=100)[source]¶

Benchmark a function with multiple iterations.

Parameters:
Return type:

dict[str, float]

clear()[source]¶

Clear all profiling data.

Return type:

None

compare(funcs, iterations=1000)[source]¶

Compare performance of multiple functions.

Parameters:
Return type:

dict[str, dict[str, float]]

comprehensive(func)[source]¶

Apply comprehensive profiling (time + memory + CPU).

Parameters:

func (collections.abc.Callable)

Return type:

collections.abc.Callable

cpu(func=None)[source]¶

Profile CPU usage.

Parameters:

func (collections.abc.Callable | None)

Return type:

collections.abc.Callable

line(func=None)[source]¶

Profile line-by-line execution.

Parameters:

func (collections.abc.Callable | None)

Return type:

collections.abc.Callable

memory(func=None, line_by_line=False)[source]¶

Profile memory usage.

Parameters:
Return type:

collections.abc.Callable

profile_context(name='profile', include_memory=True, include_cpu=True)[source]¶

Context manager for profiling a block of code.

Parameters:
stats()[source]¶

Show all profiling statistics.

Return type:

None

status()[source]¶

Get status of available profiling tools.

Return type:

dict[str, bool]

time(func=None)[source]¶

Time function execution.

Parameters:

func (collections.abc.Callable | None)

Return type:

collections.abc.Callable

class haive.core.utils.debugkit.profiling.performance.TimingProfiler[source]¶

Simple timing profiler for function execution.

clear()[source]¶

Clear timing data.

Return type:

None

get_stats()[source]¶

Get timing statistics for all functions.

Return type:

dict[str, dict[str, float]]

time_function(func)[source]¶

Decorator to time function execution.

Parameters:

func (collections.abc.Callable)

Return type:

collections.abc.Callable