]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4388: appid: fixing cppcheck warnings and cosmetic changes for appid...
authorUmang Sharma (umasharm) <umasharm@cisco.com>
Thu, 18 Jul 2024 21:41:35 +0000 (21:41 +0000)
committerChris Sherwin (chsherwi) <chsherwi@cisco.com>
Thu, 18 Jul 2024 21:41:35 +0000 (21:41 +0000)
Merge in SNORT/snort3 from ~UMASHARM/snort3:fix_appid_cpu_profiling to master

Squashed commit of the following:

commit 308fce8ec5298d01be29061c8a83198267160aed
Author: Umang Sharma <umasharm@cisco.com>
Date:   Wed Jul 17 13:27:58 2024 -0400

    appid: removing trailing whitespaces

commit 83f46dc9249f9ca2a7ff0d84feb5fb14e11494ef
Author: Umang Sharma <umasharm@cisco.com>
Date:   Tue Jul 16 10:36:12 2024 -0400

    appid: fixing cpp warnings and cosmetic changes for appid cpu profiler

src/network_inspectors/appid/appid_cpu_profile_table.cc
src/network_inspectors/appid/appid_cpu_profile_table.h
src/network_inspectors/appid/appid_module.cc

index 6e0d154e02ba81948a32bd6823af069c3f63f286..b5e97b5a447fd0ccc5f3c9af9c646e3740f963b1 100644 (file)
@@ -45,7 +45,7 @@ static std::string FormatWithCommas(uint64_t value)
 {
     std::string numStr = std::to_string(value);
     int insertPosition = numStr.length() - 3;
-    while (insertPosition > 0) 
+    while (insertPosition > 0)
     {
         numStr.insert(insertPosition, ",");
         insertPosition -= 3;
@@ -111,10 +111,10 @@ AppidCpuTableDisplayStatus AppidCPUProfilingManager::display_appid_cpu_profiler_
         print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, partition);
 
         print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, " %5d   %-15.15s   %14.14s %10.10s  %15.14s  %11.11s  %16.14s  %15.14s   %15.14s  %10.2f\n",
-                appid, bucket->second.app_name.c_str(), FormatWithCommas(bucket->second.processing_time).c_str(), FormatWithCommas(bucket->second.processed_packets).c_str(), 
-                FormatWithCommas(bucket->second.processing_time/bucket->second.processed_packets).c_str(), FormatWithCommas(bucket->second.per_appid_sessions).c_str(), 
-                FormatWithCommas(bucket->second.processing_time/bucket->second.per_appid_sessions).c_str(), FormatWithCommas(bucket->second.max_processed_pkts_per_session).c_str(), 
-                FormatWithCommas(bucket->second.max_processing_time_per_session).c_str(), static_cast<float>(bucket->second.processing_time)/static_cast<float>(total_processing_time)*100);
+                appid, bucket->second.app_name.c_str(), FormatWithCommas(bucket->second.processing_time).c_str(), FormatWithCommas(bucket->second.processed_packets).c_str(),
+                FormatWithCommas(bucket->second.processing_time/bucket->second.processed_packets).c_str(), FormatWithCommas(bucket->second.per_appid_sessions).c_str(),
+                FormatWithCommas(bucket->second.processing_time/bucket->second.per_appid_sessions).c_str(), FormatWithCommas(bucket->second.max_processed_pkts_per_session).c_str(),
+                FormatWithCommas(bucket->second.max_processing_time_per_session).c_str(), static_cast<double>(bucket->second.processing_time) / total_processing_time * 100.0);
     }
     else
     {
@@ -134,7 +134,7 @@ AppidCpuTableDisplayStatus AppidCPUProfilingManager::display_appid_cpu_profiler_
 
     std::priority_queue<std::pair<AppId, AppidCPUProfilerStats>, std::vector<std::pair<AppId, AppidCPUProfilerStats>>, CompareByAvgProcessingTime> sorted_appid_cpu_profiler_table;
 
-    for (const auto& entry : appid_cpu_profiling_table) 
+    for (const auto& entry : appid_cpu_profiling_table)
         sorted_appid_cpu_profiler_table.push(entry);
 
     if (ctrlcon)
@@ -144,7 +144,7 @@ AppidCpuTableDisplayStatus AppidCPUProfilingManager::display_appid_cpu_profiler_
     print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, TABLE_HEADER(display_rows_limit));
     print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, columns);
     print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, partition);
