crates/run/container/src/main.rs 1.6 KiB 40 lines Raw
1 //! The probe helper. It runs in a container with host PID visibility and the2 //! CDI devices that the deploy file chose, and answers one question per3 //! invocation. It never starts an engine and never reads a weight file.4 5 use std::process::ExitCode;6 7 use inf3r_host::{Host, device_free_bytes, process_tree, process_tree_bytes, process_vram_bytes};8 9 fn main() -> ExitCode {10     let args: Vec<String> = std::env::args().skip(1).collect();11     let answer = match args.first().map(String::as_str) {12         Some("--version") if args.len() == 1 => {13             println!("{}", env!("CARGO_PKG_VERSION"));14             return ExitCode::SUCCESS;15         }16         Some("--host") => Host::probe().encode(),17         Some("--rss") if args.len() == 2 => match args[1].parse::<u32>() {18             Ok(pid) => {19                 process_tree_bytes(pid).map_or_else(|| "-\n".to_string(), |n| format!("{n}\n"))20             }21             Err(_) => return ExitCode::from(2),22         },23         Some("--vram") if args.len() == 3 => match args[1].parse::<u32>() {24             Ok(pid) => process_vram_bytes(&process_tree(pid), &args[2])25                 .map_or_else(|| "-\n".to_string(), |n| format!("{n}\n")),26             Err(_) => return ExitCode::from(2),27         },28         Some("--free") if args.len() == 2 => {29             device_free_bytes(&args[1]).map_or_else(|| "-\n".to_string(), |n| format!("{n}\n"))30         }31         _ => {32             eprintln!(33                 "usage: inf3r-probe --version | --host | --rss <pid> | --vram <pid> <device> | --free <device>"34             );35             return ExitCode::from(2);36         }37     };38     print!("{answer}");39     ExitCode::SUCCESS40 }