From: Otto Moerbeek Date: Wed, 21 Oct 2020 09:07:32 +0000 (+0200) Subject: Refactor the percentage computation and use rounding (double -> uint64_t conversion... X-Git-Tag: auth-4.4.0-alpha2~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9629%2Fhead;p=thirdparty%2Fpdns.git Refactor the percentage computation and use rounding (double -> uint64_t conversion truncates) --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 684db957f3..3fe678410b 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -3201,6 +3201,14 @@ static void usr2Handler(int) ::arg().set("quiet")=g_quiet ? "" : "no"; } +static int ratePercentage(uint64_t nom, uint64_t denom) +{ + if (denom == 0) { + return 0; + } + return round(100.0 * nom / denom); +} + static void doStats(void) { static time_t lastOutputTime; @@ -3217,7 +3225,7 @@ static void doStats(void) g_log<(pleaseGetNsSpeedsSize)<<", failed ns: " << broadcastAccFunction(pleaseGetFailedServersSize)<<", ednsmap: " <(pleaseGetEDNSStatusesSize)<(pleaseGetConcurrentQueries)<<" queries running, "<(pleaseGetPacketCacheSize) << - " packet cache entries, "<<(int)(100.0*broadcastAccFunction(pleaseGetPacketCacheHits)/SyncRes::s_queries) << "% packet cache hits"<(pleaseGetPacketCacheSize); + uint64_t pcHits = broadcastAccFunction(pleaseGetPacketCacheHits); + g_log<