From 9eccfc99f157f59db0b9fb204c37f55656a0bb08 Mon Sep 17 00:00:00 2001 From: Junichi Uekawa Date: Thu, 19 Oct 2023 17:16:31 +0900 Subject: [PATCH] crosvm: tools: contrib: Improve output slightly. Output related information closer together instead of in random order, it was impossible to see what lines are related information because of multithreading. Output becomes like: pcivirtio-fs 22356 private_dirty: 0 MB rss: 1020 MB VmPTE: 172 KiB 22356:pcivirtio-fs 22417:v_fs:_data:0 22418:v_fs:_data:1 BUG=None TEST=cargo run ${DUT} Change-Id: Ie922382f0ad8ad9d2ec8a57c4a209177fdc43be6 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4954555 Reviewed-by: Keiichi Watanabe Commit-Queue: Junichi Uekawa --- tools/contrib/crosvmdump/src/main.rs | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/contrib/crosvmdump/src/main.rs b/tools/contrib/crosvmdump/src/main.rs index 8fd943da6a..3c5dd517a8 100644 --- a/tools/contrib/crosvmdump/src/main.rs +++ b/tools/contrib/crosvmdump/src/main.rs @@ -132,18 +132,18 @@ fn find_block_fds(proc_fd: &str) -> Vec { .collect() } -fn parse_fd_blocks(target: &Target, who: &str, pid: u32) -> Result<()> { +fn parse_fd_blocks(target: &Target, who: &str, pid: u32) -> Result { let lines = target .do_command(vec!["ls", "-l", &format!("/proc/{}/fd/", pid)]) .context("ls -l for proc/fd")?; let block_fds = find_block_fds(&lines); - block_fds.par_iter().for_each(|block_fd| { + let message = block_fds.par_iter().map(|block_fd| { let fdinfo = target.get_file(&format!("/proc/{}/fdinfo/{}", pid, block_fd.fd)).expect("/proc/fdinfo"); let flags = u32::from_str_radix(parse_proc_fdinfo_flags(&fdinfo), 8).expect("octal"); let fincore = target.do_fincore(&vec![block_fd.path.to_string()]).unwrap(); assert_eq!(fincore.len(), 1); - println!( + format!( "{} {} {} flags: {:o} o_direct on x86_64 {}, o_direct on arm {} page cache: {} MB / {} MB", who, block_fd.path, @@ -153,9 +153,9 @@ fn parse_fd_blocks(target: &Target, who: &str, pid: u32) -> Result<()> { (flags & 0o200000) != 0, fincore[0].0 >> 20, fincore[0].1 >> 20, - ); - }); - Ok(()) + ) + }).collect::>().join("\n"); + Ok(message) } fn parse_proc_fdinfo_flags(proc_fdinfo: &str) -> &str { @@ -169,7 +169,7 @@ fn parse_proc_fdinfo_flags(proc_fdinfo: &str) -> &str { lines["flags"] } -fn parse_virtio_fs(target: &Target, pid: u32) -> Result<()> { +fn parse_virtio_fs(target: &Target, pid: u32) -> Result { let lines = target.do_command(vec!["ls", "-1", &format!("/proc/{}/task/", pid)])?; let task_pids: Vec<_> = lines.lines().map(|x| x.parse::().unwrap()).collect(); let pid_name_pairs: Vec<_> = task_pids @@ -187,8 +187,7 @@ fn parse_virtio_fs(target: &Target, pid: u32) -> Result<()> { .map(|(task_pid, comm)| format!("{}:{}", task_pid, comm)) .collect::>() .join(" "); - println!("virtio-fs {}", message); - Ok(()) + Ok(message) } fn main() -> Result<()> { @@ -292,22 +291,23 @@ fn main() -> Result<()> { .get_file(&format!("/proc/{}/status", child_pid)) .unwrap(); let vmpte_kb = parse_status(&status_text).unwrap()["VmPTE:"]; + let message = match task_name.as_str() { + "pcivirtio-block" => parse_fd_blocks(&target, "virtio-block", *child_pid), + "pcivirtio-fs" => parse_virtio_fs(&target, *child_pid), + _ => Ok("".to_string()), + } + .unwrap(); + // output in MBs. println!( - "{} {} private_dirty: {} MB rss: {} MB VmPTE: {} KiB", + "{} {} private_dirty: {} MB rss: {} MB VmPTE: {} KiB\n {}", task_name, child_pid, dirty >> 20, rss >> 20, vmpte_kb, + message ); - - match task_name.as_str() { - "pcivirtio-block" => parse_fd_blocks(&target, "virtio-block", *child_pid), - "pcivirtio-fs" => parse_virtio_fs(&target, *child_pid), - _ => Ok(()), - } - .unwrap(); }); let balloon_stat_json = target.do_command(vec!["crosvm", "balloon_stats", socket])?;