-    
+
     uint32_t rows_displayed = 0;
 
     while (!sorted_appid_cpu_profiler_table.empty() and rows_displayed < display_rows_limit)
@@ -153,15 +153,15 @@ AppidCpuTableDisplayStatus AppidCPUProfilingManager::display_appid_cpu_profiler_
         sorted_appid_cpu_profiler_table.pop();
         if (!entry.second.processed_packets or !entry.second.per_appid_sessions)
             continue;
-            
+
         print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, " %5d   %-15.15s   %14.14s %10.10s  %15.14s  %11.11s  %16.14s  %15.14s   %15.14s  %10.2f\n",
-                entry.first, entry.second.app_name.c_str(), FormatWithCommas(entry.second.processing_time).c_str(), FormatWithCommas(entry.second.processed_packets).c_str(), 
-                FormatWithCommas(entry.second.processing_time/entry.second.processed_packets).c_str(), FormatWithCommas(entry.second.per_appid_sessions).c_str(), 
+                entry.first, entry.second.app_name.c_str(), FormatWithCommas(entry.second.processing_time).c_str(), FormatWithCommas(entry.second.processed_packets).c_str(),
+                FormatWithCommas(entry.second.processing_time/entry.second.processed_packets).c_str(), FormatWithCommas(entry.second.per_appid_sessions).c_str(),
                 FormatWithCommas(entry.second.processing_time/entry.second.per_appid_sessions).c_str(), FormatWithCommas(entry.second.max_processed_pkts_per_session).c_str(),
-                FormatWithCommas(entry.second.max_processing_time_per_session).c_str(), static_cast<float>(entry.second.processing_time)/static_cast<float>(total_processing_time)*100);
+                FormatWithCommas(entry.second.max_processing_time_per_session).c_str(), static_cast<double>(entry.second.processing_time) / total_processing_time * 100.0);
 
         rows_displayed += 1;
-    } 
+    }
 
     print_log(ctrlcon, output_type, TRACE_INFO_LEVEL, partition);
 
@@ -174,7 +174,7 @@ AppidCpuTableDisplayStatus AppidCPUProfilingManager::display_appid_cpu_profiler_
 }
 
 void AppidCPUProfilingManager::cleanup_appid_cpu_profiler_table()
