From: bert hubert Date: Wed, 3 Feb 2016 15:09:04 +0000 (+0100) Subject: let dumresp keep stats across forks and print them X-Git-Tag: dnsdist-1.0.0-alpha2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b85069a3bd15ae794c62019b2ca898f9f551fde;p=thirdparty%2Fpdns.git let dumresp keep stats across forks and print them --- diff --git a/pdns/dumresp.cc b/pdns/dumresp.cc index 129f9753ba..b9d26f0d87 100644 --- a/pdns/dumresp.cc +++ b/pdns/dumresp.cc @@ -4,22 +4,47 @@ #include "iputils.hh" #include "sstuff.hh" #include "statbag.hh" - +#include +#include +#include StatBag S; +std::atomic* g_counter; + +void printStatus() +{ + auto prev= g_counter->load(); + for(;;) { + sleep(1); + cout<load()-prev<<"\t"<load()<load(); + } +} + int main(int argc, char** argv) try { if(argc != 4) { - cerr<<"Syntax: dumresp local-address local-port number-of-threads "<), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + + g_counter = new(ptr) std::atomic(); + + int i=1; + for(; i < atoi(argv[3]); ++i) { if(!fork()) break; } - + if(i==1) { + std::thread t(printStatus); + t.detach(); + } + ComboAddress local(argv[1], atoi(argv[2])); Socket s(local.sin4.sin_family, SOCK_DGRAM); #ifdef SO_REUSEPORT @@ -37,6 +62,7 @@ try socklen_t socklen = rem.getSocklen(); for(;;) { len=recvfrom(s.getHandle(), buffer, sizeof(buffer), 0, (struct sockaddr*)&rem, &socklen); + (*g_counter)++; if(len < 0) unixDie("recvfrom");