mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-15 08:02:31 +00:00
Merge pull request #4081 from fidencio/wip/stable-2.4-agent-avoid-panic-when-getting-empty-stats
stable-2.4 | agent: Avoid agent panic when reading empty stats
This commit is contained in:
commit
10bab3c96a
@ -590,9 +590,9 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField<CpuUsage> {
|
|||||||
|
|
||||||
let h = lines_to_map(&cpuacct.stat);
|
let h = lines_to_map(&cpuacct.stat);
|
||||||
let usage_in_usermode =
|
let usage_in_usermode =
|
||||||
(((*h.get("user").unwrap() * NANO_PER_SECOND) as f64) / *CLOCK_TICKS) as u64;
|
(((*h.get("user").unwrap_or(&0) * NANO_PER_SECOND) as f64) / *CLOCK_TICKS) as u64;
|
||||||
let usage_in_kernelmode =
|
let usage_in_kernelmode =
|
||||||
(((*h.get("system").unwrap() * NANO_PER_SECOND) as f64) / *CLOCK_TICKS) as u64;
|
(((*h.get("system").unwrap_or(&0) * NANO_PER_SECOND) as f64) / *CLOCK_TICKS) as u64;
|
||||||
|
|
||||||
let total_usage = cpuacct.usage;
|
let total_usage = cpuacct.usage;
|
||||||
|
|
||||||
@ -623,9 +623,9 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField<CpuUsage> {
|
|||||||
let cpu_controller: &CpuController = get_controller_or_return_singular_none!(cg);
|
let cpu_controller: &CpuController = get_controller_or_return_singular_none!(cg);
|
||||||
let stat = cpu_controller.cpu().stat;
|
let stat = cpu_controller.cpu().stat;
|
||||||
let h = lines_to_map(&stat);
|
let h = lines_to_map(&stat);
|
||||||
let usage_in_usermode = *h.get("user_usec").unwrap();
|
let usage_in_usermode = *h.get("user_usec").unwrap_or(&0);
|
||||||
let usage_in_kernelmode = *h.get("system_usec").unwrap();
|
let usage_in_kernelmode = *h.get("system_usec").unwrap_or(&0);
|
||||||
let total_usage = *h.get("usage_usec").unwrap();
|
let total_usage = *h.get("usage_usec").unwrap_or(&0);
|
||||||
let percpu_usage = vec![];
|
let percpu_usage = vec![];
|
||||||
|
|
||||||
SingularPtrField::some(CpuUsage {
|
SingularPtrField::some(CpuUsage {
|
||||||
|
Loading…
Reference in New Issue
Block a user