From 34708248cea4a09def2fd4366e1f1d80571faadf Mon Sep 17 00:00:00 2001 From: kobayu858 <129580202+kobayu858@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:45:14 +0900 Subject: [PATCH] fix(system_monitor): fix variableScope (#8448) fix:variableScope Signed-off-by: kobayu858 --- .../src/cpu_monitor/cpu_monitor_base.cpp | 17 +++++++++-------- .../src/process_monitor/process_monitor.cpp | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/system_monitor/src/cpu_monitor/cpu_monitor_base.cpp b/system/system_monitor/src/cpu_monitor/cpu_monitor_base.cpp index b5e0e51c0ceaf..13d7151bb14c7 100644 --- a/system/system_monitor/src/cpu_monitor/cpu_monitor_base.cpp +++ b/system/system_monitor/src/cpu_monitor/cpu_monitor_base.cpp @@ -175,14 +175,6 @@ void CPUMonitorBase::checkUsage(diagnostic_updater::DiagnosticStatusWrapper & st return; } - std::string cpu_name; - float usr{0.0}; - float nice{0.0}; - float sys{0.0}; - float iowait{0.0}; - float idle{0.0}; - float usage{0.0}; - float total{0.0}; int level = DiagStatus::OK; int whole_level = DiagStatus::OK; @@ -203,6 +195,15 @@ void CPUMonitorBase::checkUsage(diagnostic_updater::DiagnosticStatusWrapper & st CpuStatus cpu_status; + std::string cpu_name; + float usr{0.0}; + float nice{0.0}; + float sys{0.0}; + float iowait{0.0}; + float idle{0.0}; + float usage{0.0}; + float total{0.0}; + if (boost::optional v = cpu_load.get_optional("cpu")) { cpu_name = v.get(); get_cpu_name = true; diff --git a/system/system_monitor/src/process_monitor/process_monitor.cpp b/system/system_monitor/src/process_monitor/process_monitor.cpp index 2ab3e053225eb..73059d2d162fa 100644 --- a/system/system_monitor/src/process_monitor/process_monitor.cpp +++ b/system/system_monitor/src/process_monitor/process_monitor.cpp @@ -127,8 +127,6 @@ void ProcessMonitor::getTasksSummary( } bp::pipe p{p_fd[0], p_fd[1]}; - std::string line; - // Echo output for grep { int out_fd[2]; @@ -179,6 +177,7 @@ void ProcessMonitor::getTasksSummary( return; } + std::string line; std::getline(is_out, line); std::cmatch match; const std::regex filter(