//! Memory profiler

use super::super::error::ProfilingError;
use super::bandwidth::measure_memory_bandwidth;
use super::cache::measure_cache_performance;
use super::latency::test_memory_latency;
use super::numa::test_numa_bandwidth;
use super::stress::run_memory_stress_test;
use super::usage::profile_memory_usage;

/// Memory performance profiler
pub struct MemoryProfiler;

impl MemoryProfiler {
    /// Create memory profiler
    pub fn new() -> Self {
        Self
    }

    /// Measure memory bandwidth
    pub fn measure_bandwidth(
        &self,
    ) -> Result<super::bandwidth::MemoryBandwidthResult, ProfilingError> {
        measure_memory_bandwidth()
    }

    /// Test memory latency
    pub fn test_latency(
        &self,
        size: u64,
    ) -> Result<super::latency::MemoryLatencyResult, ProfilingError> {
        test_memory_latency(size)
    }

    /// Measure cache performance
    pub fn measure_cache(&self) -> Result<super::cache::CacheResult, ProfilingError> {
        measure_cache_performance()
    }

    /// Test NUMA bandwidth
    pub fn test_numa(&self) -> Result<super::numa::NumaResult, ProfilingError> {
        test_numa_bandwidth()
    }

    /// Run memory stress test
    pub fn run_stress_test(
        &self,
        duration: std::time::Duration,
    ) -> Result<super::stress::StressTestResult, ProfilingError> {
        run_memory_stress_test(duration)
    }

    /// Profile memory usage of process
    pub fn profile_usage(
        &self,
        pid: u32,
    ) -> Result<super::usage::MemoryUsageProfile, ProfilingError> {
        profile_memory_usage(pid)
    }
}

impl Default for MemoryProfiler {
    fn default() -> Self {
        Self::new()
    }
}
