Skip to main content

Module memory_profiling

Module memory_profiling 

Source
Expand description

§Advanced Memory Profiling for SciRS2

This module provides comprehensive memory profiling capabilities using Pure Rust OS APIs. It enables heap profiling, memory leak detection, and allocation pattern analysis without requiring jemalloc or any C/Fortran dependencies.

§Platform Support

  • macOS: Uses mach_task_self() / task_info via libc for accurate memory stats
  • Linux: Reads /proc/self/statm and /proc/self/status for memory stats
  • Other Unix: Falls back to tracking via global allocator wrapper
  • Windows: Uses windows-sys APIs for memory info

§Features

  • Heap Profiling: Track memory allocations and deallocations
  • Leak Detection: Identify memory leaks
  • Allocation Patterns: Analyze allocation patterns
  • Statistics: Detailed memory statistics
  • Zero Overhead: Disabled by default, minimal overhead when enabled
  • Pure Rust: No C/Fortran dependencies (COOLJAPAN Policy)

§Example

use scirs2_core::profiling::memory_profiling::{MemoryProfiler, enable_profiling};

// Enable memory profiling
enable_profiling().expect("Failed to enable profiling");

// ... perform allocations ...

// Get memory statistics
let stats = MemoryProfiler::get_stats().expect("Failed to get stats");
println!("Allocated: {} bytes", stats.allocated);
println!("Resident: {} bytes", stats.resident);

Structs§

AllocationAnalysis
Allocation pattern analysis
AllocationTracker
Allocation tracker for detecting patterns
MemoryDelta
Memory delta from baseline
MemoryProfiler
Memory profiler
MemoryStats
Memory statistics gathered from OS APIs (Pure Rust)

Functions§

disable_profiling
Disable memory profiling
enable_profiling
Enable memory profiling