Raxol.Core.Performance.Profiler (Raxol v2.0.1)

View Source

Performance profiling and optimization tools for Raxol.

Provides instrumentation, profiling, and analysis capabilities to identify and optimize performance bottlenecks in the application.

Features

  • Function execution timing
  • Memory usage tracking
  • Hot path identification
  • Performance regression detection
  • Automatic optimization suggestions

Usage

import Raxol.Core.Performance.Profiler

# Profile a function
profile :my_operation do
  expensive_computation()
end

# Get performance report
Profiler.report()

Summary

Functions

Benchmarks a function with multiple iterations.

Benchmarks a function with multiple iterations (function version).

Returns a specification to start this module under a supervisor.

Clears all profiling data.

Compares performance of two implementations.

Identifies hot paths in the application.

Profiles a code block and records metrics.

Executes and profiles a function.

Profiles memory usage of a function.

Profiles memory usage of a function (function version).

Generates a performance report.

Suggests optimizations based on profiling data.

Types

metric_type()

@type metric_type() :: :execution_time | :memory_usage | :call_count | :gc_runs

profile_data()

@type profile_data() :: %{
  operation: atom(),
  metrics: map(),
  timestamp: DateTime.t(),
  metadata: map()
}

Functions

analyze_benchmark_results(operation, times)

benchmark(operation, opts \\ [], list)

(macro)

Benchmarks a function with multiple iterations.

Examples

benchmark(:sort_algorithm, iterations: 1000) do
  Enum.sort(large_list)
end

benchmark_fun(operation, opts \\ [], fun)

Benchmarks a function with multiple iterations (function version).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

Clears all profiling data.

compare(operation, implementations)

Compares performance of two implementations.

Examples

compare(:string_concat,
  old: fn -> str1 <> str2 end,
  new: fn -> [str1, str2] |> IO.iodata_to_binary() end
)

get_gc_runs(info)

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

identify_hot_paths(duration \\ 5000)

Identifies hot paths in the application.

profile(operation, opts \\ [], list)

(macro)

Profiles a code block and records metrics.

Options

  • :sample_rate - Sampling rate (0.0 to 1.0, default: 1.0)
  • :trace - Enable detailed tracing (default: false)
  • :metadata - Additional metadata to record

Examples

profile :database_query, metadata: %{query: "SELECT *"} do
  Repo.all(User)
end

profile_execution(operation, opts, fun)

Executes and profiles a function.

profile_memory(operation, list)

(macro)

Profiles memory usage of a function.

profile_memory_fun(operation, fun)

Profiles memory usage of a function (function version).

record_memory_metrics(operation, memory_delta, gc_runs)

report(opts \\ [])

Generates a performance report.

start_link(init_opts \\ [])

suggest_optimizations()

Suggests optimizations based on profiling data.