From: bert hubert Date: Thu, 15 Jan 2015 12:24:08 +0000 (+0100) Subject: add CPU time nanosecond resolution infrastructure, behind #ifdef now for supporting... X-Git-Tag: rec-3.7.0-rc1~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df13e61d07c2f42c847ba45ac64fde28f1df412e;p=thirdparty%2Fpdns.git add CPU time nanosecond resolution infrastructure, behind #ifdef now for supporting systems --- diff --git a/pdns/misc.hh b/pdns/misc.hh index 019facd1bf..e7c72e0de7 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -181,6 +181,26 @@ int makeGidNumeric(const string &group); int makeUidNumeric(const string &user); void cleanSlashes(string &str); +#ifdef _POSIX_THREAD_CPUTIME +/** CPUTime measurements */ +class CPUTime +{ +public: + void start() + { + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &d_start); + } + uint64_t ndiff() + { + struct timespec now; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now); + return 1000000000ULL*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec); + } +private: + struct timespec d_start; +}; +#endif + /** The DTime class can be used for timing statistics with microsecond resolution. On 32 bits systems this means that 2147 seconds is the longest time that can be measured. */ class DTime