]> granicus.if.org Git - pdns/commitdiff
add some timing infra which is disabled by default, turn it on with -DMTASKERTIMING
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 15 Jan 2015 12:35:11 +0000 (13:35 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 15 Jan 2015 12:35:11 +0000 (13:35 +0100)
pdns/mtasker.cc
pdns/mtasker.hh

index f92685451bd445b10fbfc626ef62b02bf151fb6f..4ea7770564a20b2d8f018ac29df9ab61f497c2e1 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <iostream>
 
+
 /** \page MTasker
     Simple system for implementing cooperative multitasking of functions, with 
     support for waiting on events which can return values.
@@ -190,11 +191,17 @@ template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEven
   w.key=key;
 
   d_waiters.insert(w);
-  
+#ifdef MTASKERTIMING
+  unsigned int diff=d_threads[d_tid].dt.ndiff()/1000;
+  d_threads[d_tid].totTime+=diff;
+#endif
   if(swapcontext(d_waiters.find(key)->context,&d_kernel)) { // 'A' will return here when 'key' has arrived, hands over control to kernel first
     perror("swapcontext");
     exit(EXIT_FAILURE); // no way we can deal with this 
   }
+#ifdef MTASKERTIMING
+  d_threads[d_tid].dt.start();
+#endif
   if(val && d_waitstatus==Answer) 
     *val=d_waitval;
   d_tid=w.tid;
@@ -299,6 +306,9 @@ template<class Key, class Val>bool MTasker<Key,Val>::schedule(struct timeval*  n
 {
   if(!d_runQueue.empty()) {
     d_tid=d_runQueue.front();
+#ifdef MTASKERTIMING
+    d_threads[d_tid].dt.start();
+#endif
     if(swapcontext(&d_kernel, d_threads[d_tid].context)) {
       perror("swapcontext in schedule");
       exit(EXIT_FAILURE);
@@ -399,9 +409,18 @@ template<class Key, class Val>int MTasker<Key,Val>::getTid()
   return d_tid;
 }
 
-
 //! Returns the maximum stack usage so far of this MThread
 template<class Key, class Val>unsigned int MTasker<Key,Val>::getMaxStackUsage()
 {
   return d_threads[d_tid].startOfStack - d_threads[d_tid].highestStackSeen;
 }
+
+//! Returns the maximum stack usage so far of this MThread
+template<class Key, class Val>unsigned int MTasker<Key,Val>::getUsec()
+{
+#ifdef MTASKERTIMING
+  return d_threads[d_tid].totTime + d_threads[d_tid].dt.ndiff()/1000;
+#else 
+  return 0;
+#endif
+}
index 5c42fce4a2b564e3bd8b9db28d5ba619551d7ad1..6f9ce7043f294b4997e152696e9963e3402fe2ad 100644 (file)
 #include <boost/multi_index/ordered_index.hpp>
 #include <boost/multi_index/key_extractors.hpp>
 #include "namespaces.hh"
+#include "misc.hh"
 using namespace ::boost::multi_index;
 
+// #define MTASKERTIMING 1
+
 struct KeyTag {};
 
 //! The main MTasker class    
@@ -54,6 +57,10 @@ private:
        ucontext_t* context;
        char* startOfStack;
        char* highestStackSeen;
+#ifdef MTASKERTIMING
+       CPUTime dt;
+       unsigned int totTime;
+#endif
   };
 
   typedef std::map<int, ThreadInfo> mthreads_t;
@@ -105,6 +112,7 @@ public:
   unsigned int numProcesses();
   int getTid(); 
   unsigned int getMaxStackUsage();
+  unsigned int getUsec();
 
 private:
   static void threadWrapper(uint32_t self1, uint32_t self2, tfunc_t *tf, int tid, uint32_t val1, uint32_t val2);