Raxol.Profiler (Raxol v2.6.0)

View Source

Compatibility layer for performance profiling.

This module provides a simplified API for profiling code execution. Delegates to Raxol.Performance.Profiler for the actual implementation.

Example

Raxol.Profiler.enable()

result = Raxol.Profiler.profile do
  expensive_operation()
end

Raxol.Profiler.report()

Summary

Functions

Benchmark a function with multiple iterations.

Clear all profiling data.

Compare two implementations.

Disable the profiler and stop collecting metrics.

Enable the profiler.

Profile a code block and record metrics.

Generate a performance report.

Get optimization suggestions based on profiling data.

Functions

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

@spec benchmark(atom(), keyword(), (-> any())) :: map()

Benchmark a function with multiple iterations.

Options

  • :iterations - Number of iterations (default: 100)
  • :warmup - Warmup iterations (default: 10)

Example

Raxol.Profiler.benchmark(:sort, iterations: 1000, fn ->
  Enum.sort(list)
end)

clear()

@spec clear() :: :ok

Clear all profiling data.

compare(operation, implementations)

@spec compare(
  atom(),
  keyword()
) :: map()

Compare two implementations.

Example

Raxol.Profiler.compare(:concat,
  old: fn -> str1 <> str2 end,
  new: fn -> IO.iodata_to_binary([str1, str2]) end
)

disable()

@spec disable() :: :ok

Disable the profiler and stop collecting metrics.

enable()

@spec enable() :: :ok | {:error, term()}

Enable the profiler.

Starts the profiler GenServer if not already running.

profile(opts \\ [], list)

(macro)

Profile a code block and record metrics.

Returns the result of the block while recording execution time, memory usage, and GC statistics.

Options

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

Example

{result, stats} = Raxol.Profiler.profile do
  Enum.sort(large_list)
end

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

@spec profile_operation(atom(), keyword(), (-> any())) :: any()

Profile a named operation.

Example

Raxol.Profiler.profile_operation(:database_query, fn ->
  Repo.all(User)
end)

report(opts \\ [])

@spec report(keyword()) :: String.t() | map() | list()

Generate a performance report.

Options

  • :format - Output format: :text (default), :json, or :raw
  • :operations - Filter to specific operations (default: :all)

Example

Raxol.Profiler.report()
Raxol.Profiler.report(format: :json)

suggest_optimizations()

@spec suggest_optimizations() :: [String.t()]

Get optimization suggestions based on profiling data.