Skip to content

Commit

Permalink
Optimize IP address formatting and refactor CPU steal time calculatio…
Browse files Browse the repository at this point in the history
…n in geph5-bridge
  • Loading branch information
nullchinchilla committed Jul 21, 2024
1 parent b6d8b05 commit 3cfb49f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions binaries/geph5-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn broker_upload_loop(control_listen: SocketAddr, control_cookie: String)
.split_ascii_whitespace()
.next()
.unwrap(),
control_listen.ip().to_string().replace(".", "-")
control_listen.ip().to_string().replace('.', "-")
);

let broker_rpc =
Expand All @@ -86,8 +86,21 @@ async fn broker_upload_loop(control_listen: SocketAddr, control_cookie: String)
}));
loop {
let steal_time: f64 = {
let output = Command::new("bash").arg("c").arg(r#"steal() { cat /proc/stat | grep '^cpu ' | awk '{print $9}'; }; s1=$(steal); sleep 1; s2=$(steal); echo "scale=2; ($s2 - $s1) / 100" | bc"#).output().await.unwrap().stdout;
String::from_utf8_lossy(&output).parse().unwrap()
async fn get_steal() -> u64 {
let output = Command::new("bash")
.arg("-c")
.arg("cat /proc/stat | grep '^cpu ' | awk '{print $9}'")
.output()
.await
.unwrap()
.stdout;
String::from_utf8_lossy(&output).trim().parse().unwrap()
}

let s1 = get_steal().await;
smol::Timer::after(Duration::from_secs(1)).await;
let s2 = get_steal().await;
(s2 as f64 - s1 as f64) / 100.0
};
// if steal_time > 0.3 {
// Command::new("reboot").status().await.unwrap();
Expand Down

0 comments on commit 3cfb49f

Please sign in to comment.