From: Steven Baigal (sbaigal) Date: Tue, 5 Jul 2022 14:19:24 +0000 (+0000) Subject: Pull request #3492: utils: make shutdown timing stats more precise (github PR #184) X-Git-Tag: 3.1.34.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=658aa230a3bb758f509bf3127dcfbaa17219e05f;p=thirdparty%2Fsnort3.git Pull request #3492: utils: make shutdown timing stats more precise (github PR #184) Merge in SNORT/snort3 from ~ASERBENI/snort3:github_issue_184 to master Squashed commit of the following: commit 776e276faf3cc86b3d9cd3675cca558a24271e57 Author: trevor tao Date: Mon May 24 21:09:15 2021 +0800 utils: make shutdown timing stats more precise Thanks to trevor tao for the update. --- diff --git a/src/utils/stats.cc b/src/utils/stats.cc index f8f052c3c..be430903e 100644 --- a/src/utils/stats.cc +++ b/src/utils/stats.cc @@ -24,6 +24,7 @@ #include "stats.h" #include +#include #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); }