guardy 0.2.4

Fast, secure git hooks in Rust with secret scanning and protected file synchronization
Documentation
#!/usr/bin/env -S cargo +nightly -Zscript
//! Memory profiling test for guardy scanning

use std::process::Command;
use std::thread;
use std::time::{Duration, Instant};

fn get_memory_usage(pid: u32) -> Option<u64> {
    let output = Command::new("ps")
        .args(&["-o", "rss=", "-p", &pid.to_string()])
        .output()
        .ok()?;
    
    let rss_str = String::from_utf8(output.stdout).ok()?;
    let rss_kb: u64 = rss_str.trim().parse().ok()?;
    Some(rss_kb * 1024) // Convert to bytes
}

fn main() {
    println!("🔬 Starting memory profile test...");
    
    // Start guardy scan in background
    let mut child = Command::new("target/release/guardy")
        .args(&["scan", "../../../../", "-q"])
        .spawn()
        .expect("Failed to start guardy");
    
    let pid = child.id();
    println!("📊 Monitoring process {} memory usage...", pid);
    
    let start = Instant::now();
    let mut max_memory = 0;
    let mut samples = Vec::new();
    
    // Monitor every 2 seconds
    while let Ok(None) = child.try_wait() {
        if let Some(memory) = get_memory_usage(pid) {
            let elapsed = start.elapsed().as_secs();
            max_memory = max_memory.max(memory);
            samples.push((elapsed, memory));
            
            println!("⏱️  {}s: {:.1}MB (peak: {:.1}MB)", 
                     elapsed, 
                     memory as f64 / 1024.0 / 1024.0,
                     max_memory as f64 / 1024.0 / 1024.0);
        }
        thread::sleep(Duration::from_secs(2));
    }
    
    // Final results
    println!("\n🔍 Memory Profile Summary:");
    println!("  Peak Memory: {:.1}MB", max_memory as f64 / 1024.0 / 1024.0);
    println!("  Runtime: {:?}", start.elapsed());
    
    if samples.len() > 2 {
        let growth = samples.last().unwrap().1 as i64 - samples[1].1 as i64;
        println!("  Memory Growth: {:.1}MB", growth as f64 / 1024.0 / 1024.0);
        
        if growth > 100 * 1024 * 1024 { // More than 100MB growth
            println!("  ⚠️  Potential memory leak detected!");
        }
    }
}