This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / knot2 / crates / knot-sim / src / main.rs
1.7 kB 49 lines
1#[tokio::main(flavor = "multi_thread", worker_threads = 4)] 2async fn main() { 3 let args: Vec<String> = std::env::args().skip(1).collect(); 4 let dump = args.iter().any(|arg| arg == "dump"); 5 let target_flag = args.iter().position(|arg| arg == "--target"); 6 let target = match target_flag { 7 Some(position) => match args.get(position + 1) { 8 Some(path) => Some(path.clone()), 9 None => { 10 eprintln!("knot-sim: --target needs a path"); 11 std::process::exit(1); 12 } 13 }, 14 None => None, 15 }; 16 let numbers: Vec<u64> = args 17 .iter() 18 .enumerate() 19 .filter(|(index, _)| { 20 !matches!(target_flag, Some(position) if *index == position || *index == position + 1) 21 }) 22 .filter_map(|(_, arg)| arg.parse().ok()) 23 .collect(); 24 let seed = numbers.first().copied().unwrap_or(1); 25 let rounds = numbers.get(1).copied().unwrap_or(12) as u32; 26 let trace = match target { 27 Some(path) => match knot_sim::run_realdata(std::path::Path::new(&path), seed, rounds).await 28 { 29 Ok(trace) => trace, 30 Err(error) => { 31 eprintln!("knot-sim: {error}"); 32 std::process::exit(1); 33 } 34 }, 35 None => knot_sim::run(seed, rounds).await, 36 }; 37 if dump { 38 println!( 39 "{}", 40 serde_json::to_string_pretty(&trace).expect("trace serializes") 41 ); 42 } 43 println!( 44 "knot-sim seed={seed} rounds={rounds} steps={} snapshots={} digest={:016x}", 45 trace.steps.len(), 46 trace.snapshots.len(), 47 trace.digest() 48 ); 49}