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.
Profile a named operation.
Generate a performance report.
Get optimization suggestions based on profiling data.
Functions
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)
@spec clear() :: :ok
Clear all profiling data.
Compare two implementations.
Example
Raxol.Profiler.compare(:concat,
old: fn -> str1 <> str2 end,
new: fn -> IO.iodata_to_binary([str1, str2]) end
)
@spec disable() :: :ok
Disable the profiler and stop collecting metrics.
@spec enable() :: :ok | {:error, term()}
Enable the profiler.
Starts the profiler GenServer if not already running.
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 a named operation.
Example
Raxol.Profiler.profile_operation(:database_query, fn ->
Repo.all(User)
end)
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)
@spec suggest_optimizations() :: [String.t()]
Get optimization suggestions based on profiling data.