-{ 
+{
     std::lock_guard<std::mutex> lock(appid_cpu_profiler_mutex);
     appid_cpu_profiling_table.clear();
     total_processing_time = 0;
@@ -200,11 +200,11 @@ void AppidCPUProfilingManager::insert_appid_cpu_profiler_record(AppId appId, con
     std::lock_guard<std::mutex> lock(appid_cpu_profiler_mutex);
 
     auto it = appid_cpu_profiling_table.find(appId);
-    if (it == appid_cpu_profiling_table.end()) 
+    if (it == appid_cpu_profiling_table.end())
     {
         appid_cpu_profiling_table.emplace(appId, stats);
     }
-    else 
+    else
     {
         it->second.processing_time += stats.processing_time;
         it->second.processed_packets += stats.processed_packets;
@@ -223,7 +223,7 @@ void AppidCPUProfilingManager::check_appid_cpu_profiler_table_entry(const AppIdS
     if (payload_id > APP_ID_NONE)
     {
         const char* app_name = asd->get_odp_ctxt().get_app_info_mgr().get_app_name(payload_id);
-        if (app_name == nullptr) 
+        if (app_name == nullptr)
             app_name = "unknown";
 
         stats_bucket_insert(payload_id, app_name, asd->stats.prev_payload_processing_time, asd->stats.prev_payload_processing_packets);
@@ -237,7 +237,7 @@ void AppidCPUProfilingManager::stats_bucket_insert(AppId appid, const char* app_
         appid_log(nullptr, TRACE_INFO_LEVEL, "appid: processed packets/time are NULL for appid : %d , app_name : %s , processing time :%lu \n", appid, app_name, processing_time);
         return;
     }
-        
+
     AppidCPUProfilerStats stats(app_name, processing_time, processed_packets, 1);
     insert_appid_cpu_profiler_record(appid, stats);
 }
@@ -270,7 +270,7 @@ void AppidCPUProfilingManager::check_appid_cpu_profiler_table_entry(const AppIdS
 
         stats_bucket_insert(payload_id, app_name, asd->stats.processing_time - asd->stats.prev_payload_processing_time, asd->stats.cpu_profiler_pkt_count - asd->stats.prev_payload_processing_packets);
     }
-    if (misc_id > APP_ID_NONE and misc_id != service_id and misc_id != client_id and misc_id != payload_id) 
+    if (misc_id > APP_ID_NONE and misc_id != service_id and misc_id != client_id and misc_id != payload_id)
     {
         const char* app_name = asd->get_odp_ctxt().get_app_info_mgr().get_app_name(misc_id);
         if (app_name == nullptr)
index ab0f3aa632db1041f2507ea5a4d21f3f88164de9..a0e84b509b0c1372b33b12f27443ca6444916387 100644 (file)
@@ -57,7 +57,7 @@ struct AppidCPUProfilerStats {
     uint32_t per_appid_sessions = 0;
     uint64_t max_processing_time_per_session = 0;
     uint64_t max_processed_pkts_per_session = 0;
-    
+
     AppidCPUProfilerStats(const char* app_name, uint64_t processing_time, uint64_t processed_packets, uint32_t per_appid_sessions) :
         app_name(app_name), processing_time(processing_time), processed_packets(processed_packets), per_appid_sessions(per_appid_sessions),
         max_processing_time_per_session(processing_time), max_processed_pkts_per_session(processed_packets)
@@ -74,10 +74,10 @@ private:
     uint32_t total_per_appid_sessions = 0;
     uint64_t max_processing_time_per_session = 0;
     uint64_t max_processed_pkts_per_session = 0;
-        
+
 public:
     AppidCPUProfilingManager() = default;
-    
+
     void stats_bucket_insert(AppId appid, const char* app_name, uint64_t processing_time, uint64_t processed_packets);
     void insert_appid_cpu_profiler_record(AppId appId, const AppidCPUProfilerStats& stats);
     void check_appid_cpu_profiler_table_entry(const AppIdSession* asd, AppId service_id, AppId client_id, AppId payload_id, AppId misc_id);
@@ -87,7 +87,7 @@ public:
     AppidCpuTableDisplayStatus display_appid_cpu_profiler_table(OdpContext&, uint32_t display_rows_limit = APPID_CPU_PROFILER_DEFAULT_DISPLAY_ROWS,
                                                                 bool override_running_flag = false, ControlConn* control_conn = nullptr);
     AppidCpuTableDisplayStatus display_appid_cpu_profiler_table(AppId, OdpContext&, ControlConn* control_conn = nullptr);
-    
+
     void cleanup_appid_cpu_profiler_table();
 };
 #endif
index d981580a714697e680891f4d21830f19daf6a51b..45f2e71e710e7a2236ea856e1d8013256433bb1b 100644 (file)
@@ -450,7 +450,7 @@ static int show_cpu_profiler_status(lua_State* L)
     }
     const AppIdContext& ctxt = inspector->get_ctxt();
     OdpContext& odp_ctxt = ctxt.get_odp_ctxt();
-    ctrlcon->respond("appid cpu profiler enabled: %s , running: %s \n",
+    ctrlcon->respond("appid cpu profiler enabled: %s, running: %s \n",
             odp_ctxt.is_appid_cpu_profiler_enabled() ? "yes" : "no", odp_ctxt.is_appid_cpu_profiler_running() ? "yes" : "no");
     return 0;
 }