Module profiling

Module profiling 

Source
Expand description

Memory profiling and leak detection utilities.

This module provides comprehensive memory profiling tools for detecting memory leaks, tracking allocations, and analyzing memory usage patterns.

§Features

  • Allocation Tracking: Track every allocation and deallocation
  • Leak Detection: Identify memory that wasn’t freed
  • Memory Snapshots: Capture and compare memory state
  • Heap Profiling: Integration with DHAT for detailed heap analysis
  • Pool Monitoring: Track string/buffer pool usage

§Quick Start

use prax_query::profiling::{MemoryProfiler, AllocationTracker};

// Start profiling
let profiler = MemoryProfiler::new();

// Take initial snapshot
let before = profiler.snapshot();

// ... do some work ...

// Take final snapshot
let after = profiler.snapshot();

// Analyze difference
let diff = after.diff(&before);
if diff.has_leaks() {
    eprintln!("Potential memory leak detected!");
    eprintln!("{}", diff.report());
}

§Enabling Profiling

Add the profiling feature to enable runtime profiling:

[dependencies]
prax-query = { version = "0.3", features = ["profiling"] }

For DHAT heap profiling (slower but more detailed):

[dependencies]
prax-query = { version = "0.3", features = ["dhat-heap"] }

Re-exports§

pub use allocation::AllocationRecord;
pub use allocation::AllocationTracker;
pub use allocation::AllocationStats;
pub use allocation::TrackedAllocator;
pub use allocation::GLOBAL_TRACKER;
pub use heap::HeapProfiler;
pub use heap::HeapStats;
pub use heap::HeapReport;
pub use leak_detector::LeakDetector;
pub use leak_detector::LeakReport;
pub use leak_detector::PotentialLeak;
pub use leak_detector::LeakSeverity;
pub use snapshot::MemorySnapshot;
pub use snapshot::SnapshotDiff;
pub use snapshot::PoolSnapshot;

Modules§

allocation
Allocation tracking and statistics.
heap
Heap profiling and analysis.
leak_detector
Memory leak detection.
snapshot
Memory snapshots for comparing state over time.

Structs§

MemoryProfiler
Memory profiler combining all profiling capabilities.
MemoryReport
Comprehensive memory report.
PoolStats
Pool statistics.

Functions§

disable_profiling
Disable memory profiling globally.
enable_profiling
Enable memory profiling globally.
is_profiling_enabled
Check if profiling is enabled.
with_profiling
Run a closure with profiling enabled, returning the result and a memory report.
with_profiling_async
Async version of with_profiling.