From: bert hubert Date: Wed, 3 Jul 2013 10:05:46 +0000 (+0200) Subject: teach dnstcpbench to emit some nice statistics, plus document them X-Git-Tag: auth-3.3~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=816d1ea4d94295009fc5328cdc23f68d821729e2;p=thirdparty%2Fpdns.git teach dnstcpbench to emit some nice statistics, plus document them --- diff --git a/pdns/dnstcpbench.cc b/pdns/dnstcpbench.cc index 67a0512b08..34754abf28 100644 --- a/pdns/dnstcpbench.cc +++ b/pdns/dnstcpbench.cc @@ -15,6 +15,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include +#include + +#include + #include "dnsparser.hh" #include "sstuff.hh" #include "misc.hh" @@ -24,9 +30,11 @@ #include #include #include +#include StatBag S; namespace po = boost::program_options; + po::variables_map g_vm; bool g_verbose; bool g_onlyTCP; @@ -35,19 +43,24 @@ unsigned int g_timeoutMsec; AtomicCounter g_networkErrors, g_otherErrors, g_OK, g_truncates, g_authAnswers, g_timeOuts; ComboAddress g_dest; +unsigned int makeUsec(const struct timeval& tv) +{ + return 1000000*tv.tv_sec + tv.tv_usec; +} + /* On Linux, run echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle to prevent running out of free TCP ports */ struct BenchQuery { - BenchQuery(const std::string& qname_, uint16_t qtype_) : qname(qname_), qtype(qtype_), udpMsec(0), tcpMsec(0) {} + BenchQuery(const std::string& qname_, uint16_t qtype_) : qname(qname_), qtype(qtype_), udpUsec(0), tcpUsec(0), answerSecond(0) {} BenchQuery(){} std::string qname; uint16_t qtype; - uint16_t udpMsec, tcpMsec; + uint32_t udpUsec, tcpUsec; + time_t answerSecond; }; - void doQuery(BenchQuery* q) try { @@ -56,6 +69,9 @@ try int res; string reply; + struct timeval tv, now; + gettimeofday(&tv, 0); + if(!g_onlyTCP) { Socket udpsock((AddressFamily)g_dest.sin4.sin_family, Datagram); @@ -70,6 +86,11 @@ try } udpsock.recvFrom(reply, origin); + + gettimeofday(&now, 0); + q->udpUsec = makeUsec(now - tv); + tv=now; + MOADNSParser mdp(reply); if(!mdp.d_header.tc) return; @@ -116,6 +137,10 @@ try reply=string(creply, len); delete[] creply; + gettimeofday(&now, 0); + q->tcpUsec = makeUsec(now - tv); + q->answerSecond = now.tv_sec; + MOADNSParser mdp(reply); // cout<<"Had correct TCP/IP response, "<