From: Rishabh Choudhary (rishacho) Date: Mon, 29 Jul 2024 05:54:00 +0000 (+0000) Subject: Pull request #4396: main: fix coverage for show snort cpu command X-Git-Tag: 3.3.2.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06eba8dda3d1ceb5d8800e8cd17e1600ab6be170;p=thirdparty%2Fsnort3.git Pull request #4396: main: fix coverage for show snort cpu command Merge in SNORT/snort3 from ~RISHACHO/snort3:cpu_usage_snort to master Squashed commit of the following: commit c8dcd376b5fe4a0e6a53eb31731badfe490885b8 Author: Rishabh Choudhary Date: Wed Jul 24 13:19:46 2024 +0530 main: fix coverage Replace an impossible condition with assert statement. --- diff --git a/src/main/analyzer_command.cc b/src/main/analyzer_command.cc index 77a6952cb..daa5ff03b 100644 --- a/src/main/analyzer_command.cc +++ b/src/main/analyzer_command.cc @@ -277,20 +277,18 @@ ACShowSnortCPU::~ACShowSnortCPU() if (DAQ_SUCCESS == status) { LogRespond(ctrlcon, "\nSummary \t%.1f%% \t%.1f%% \t%.1f%%\n", - cpu_usage_30s/instance_num, - cpu_usage_120s/instance_num, - cpu_usage_300s/instance_num); + cpu_usage_30s/instance_num, cpu_usage_120s/instance_num, + cpu_usage_300s/instance_num); } } bool ACShowSnortCPU::execute(Analyzer& analyzer, void**) { DIOCTL_GetCpuProfileData get_data = {}; - do + { std::lock_guard lock(cpu_usage_mutex); - if (DAQ_SUCCESS != status) - break; + assert(DAQ_SUCCESS == status); SFDAQInstance* instance = get_daq_instance(analyzer); ThreadConfig *thread_config = SnortConfig::get_conf()->thread_config; @@ -304,24 +302,24 @@ bool ACShowSnortCPU::execute(Analyzer& analyzer, void**) if (DAQ_SUCCESS != status) { LogRespond(ctrlcon, "Fetching profile data failed from DAQ instance\n"); - break; + return true; } + double cpu_30s = static_cast (get_data.cpu_usage_percent_30s); + double cpu_120s = static_cast (get_data.cpu_usage_percent_120s); + double cpu_300s = static_cast (get_data.cpu_usage_percent_300s); + // Print CPU usage LogRespond(ctrlcon, "%-3d \t%-6d \t%.1f%% \t%.1f%% \t%.1f%%\n", - instance_num, - tid, - get_data.cpu_usage_percent_30s, - get_data.cpu_usage_percent_120s, - get_data.cpu_usage_percent_300s); + instance_num, tid, cpu_30s, cpu_120s, cpu_300s); // Add CPU usage data - cpu_usage_30s += get_data.cpu_usage_percent_30s; - cpu_usage_120s += get_data.cpu_usage_percent_120s; - cpu_usage_300s += get_data.cpu_usage_percent_300s; + cpu_usage_30s += cpu_30s; + cpu_usage_120s += cpu_120s; + cpu_usage_300s += cpu_300s; instance_num++; - } while (0); + } return true; } diff --git a/src/main/analyzer_command.h b/src/main/analyzer_command.h index b54438d03..45b7e9e58 100644 --- a/src/main/analyzer_command.h +++ b/src/main/analyzer_command.h @@ -218,9 +218,9 @@ public: private: int status = DAQ_SUCCESS; - float cpu_usage_30s = 0.0; - float cpu_usage_120s = 0.0; - float cpu_usage_300s = 0.0; + double cpu_usage_30s = 0.0; + double cpu_usage_120s = 0.0; + double cpu_usage_300s = 0.0; int instance_num = 0; std::mutex cpu_usage_mutex; };