From: bert hubert Date: Thu, 15 Jan 2015 12:35:11 +0000 (+0100) Subject: add some timing infra which is disabled by default, turn it on with -DMTASKERTIMING X-Git-Tag: rec-3.7.0-rc1~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b80f25dfd346a940539582d2cb83fa4587c64bf1;p=thirdparty%2Fpdns.git add some timing infra which is disabled by default, turn it on with -DMTASKERTIMING --- diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index f92685451b..4ea7770564 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -25,6 +25,7 @@ #include #include + /** \page MTasker Simple system for implementing cooperative multitasking of functions, with support for waiting on events which can return values. @@ -190,11 +191,17 @@ templateint MTasker::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 @@ templatebool MTasker::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 @@ templateint MTasker::getTid() return d_tid; } - //! Returns the maximum stack usage so far of this MThread templateunsigned int MTasker::getMaxStackUsage() { return d_threads[d_tid].startOfStack - d_threads[d_tid].highestStackSeen; } + +//! Returns the maximum stack usage so far of this MThread +templateunsigned int MTasker::getUsec() +{ +#ifdef MTASKERTIMING + return d_threads[d_tid].totTime + d_threads[d_tid].dt.ndiff()/1000; +#else + return 0; +#endif +} diff --git a/pdns/mtasker.hh b/pdns/mtasker.hh index 5c42fce4a2..6f9ce7043f 100644 --- a/pdns/mtasker.hh +++ b/pdns/mtasker.hh @@ -32,8 +32,11 @@ #include #include #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 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);