diff --git a/Cargo.lock b/Cargo.lock index 1e7f67ad71..f266b9da5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,6 +805,7 @@ dependencies = [ "log", "merge", "metrics", + "metrics_events", "minijail", "net_util", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 7c7614ae71..b75fdfaa4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -462,6 +462,7 @@ libcras = "*" log = { version = "0", features = ["release_max_level_debug"]} merge = "0.1.0" metrics = { path = "metrics" } +metrics_events = { path = "metrics_events" } net_util = { path = "net_util" } once_cell = "1.7" protobuf = { version = "3.2", optional = true } diff --git a/metrics_events/src/event_types.rs b/metrics_events/src/event_types.rs index f1fde88c4f..c67523e493 100644 --- a/metrics_events/src/event_types.rs +++ b/metrics_events/src/event_types.rs @@ -49,6 +49,7 @@ pub enum MetricEventType { VirtioWakeup { virtio_id: u32, }, + VcpuShutdownError, Other(i64), Vendor(VendorMetricEventType), } diff --git a/src/crosvm/sys/linux/vcpu.rs b/src/crosvm/sys/linux/vcpu.rs index 5999d3776e..4a80280ade 100644 --- a/src/crosvm/sys/linux/vcpu.rs +++ b/src/crosvm/sys/linux/vcpu.rs @@ -35,6 +35,7 @@ use hypervisor::IoParams; use hypervisor::VcpuExit; use hypervisor::VcpuSignalHandle; use libc::c_int; +use metrics_events::MetricEventType; #[cfg(target_arch = "riscv64")] use riscv64::Riscv64 as Arch; #[cfg(target_arch = "x86_64")] @@ -389,7 +390,15 @@ where } Ok(VcpuExit::IrqWindowOpen) => {} Ok(VcpuExit::Hlt) => irq_chip.halted(cpu_id), - Ok(VcpuExit::Shutdown(_)) => return ExitState::Stop, + Ok(VcpuExit::Shutdown(reason)) => { + if let Err(e) = reason { + metrics::log_descriptor( + MetricEventType::VcpuShutdownError, + e.get_raw_error_code() as i64, + ); + } + return ExitState::Stop; + } Ok(VcpuExit::FailEntry { hardware_entry_failure_reason, }) => { diff --git a/src/sys/windows/run_vcpu.rs b/src/sys/windows/run_vcpu.rs index 3934dc59c2..44d0665d12 100644 --- a/src/sys/windows/run_vcpu.rs +++ b/src/sys/windows/run_vcpu.rs @@ -66,6 +66,7 @@ use hypervisor::IoOperation; use hypervisor::IoParams; use hypervisor::VcpuExit; use hypervisor::VcpuInitX86_64; +use metrics_events::MetricEventType; use sync::Condvar; use sync::Mutex; use vm_control::VcpuControl; @@ -832,6 +833,12 @@ where // with Shutdown. Normal reboots and shutdowns, like window close, use // the vm event tube and VmRunMode::Exiting instead of VcpuExit::Shutdown. Ok(VcpuExit::Shutdown(reason)) => { + if let Err(e) = reason { + metrics::log_descriptor( + MetricEventType::VcpuShutdownError, + e.get_raw_error_code() as i64, + ); + } bail_exit_code!(Exit::VcpuShutdown, "vcpu shutdown (reason: {:?})", reason) } Ok(VcpuExit::FailEntry {