benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / src / harness / smaps.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use std::fs; |
| 17 | |
| 18 | #[derive(Debug, Clone, Copy, Default)] |
| 19 | pub struct ProcessMemorySnapshot { |
| 20 | pub rss_kb: u64, |
| 21 | pub pss_kb: u64, |
| 22 | pub pss_dirty_kb: u64, |
| 23 | pub private_dirty_kb: u64, |
| 24 | pub shared_clean_kb: u64, |
| 25 | } |
| 26 | |
| 27 | impl ProcessMemorySnapshot { |
| 28 | pub fn rss_mb(&self) -> f64 { |
| 29 | self.rss_kb as f64 / 1024.0 |
| 30 | } |
| 31 | pub fn pss_mb(&self) -> f64 { |
| 32 | self.pss_kb as f64 / 1024.0 |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | pub fn read_smaps_rollup(pid: u32) -> Option<ProcessMemorySnapshot> { |
| 37 | let path = format!("/proc/{}/smaps_rollup", pid); |
| 38 | let content = fs::read_to_string(&path).ok()?; |
| 39 | let mut snap = ProcessMemorySnapshot::default(); |
| 40 | for line in content.lines() { |
| 41 | if let Some(rest) = line.strip_prefix("Rss:") { |
| 42 | snap.rss_kb = parse_kb(rest); |
| 43 | } else if let Some(rest) = line.strip_prefix("Pss:") { |
| 44 | snap.pss_kb = parse_kb(rest); |
| 45 | } else if let Some(rest) = line.strip_prefix("Pss_Dirty:") { |
| 46 | snap.pss_dirty_kb = parse_kb(rest); |
| 47 | } else if let Some(rest) = line.strip_prefix("Private_Dirty:") { |
| 48 | snap.private_dirty_kb = parse_kb(rest); |
| 49 | } else if let Some(rest) = line.strip_prefix("Shared_Clean:") { |
| 50 | snap.shared_clean_kb = parse_kb(rest); |
| 51 | } |
| 52 | } |
| 53 | Some(snap) |
| 54 | } |
| 55 | |
| 56 | fn parse_kb(s: &str) -> u64 { |
| 57 | s.split_whitespace() |
| 58 | .next() |
| 59 | .and_then(|v| v.parse::<u64>().ok()) |
| 60 | .unwrap_or(0) |
| 61 | } |
| 62 | |
| 63 | pub fn get_process_tree_pids(root_pid: u32) -> Vec<u32> { |
| 64 | let mut pids = vec![root_pid]; |
| 65 | let mut queue = vec![root_pid]; |
| 66 | while let Some(parent) = queue.pop() { |
| 67 | let task_dir = format!("/proc/{}/task", parent); |
| 68 | if let Ok(entries) = fs::read_dir(task_dir) { |
| 69 | for entry in entries.flatten() { |
| 70 | let children_path = entry.path().join("children"); |
| 71 | if let Ok(content) = fs::read_to_string(children_path) { |
| 72 | for child_str in content.split_whitespace() { |
| 73 | if let Ok(child_pid) = child_str.parse::<u32>() { |
| 74 | if !pids.contains(&child_pid) { |
| 75 | pids.push(child_pid); |
| 76 | queue.push(child_pid); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | pids |
| 85 | } |
| 86 | |
| 87 | pub fn read_process_tree_smaps(root_pid: u32) -> Option<ProcessMemorySnapshot> { |
| 88 | let pids = get_process_tree_pids(root_pid); |
| 89 | let mut total = ProcessMemorySnapshot::default(); |
| 90 | let mut found_any = false; |
| 91 | for pid in pids { |
| 92 | if let Some(snap) = read_smaps_rollup(pid) { |
| 93 | total.rss_kb += snap.rss_kb; |
| 94 | total.pss_kb += snap.pss_kb; |
| 95 | total.pss_dirty_kb += snap.pss_dirty_kb; |
| 96 | total.private_dirty_kb += snap.private_dirty_kb; |
| 97 | total.shared_clean_kb += snap.shared_clean_kb; |
| 98 | found_any = true; |
| 99 | } |
| 100 | } |
| 101 | if found_any { |
| 102 | Some(total) |
| 103 | } else { |
| 104 | None |
| 105 | } |
| 106 | } |