"Fossies" - the Fresh Open Source Software Archive

Member "pdns-auth-4.2.0/pdns/responsestats.cc" (27 Aug 2019, 2660 Bytes) of package /linux/misc/dns/pdns-auth-4.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "responsestats.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.13_vs_4.2.0.

    1 #ifdef HAVE_CONFIG_H
    2 #include "config.h"
    3 #endif
    4 #include "responsestats.hh"
    5 #include <limits>
    6 #include "namespaces.hh"
    7 #include "logger.hh"
    8 
    9 #include "dnsparser.hh"
   10 
   11 ResponseStats::ResponseStats() :   d_qtypecounters(new std::atomic<unsigned long>[65536]), d_rcodecounters(new std::atomic<unsigned long>[256])
   12 {
   13   d_sizecounters.push_back(make_pair(20,0));
   14   d_sizecounters.push_back(make_pair(40,0));
   15   d_sizecounters.push_back(make_pair(60,0));
   16   d_sizecounters.push_back(make_pair(80,0));
   17   d_sizecounters.push_back(make_pair(100,0));
   18   d_sizecounters.push_back(make_pair(150,0));
   19   for(int n=200; n < 65000 ; n+=200)
   20     d_sizecounters.push_back(make_pair(n,0));
   21   d_sizecounters.push_back(make_pair(std::numeric_limits<uint16_t>::max(),0));
   22   for(unsigned int n =0 ; n < 65535; ++n)
   23     d_qtypecounters[n] = 0;
   24   for(unsigned int n =0 ; n < 256; ++n)
   25     d_rcodecounters[n] = 0;
   26 }
   27 
   28 ResponseStats g_rs;
   29 
   30 static bool pcomp(const pair<uint16_t, uint64_t>&a , const pair<uint16_t, uint64_t>&b)
   31 {
   32   return a.first < b.first;
   33 }
   34 
   35 void ResponseStats::submitResponse(uint16_t qtype,uint16_t respsize, uint8_t rcode, bool udpOrTCP)
   36 {
   37     d_rcodecounters[rcode]++;
   38     submitResponse(qtype, respsize, udpOrTCP);
   39 }
   40 
   41 void ResponseStats::submitResponse(uint16_t qtype,uint16_t respsize, bool udpOrTCP)
   42 {
   43   d_qtypecounters[qtype]++;
   44   pair<uint16_t, uint64_t> s(respsize, 0);
   45   sizecounters_t::iterator iter = std::upper_bound(d_sizecounters.begin(), d_sizecounters.end(), s, pcomp);
   46   if(iter!= d_sizecounters.begin())
   47     --iter;
   48   iter->second++;
   49 }
   50 
   51 map<uint16_t, uint64_t> ResponseStats::getQTypeResponseCounts()
   52 {
   53   map<uint16_t, uint64_t> ret;
   54   uint64_t count;
   55   for(unsigned int i = 0 ; i < 65535 ; ++i) {
   56     count= d_qtypecounters[i];
   57     if(count)
   58       ret[i]=count;
   59   }
   60   return ret;
   61 }
   62 
   63 map<uint16_t, uint64_t> ResponseStats::getSizeResponseCounts()
   64 {
   65   map<uint16_t, uint64_t> ret;
   66   for(sizecounters_t::const_iterator iter = d_sizecounters.begin();
   67       iter != d_sizecounters.end();
   68       ++iter) {
   69     ret[iter->first]=iter->second;
   70   }
   71   return ret;
   72 }
   73 
   74 map<uint8_t, uint64_t> ResponseStats::getRCodeResponseCounts()
   75 {
   76   map<uint8_t, uint64_t> ret;
   77   uint64_t count;
   78   for(unsigned int i = 0 ; i < 256 ; ++i) {
   79     count= d_rcodecounters[i];
   80     if(count)
   81       ret[i]=count;
   82   }
   83   return ret;
   84 }
   85 
   86 string ResponseStats::getQTypeReport()
   87 {
   88   typedef map<uint16_t, uint64_t> qtypenums_t;
   89   qtypenums_t qtypenums = getQTypeResponseCounts();
   90   ostringstream os;
   91   boost::format fmt("%s\t%d\n");
   92   for(const qtypenums_t::value_type& val :  qtypenums) {
   93     os << (fmt %DNSRecordContent::NumberToType( val.first) % val.second).str();
   94   }
   95   return os.str();
   96 }