mecha10-core 0.8.2

Mecha10 core runtime and foundational types
Documentation
use mecha10_core::profiling::*;
use std::time::Duration;

#[tokio::test]
async fn test_latency_tracking() {
    let metrics = PerformanceMetrics::new();

    metrics.record_latency("/test/topic", 1000).await;
    metrics.record_latency("/test/topic", 2000).await;
    metrics.record_latency("/test/topic", 1500).await;

    let stats = metrics.get_latency_stats("/test/topic").await.unwrap();
    assert_eq!(stats.count, 3);
    assert_eq!(stats.min_us, 1000);
    assert_eq!(stats.max_us, 2000);
    assert_eq!(stats.mean_us, 1500.0);
}

#[tokio::test]
async fn test_throughput_tracking() {
    let metrics = PerformanceMetrics::new();

    for _ in 0..100 {
        metrics.record_message("/test/topic", 1024).await;
    }

    tokio::time::sleep(Duration::from_millis(100)).await;

    let stats = metrics.get_throughput_stats("/test/topic").await.unwrap();
    assert_eq!(stats.message_count, 100);
    assert_eq!(stats.byte_count, 102400);
    assert!(stats.messages_per_sec > 0.0);
}

#[tokio::test]
async fn test_execution_tracking() {
    let metrics = PerformanceMetrics::new();

    {
        let _timer = metrics.start_timer("test_function").await;
        tokio::time::sleep(Duration::from_millis(10)).await;
    }

    tokio::time::sleep(Duration::from_millis(10)).await;

    let stats = metrics.get_execution_stats("test_function").await;
    assert!(stats.is_some());
    let stats = stats.unwrap();
    assert_eq!(stats.count, 1);
    assert!(stats.mean_us >= 10000.0);
}

#[tokio::test]
async fn test_memory_tracking() {
    let metrics = PerformanceMetrics::new();

    metrics.record_memory(1000000, 0).await;
    metrics.record_memory(500000, 0).await;
    metrics.record_memory(0, 200000).await;

    let stats = metrics.get_memory_stats().await;
    assert_eq!(stats.total_allocated_bytes, 1500000);
    assert_eq!(stats.total_freed_bytes, 200000);
    assert_eq!(stats.current_usage_bytes, 1300000);
}