MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resources

Function resources

atomic-cli/src/commands/git/rolling_dashboard.rs:44–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43#[cfg(any(target_os = "macos", target_os = "linux"))]
44fn resources() -> Resources {
45 let rss = std::process::Command::new("ps")
46 .args(["-o", "rss=", "-p", &std::process::id().to_string()])
47 .output()
48 .ok()
49 .filter(|output| output.status.success())
50 .and_then(|output| String::from_utf8(output.stdout).ok())
51 .and_then(|text| text.trim().parse::<u64>().ok())
52 .and_then(|kib| kib.checked_mul(1024));
53 let mut usage = std::mem::MaybeUninit::<libc::rusage>::uninit();
54 // SAFETY: getrusage initializes the output on success.
55 if unsafe { libc::getrusage(libc::RUSAGE_SELF, usage.as_mut_ptr()) } != 0 {
56 return Resources {
57 rss,
58 ..Resources::default()
59 };
60 }
61 // SAFETY: getrusage succeeded above.
62 let usage = unsafe { usage.assume_init() };
63 #[cfg(target_os = "macos")]
64 let peak_rss = usage.ru_maxrss as u64;
65 #[cfg(target_os = "linux")]
66 let peak_rss = (usage.ru_maxrss as u64).saturating_mul(1024);
67 let seconds = |time: libc::timeval| time.tv_sec as f64 + time.tv_usec as f64 / 1_000_000.0;
68 Resources {
69 rss,
70 peak_rss: Some(peak_rss),
71 cpu_seconds: Some(seconds(usage.ru_utime) + seconds(usage.ru_stime)),
72 }
73}
74
75#[cfg(not(any(target_os = "macos", target_os = "linux")))]
76fn resources() -> Resources {

Callers 1

startMethod · 0.85

Calls 3

successMethod · 0.80
okMethod · 0.45
outputMethod · 0.45

Tested by

no test coverage detected