]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3492: utils: make shutdown timing stats more precise (github PR #184)
authorSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 5 Jul 2022 14:19:24 +0000 (14:19 +0000)
committerSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 5 Jul 2022 14:19:24 +0000 (14:19 +0000)
Merge in SNORT/snort3 from ~ASERBENI/snort3:github_issue_184 to master

Squashed commit of the following:

commit 776e276faf3cc86b3d9cd3675cca558a24271e57
Author: trevor tao <trevor.tao@arm.com>
Date:   Mon May 24 21:09:15 2021 +0800

    utils: make shutdown timing stats more precise

    Thanks to trevor tao <trevor.tao@arm.com> for the update.

src/utils/stats.cc

index f8f052c3c1d73c5b78d253d92231aaad653c167f..be430903e11929cc0ac120ca3f45693f597c91fd 100644 (file)
@@ -24,6 +24,7 @@
 #include "stats.h"
 
 #include <cassert>
+#include <cmath>
 
 #include "control/control.h"
 #include "detection/detection_engine.h"
@@ -46,6 +47,7 @@
 
 #define STATS_SEPARATOR \
     "--------------------------------------------------"
+#define USECS_PER_SEC 1000000.0
 
 ProcessCount proc_stats;
 
@@ -152,9 +154,6 @@ static void timing_stats()
     TIMERSUB(&endtime, &starttime, &difftime);
 
     uint32_t tmp = (uint32_t)difftime.tv_sec;
-    uint32_t total_secs = tmp;
-    if ( total_secs < 1 )
-        total_secs = 1;
 
     uint32_t hrs  = tmp / SECONDS_PER_HOUR;
     tmp  = tmp % SECONDS_PER_HOUR;
@@ -175,10 +174,12 @@ static void timing_stats()
     uint64_t num_pkts = (uint64_t)daq->get_global_count("analyzed");
     uint64_t num_byts = (uint64_t)daq->get_global_count("rx_bytes");
 
-    if ( uint64_t pps = (num_pkts / total_secs) )
+    double total_secs = tmp + difftime.tv_usec / USECS_PER_SEC;
+
+    if ( uint64_t pps = (uint64_t)llround(num_pkts / total_secs) )
         LogMessage("%25.25s: " STDu64 "\n", "pkts/sec", pps);
 
-    if ( uint64_t mbps = 8 * num_byts / total_secs / 1024 / 1024 )
+    if ( uint64_t mbps = (uint64_t)llround(8 * num_byts / total_secs / 1024 / 1024) )
         LogMessage("%25.25s: " STDu64 "\n", "Mbits/sec", mbps);
 }