mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
ci: Parse the smaps file with Rust
Instead of using bash and awk, using Rust allows us to retrieve information about a VM process with the right permissions as we are not forced to spawn a new child process. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
bdb7bcdbe3
commit
ac118c9924
31
src/main.rs
31
src/main.rs
@ -414,6 +414,8 @@ mod tests {
|
||||
#![allow(dead_code)]
|
||||
use ssh2::Session;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::BufRead;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::process::{Command, Stdio};
|
||||
@ -3046,23 +3048,20 @@ mod tests {
|
||||
}
|
||||
|
||||
fn get_pss(pid: u32) -> u32 {
|
||||
let output = Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(
|
||||
format!(
|
||||
"cat /proc/{}/smaps | grep -i pss | awk '{{Total+=$2}} END {{print Total}}'",
|
||||
pid
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.output()
|
||||
.unwrap();
|
||||
let smaps = fs::File::open(format!("/proc/{}/smaps", pid)).unwrap();
|
||||
let reader = io::BufReader::new(smaps);
|
||||
|
||||
std::str::from_utf8(output.stdout.as_slice())
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap()
|
||||
let mut total = 0;
|
||||
for line in reader.lines() {
|
||||
let l = line.unwrap();
|
||||
// Lines look like this:
|
||||
// Pss: 176 kB
|
||||
if l.contains("Pss") {
|
||||
let values: Vec<&str> = l.rsplit(' ').collect();
|
||||
total += values[1].trim().parse::<u32>().unwrap()
|
||||
}
|
||||
}
|
||||
total
|
||||
}
|
||||
|
||||
fn test_memory_mergeable(mergeable: bool) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user