]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add ./configure --enable-malloc-trace which will cause powerdns recursor (for now...
authorbert hubert <bert.hubert@powerdns.com>
Wed, 25 Nov 2015 14:11:45 +0000 (15:11 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Wed, 25 Nov 2015 14:11:45 +0000 (15:11 +0100)
configure.ac
m4/pdns_enable_malloc_trace.m4 [new file with mode: 0644]
pdns/Makefile.am
pdns/malloctrace.cc
pdns/malloctrace.hh
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc

index 8634b8a413f949f587d61a04a5de22f4a6a3699d..74746484eda46a49c2fa6822ea0700d5b6b624ea 100644 (file)
@@ -318,6 +318,7 @@ AC_SUBST([PROGRAM_LDFLAGS])
 
 PDNS_ENABLE_COVERAGE
 PDNS_ENABLE_SANITIZERS
+PDNS_ENABLE_MALLOC_TRACE
 
 AC_SUBST(LIBS)
 
diff --git a/m4/pdns_enable_malloc_trace.m4 b/m4/pdns_enable_malloc_trace.m4
new file mode 100644 (file)
index 0000000..4987a53
--- /dev/null
@@ -0,0 +1,13 @@
+AC_DEFUN([PDNS_ENABLE_MALLOC_TRACE], [
+  AC_MSG_CHECKING([whether to enable code malloc-trace])
+  AC_ARG_ENABLE([malloc-trace],
+    AS_HELP_STRING([--enable-malloc-trace],
+      [enable malloc-trace @<:@default=no@:>@]),
+    [enable_malloc_trace=$enableval],
+    [enable_malloc_trace=no]
+  )
+  AC_MSG_RESULT([$enable_malloc_trace])
+  AM_CONDITIONAL([MALLOC_TRACE], [test "x$enable_malloc_trace" = "xyes"])  
+  AS_IF([test "x$enable_malloc_trace" = "xyes"], 
+  AC_DEFINE([MALLOC_TRACE], [1], [Define to 1 if you want to benefit from malloc trace]) )
+])
index 583bad7c133dd9ee580cd0ec213a6bae4948d91f..d90d7dca86b2dbc3a72162cbb6deb13530cd678e 100644 (file)
@@ -1143,6 +1143,10 @@ pdns_recursor_SOURCES += pkcs11signers.cc pkcs11signers.hh
 pdns_recursor_LDADD += $(P11KIT1_LIBS)
 endif
 
+if MALLOC_TRACE
+pdns_recursor_SOURCES += malloctrace.cc malloctrace.hh 
+pdns_recursor_LDFLAGS = $(AM_LDFLAGS) -rdynamic
+endif
 
 if LUA
 pdns_recursor_LDADD += $(LUA_LIBS)
index 268580d00b6f6df3acfd5597b22f558a9b00eb17..750782c78a96345bd3ff41681897ec8f268a5fe3 100644 (file)
@@ -118,13 +118,11 @@ std::string MallocTracer::topAllocatorsString(int num)
   return str;
 }
 
-/*
-char **strings;
-  size_t i;
-  strings = backtrace_symbols (array, size); //Need -rdynamic gcc (linker) flag for this to work
-
-  for (i = 0; i < size; i++) //skip useless functions
-    ret+=strings[i]+string("\n");
-  return ret;
-*/
+void MallocTracer::clearAllocators()
+{
+  l_active=true;
+  std::lock_guard<std::mutex> lock(d_mut); 
+  d_stats.clear(); 
+  l_active=false;
+}
 
index 83d23b20649de1e9e1cb304bbc26fd64a29665fc..b3091c1566b9a615a0a9390cc8c2d98b760871a2 100644 (file)
@@ -19,7 +19,7 @@ public:
   uint64_t getAllocs(const std::string& = std::string()) const { return d_allocs; }
   uint64_t getAllocFlux(const std::string& = std::string()) const { return d_allocflux; }
   uint64_t getTotAllocated(const std::string& = std::string()) const { return d_totAllocated; }
-
+  uint64_t getNumOut() { std::lock_guard<std::mutex> lock(d_mut); return d_sizes.size(); }
   struct AllocStats
   {
     int count;
@@ -29,6 +29,8 @@ public:
                                std::vector<void*> > > allocators_t;
   allocators_t topAllocators(int num=-1);
   std::string topAllocatorsString(int num=-1);
+  void clearAllocators();
+
 private:
   static std::vector<void*> makeBacktrace();
   std::atomic<uint64_t> d_allocs{0}, d_allocflux{0}, d_totAllocated{0};
index 6e48f3e1c6464a81abc96268de7a008a0a934426..81ccf24150af238966f5ca0df2298f08501501cd 100644 (file)
@@ -56,6 +56,9 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/function.hpp>
 #include <boost/algorithm/string.hpp>
+#ifdef MALLOC_TRACE
+#include "malloctrace.hh"
+#endif
 #include <netinet/tcp.h>
 #include "dnsparser.hh"
 #include "dnswriter.hh"
@@ -641,6 +644,7 @@ void startDoResolve(void *p)
       tracedQuery=true;
     }
 
+
     if(!g_quiet || tracedQuery)
       L<<Logger::Warning<<t_id<<" ["<<MT->getTid()<<"/"<<MT->numProcesses()<<"] " << (dc->d_tcp ? "TCP " : "") << "question for '"<<dc->d_mdp.d_qname<<"|"
        <<DNSRecordContent::NumberToType(dc->d_mdp.d_qtype)<<"' from "<<dc->getRemote()<<endl;
@@ -1086,11 +1090,25 @@ string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fr
   string response;
   try {
     uint32_t age;
+#ifdef MALLOC_TRACE
+    /*
+    static uint64_t last=0;
+    if(!last)
+      g_mtracer->clearAllocators();
+    cout<<g_mtracer->getAllocs()-last<<" "<<g_mtracer->getNumOut()<<" -- BEGIN TRACE"<<endl;
+    last=g_mtracer->getAllocs();
+    cout<<g_mtracer->topAllocatorsString()<<endl;
+    g_mtracer->clearAllocators();
+    */
+#endif
+
     if(!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(question, g_now.tv_sec, &response, &age)) {
       if(!g_quiet)
         L<<Logger::Notice<<t_id<< " question answered from packet cache from "<<fromaddr.toString()<<endl;
       // t_queryring->push_back("packetcached");
 
+      
+
       g_stats.packetCacheHits++;
       SyncRes::s_queries++;
       ageDNSPacket(response, age);
index 1f744ee4761cded2b8bb15b074339b62198d803a..42e27fcec457e33e4a3586ae315ef6546138088e 100644 (file)
@@ -6,7 +6,9 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/bind.hpp>
 #include <vector>
-
+#ifdef MALLOC_TRACE
+#include "malloctrace.hh"
+#endif
 #include "misc.hh"
 #include "recursor_cache.hh"
 #include "syncres.hh"
@@ -615,6 +617,12 @@ RecursorControlParser::RecursorControlParser()
   //  addGetStat("query-rate", getQueryRate);
   addGetStat("user-msec", getUserTimeMsec);
   addGetStat("sys-msec", getSysTimeMsec);
+
+#ifdef MALLOC_TRACE
+  addGetStat("memory-allocs", boost::bind(&MallocTracer::getAllocs, g_mtracer, string()));
+  addGetStat("memory-alloc-flux", boost::bind(&MallocTracer::getAllocFlux, g_mtracer, string()));
+  addGetStat("memory-allocated", boost::bind(&MallocTracer::getTotAllocated, g_mtracer, string()));
+#endif
 }
 
 static void doExitGeneric(bool nicely)