pub struct Profiler { /* private fields */ }Expand description
Execution profiler for tracking operation statistics
The profiler collects statistics for each operation during query execution.
It can be enabled or disabled; when disabled, record is a no-op for
minimal overhead.
§Thread Safety
This implementation is NOT thread-safe. It is designed for single-threaded execution in the MVP.
§Example
use xlog_runtime::profiler::{Profiler, OpStats};
// Create an enabled profiler
let mut profiler = Profiler::new(true);
// Record some stats
profiler.record(OpStats::timed("scan", 0, 1000, 100));
profiler.record(OpStats::timed("filter", 1000, 500, 200));
// Check totals
assert_eq!(profiler.total_duration_us(), 300);
// Get summary
println!("{}", profiler.summary());Implementations§
Source§impl Profiler
impl Profiler
Sourcepub fn new(enabled: bool) -> Self
pub fn new(enabled: bool) -> Self
Create a new profiler
§Arguments
enabled- Whether to collect statistics. When disabled,recordis a no-op.
Sourcepub fn set_memory_budget(&mut self, budget_bytes: u64)
pub fn set_memory_budget(&mut self, budget_bytes: u64)
Set memory budget for reporting
Sourcepub fn begin_stratum(
&mut self,
stratum_id: usize,
num_rules: usize,
is_recursive: bool,
)
pub fn begin_stratum( &mut self, stratum_id: usize, num_rules: usize, is_recursive: bool, )
Begin timing a stratum
§Arguments
stratum_id- The stratum indexnum_rules- Number of rules in the stratumis_recursive- Whether the stratum is recursive
Sourcepub fn end_stratum(&mut self)
pub fn end_stratum(&mut self)
End timing the current stratum
Sourcepub fn record_iterations(&mut self, iterations: usize)
pub fn record_iterations(&mut self, iterations: usize)
Record fixpoint iteration count for the current stratum
Sourcepub fn record_op(
&mut self,
op_name: impl Into<String>,
input_rows: u64,
output_rows: u64,
start: Instant,
memory_bytes: u64,
)
pub fn record_op( &mut self, op_name: impl Into<String>, input_rows: u64, output_rows: u64, start: Instant, memory_bytes: u64, )
Record an operation with timing
This is a convenience method that calculates duration from a start time.
§Arguments
op_name- Name of the operation (e.g., “join”, “filter”, “scan”)input_rows- Number of input rowsoutput_rows- Number of output rowsstart- The instant when the operation startedmemory_bytes- Memory used by the operation
Sourcepub fn start_op(&self) -> Option<Instant>
pub fn start_op(&self) -> Option<Instant>
Start timing an operation
Returns the current instant if profiling is enabled, None otherwise. This allows zero-overhead timing when profiling is disabled.
Sourcepub fn record_peak_memory(&mut self, memory_bytes: u64)
pub fn record_peak_memory(&mut self, memory_bytes: u64)
Record peak memory observation
Sourcepub fn execution_stats(&self, total_output_rows: u64) -> ExecutionStats
pub fn execution_stats(&self, total_output_rows: u64) -> ExecutionStats
Get execution stats for CLI output
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if profiling is enabled
Sourcepub fn record(&mut self, stats: OpStats)
pub fn record(&mut self, stats: OpStats)
Record operation statistics
If the profiler is disabled, this is a no-op. If a stratum is active, the operation is also recorded in the stratum.
§Arguments
stats- The operation statistics to record
Sourcepub fn stats(&self) -> &[OpStats]
pub fn stats(&self) -> &[OpStats]
Get all recorded statistics
Returns a slice of all operation statistics collected so far.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all recorded statistics
Removes all collected statistics but keeps the profiler enabled/disabled state.
Sourcepub fn total_duration_us(&self) -> u64
pub fn total_duration_us(&self) -> u64
Get total duration across all operations in microseconds
Sourcepub fn total_memory_bytes(&self) -> u64
pub fn total_memory_bytes(&self) -> u64
Get total memory usage across all operations in bytes
Note: This is the sum of memory reported by each operation, which may include overlapping allocations. It represents total memory activity rather than peak memory usage.
Sourcepub fn peak_memory_bytes(&self) -> u64
pub fn peak_memory_bytes(&self) -> u64
Get peak memory usage across all operations in bytes
Returns the maximum memory_bytes value across all recorded operations. Returns 0 if no operations have been recorded.
Sourcepub fn operation_count(&self) -> usize
pub fn operation_count(&self) -> usize
Get the number of recorded operations
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Generate a human-readable summary of the profiling data
The summary includes:
- Total operation count
- Total duration in milliseconds
- Total memory usage
- Per-operation breakdown with timing and row counts
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable the profiler
When disabled, record becomes a no-op. Existing stats are preserved.