interplane.Get Omega
Read in your language

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

branch main Branches Tags History

benchmarks-mv / src / harness / memory.rs

81 lines · 2718 bytes Raw Blame History
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
16use std::fs;
17use std::process::Command;
18
19pub fn read_process_rss_mb(pid: u32) -> Option<f64> {
20 // 1. Check Linux /proc/<pid>/status
21 let status_path = format!("/proc/{}/status", pid);
22 if let Ok(content) = fs::read_to_string(&status_path) {
23 for line in content.lines() {
24 if line.starts_with("VmRSS:") {
25 let parts: Vec<&str> = line.split_whitespace().collect();
26 if parts.len() >= 2 {
27 if let Ok(kb) = parts[1].parse::<f64>() {
28 return Some(kb / 1024.0);
29 }
30 }
31 }
32 }
33 }
34
35 // 2. Fallback to `ps -o rss= -p <pid>`
36 if let Ok(output) = Command::new("ps")
37 .args(["-o", "rss=", "-p", &pid.to_string()])
38 .output()
39 {
40 let text = String::from_utf8_lossy(&output.stdout).trim().to_string();
41 if let Ok(kb) = text.parse::<f64>() {
42 return Some(kb / 1024.0);
43 }
44 }
45
46 None
47}
48
49pub fn find_pid_by_pattern(pattern: &str) -> Option<u32> {
50 // Try pgrep
51 if let Ok(output) = Command::new("pgrep").args(["-f", pattern]).output() {
52 let text = String::from_utf8_lossy(&output.stdout);
53 for line in text.lines() {
54 if let Ok(pid) = line.trim().parse::<u32>() {
55 if pid != std::process::id() {
56 return Some(pid);
57 }
58 }
59 }
60 }
61
62 // Fallback: scan /proc
63 if let Ok(entries) = fs::read_dir("/proc") {
64 for entry in entries.flatten() {
65 let name = entry.file_name();
66 if let Ok(pid) = name.to_string_lossy().parse::<u32>() {
67 if pid == std::process::id() {
68 continue;
69 }
70 let cmdline_path = format!("/proc/{}/cmdline", pid);
71 if let Ok(cmdline) = fs::read_to_string(&cmdline_path) {
72 if cmdline.contains(pattern) {
73 return Some(pid);
74 }
75 }
76 }
77 }
78 }
79
80 None
81}