From df13e61d07c2f42c847ba45ac64fde28f1df412e Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 15 Jan 2015 13:24:08 +0100 Subject: [PATCH] add CPU time nanosecond resolution infrastructure, behind #ifdef now for supporting systems --- pdns/misc.hh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pdns/misc.hh b/pdns/misc.hh index 019facd1b..e7c72e0de 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 -- 2.40.0