Skip to main content

Profiler

Struct Profiler 

Source
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

Source

pub fn new(enabled: bool) -> Self

Create a new profiler

§Arguments
  • enabled - Whether to collect statistics. When disabled, record is a no-op.
Source

pub fn set_memory_budget(&mut self, budget_bytes: u64)

Set memory budget for reporting

Source

pub fn begin_stratum( &mut self, stratum_id: usize, num_rules: usize, is_recursive: bool, )

Begin timing a stratum

§Arguments
  • stratum_id - The stratum index
  • num_rules - Number of rules in the stratum
  • is_recursive - Whether the stratum is recursive
Source

pub fn end_stratum(&mut self)

End timing the current stratum

Source

pub fn record_iterations(&mut self, iterations: usize)

Record fixpoint iteration count for the current stratum

Source

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 rows
  • output_rows - Number of output rows
  • start - The instant when the operation started
  • memory_bytes - Memory used by the operation
Source

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.

Source

pub fn record_peak_memory(&mut self, memory_bytes: u64)

Record peak memory observation

Source

pub fn execution_stats(&self, total_output_rows: u64) -> ExecutionStats

Get execution stats for CLI output

Source

pub fn is_enabled(&self) -> bool

Check if profiling is enabled

Source

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
Source

pub fn stats(&self) -> &[OpStats]

Get all recorded statistics

Returns a slice of all operation statistics collected so far.

Source

pub fn clear(&mut self)

Clear all recorded statistics

Removes all collected statistics but keeps the profiler enabled/disabled state.

Source

pub fn total_duration_us(&self) -> u64

Get total duration across all operations in microseconds

Source

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.

Source

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.

Source

pub fn operation_count(&self) -> usize

Get the number of recorded operations

Source

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
Source

pub fn set_enabled(&mut self, enabled: bool)

Enable or disable the profiler

When disabled, record becomes a no-op. Existing stats are preserved.

Trait Implementations§

Source§

impl Default for Profiler

Source§

fn default() -> Self

Creates a disabled profiler by default

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,