Getting CPU guest time & RSS again sooner when zero value is measured
Bug: 396613989
Bug: 395981347
Test: atest MicrodroidHostTestCases:com.android.microdroid.test.MicrodroidHostTests#testTelemetryPushedAtoms_protectedVm_false_os_microdroid --iterations 10
Change-Id: If146d412d82c877c1aed472df4a6d8410c931652
diff --git a/android/virtmgr/src/crosvm.rs b/android/virtmgr/src/crosvm.rs
index 9ee181a..77710c3 100644
--- a/android/virtmgr/src/crosvm.rs
+++ b/android/virtmgr/src/crosvm.rs
@@ -21,7 +21,7 @@
use binder::ParcelFileDescriptor;
use command_fds::CommandFdExt;
use libc::{sysconf, _SC_CLK_TCK};
-use log::{debug, error, info};
+use log::{debug, error, info, warn};
use semver::{Version, VersionReq};
use nix::{fcntl::OFlag, unistd::pipe2, unistd::Uid, unistd::User};
use regex::{Captures, Regex};
@@ -649,7 +649,7 @@
Ok(guest_time) => vm_metric.cpu_guest_time = Some(guest_time),
Err(e) => {
metric_countdown = 0;
- error!("Failed to get guest CPU time: {e:?}");
+ warn!("Failed to get guest CPU time: {}", e);
}
}
@@ -663,7 +663,7 @@
}
Err(e) => {
metric_countdown = 0;
- error!("Failed to get guest RSS: {}", e);
+ warn!("Failed to get guest RSS: {}", e);
}
}
}
@@ -857,6 +857,9 @@
}
let guest_time_ticks = data_list[42].parse::<i64>()?;
+ if guest_time_ticks == 0 {
+ bail!("zero value is measured on elapsed CPU guest_time");
+ }
// SAFETY: It just returns an integer about CPU tick information.
let ticks_per_sec = unsafe { sysconf(_SC_CLK_TCK) };
Ok(guest_time_ticks * MILLIS_PER_SEC / ticks_per_sec)
@@ -887,7 +890,12 @@
rss_crosvm_total += rss;
}
}
-
+ if rss_crosvm_total == 0 {
+ bail!("zero value is measured on RSS of crosvm");
+ }
+ if rss_vm_total == 0 {
+ bail!("zero value is measured on RSS of VM");
+ }
Ok(Rss { vm: rss_vm_total, crosvm: rss_crosvm_total })
}