Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/synapse/blob/main/crates/synapse-bench/src/lib.rs # synapse A component of the AienOS ecosystem. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `synapse / crates / synapse-bench / src / lib.rs` 122 lines ยท 4441 bytes Raw Blame History 1 //! Gate 4 comparative qualification harness for Synapse ([aien-sovereign-core#515]). 2 //! 3 //! The harness measures Synapse changeset ingest and checkout-free queries against 4 //! conventional Git workflows on a pinned, real repository fixture, runs neutral 5 //! conformance suites (WAL recovery, Git materialization, Radicle canonicality), and 6 //! records raw per-operation traces plus a host and toolchain manifest. 7 //! 8 //! It reports measurements only. No module contains an adoption verdict, and no test 9 //! asserts that one arm is faster than another: tests assert correctness only. 10 //! 11 //! Process model: the `run` orchestrator ([`orchestrator::run_qualification`]) spawns 12 //! one child process per measurement cell (`synapse-bench child ...`) so that CPU time 13 //! (`getrusage` self plus waited children) and peak RSS are attributed per arm. 14 //! 15 //! [aien-sovereign-core#515]: https://github.com/aien-spark/aien-sovereign-core/issues/515 16 17 pub mod bounds; 18 pub mod c1; 19 pub mod conflict; 20 pub mod conformance; 21 pub mod crypto_vectors; 22 pub mod energy; 23 pub mod fixture; 24 pub mod floor; 25 pub mod git_arm; 26 pub mod gitcmd; 27 pub mod host; 28 pub mod merge_t1; 29 pub mod orchestrator; 30 pub mod pmu; 31 pub mod pmu_diag; 32 pub mod query; 33 pub mod recovery; 34 pub mod rng; 35 pub mod rusage; 36 pub mod segments; 37 pub mod stats; 38 pub mod synapse_arm; 39 pub mod tree_parity; 40 pub mod workload; 41 pub mod write_phase; 42 pub mod x6; 43 44 use std::path::Path; 45 46 /// Write `value` as pretty JSON to `path`, creating parent directories. 47 pub fn write_json(path: &Path, value: &T) -> Result<(), String> { 48 if let Some(parent) = path.parent() { 49 std::fs::create_dir_all(parent).map_err(|e| format!("create {}: {e}", parent.display()))?; 50 } 51 let bytes = serde_json::to_vec_pretty(value) 52 .map_err(|e| format!("serialize {}: {e}", path.display()))?; 53 std::fs::write(path, bytes).map_err(|e| format!("write {}: {e}", path.display())) 54 } 55 56 /// Read and deserialize a JSON file. 57 pub fn read_json(path: &Path) -> Result { 58 let bytes = std::fs::read(path).map_err(|e| format!("read {}: {e}", path.display()))?; 59 serde_json::from_slice(&bytes).map_err(|e| format!("parse {}: {e}", path.display())) 60 } 61 62 /// Write one JSON object per line (JSONL) to `path`, creating parent directories. 63 pub fn write_jsonl(path: &Path, rows: &[T]) -> Result<(), String> { 64 if let Some(parent) = path.parent() { 65 std::fs::create_dir_all(parent).map_err(|e| format!("create {}: {e}", parent.display()))?; 66 } 67 let mut out = Vec::with_capacity(rows.len() * 160); 68 for row in rows { 69 serde_json::to_writer(&mut out, row) 70 .map_err(|e| format!("serialize trace row for {}: {e}", path.display()))?; 71 out.push(b'\n'); 72 } 73 std::fs::write(path, out).map_err(|e| format!("write {}: {e}", path.display())) 74 } 75 76 /// Convert a path to UTF-8 for use as a command-line argument. 77 pub fn path_str(path: &Path) -> Result<&str, String> { 78 path.to_str() 79 .ok_or_else(|| format!("path is not valid UTF-8: {}", path.display())) 80 } 81 82 /// Current wall-clock time in Unix milliseconds. 83 pub fn unix_now_ms() -> u64 { 84 std::time::SystemTime::now() 85 .duration_since(std::time::UNIX_EPOCH) 86 .map(|d| d.as_millis() as u64) 87 .unwrap_or(0) 88 } 89 90 /// Current UTC timestamp formatted as `YYYY-MM-DDTHH:MM:SSZ` (civil-from-days, no external crate). 91 pub fn utc_timestamp() -> String { 92 let secs = unix_now_ms() / 1000; 93 let days = (secs / 86_400) as i64; 94 let rem = secs % 86_400; 95 let (h, m, s) = (rem / 3600, (rem % 3600) / 60, rem % 60); 96 // Howard Hinnant's days-to-civil algorithm. 97 let z = days + 719_468; 98 let era = z.div_euclid(146_097); 99 let doe = z - era * 146_097; 100 let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365; 101 let y = yoe + era * 400; 102 let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); 103 let mp = (5 * doy + 2) / 153; 104 let d = doy - (153 * mp + 2) / 5 + 1; 105 let mo = if mp < 10 { mp + 3 } else { mp - 9 }; 106 let y = if mo <= 2 { y + 1 } else { y }; 107 format!("{y:04}-{mo:02}-{d:02}T{h:02}:{m:02}:{s:02}Z") 108 } 109 110 #[cfg(test)] 111 mod tests { 112 use super::*; 113 114 #[test] 115 fn utc_timestamp_has_iso_shape() { 116 let ts = utc_timestamp(); 117 assert_eq!(ts.len(), 20); 118 assert!(ts.ends_with('Z')); 119 assert_eq!(&ts[4..5], "-"); 120 assert_eq!(&ts[10..11], "T"); 121 } 122 }