14 #include <sys/resource.h>
34 : state_(kStopped), startRealTime_(), startCPUTime_(), accumulatedRealTime_(0), accumulatedCPUTime_(0) {
35 #ifdef USE_CLOCK_GETTIME
70 #ifdef USE_CLOCK_GETTIME
77 if (0 != getrusage(RUSAGE_SELF, &theUsage)) {
80 startCPUTime_.tv_sec = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec;
81 startCPUTime_.tv_usec = theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec;
111 #ifdef USE_CLOCK_GETTIME
112 double const nanosecToSec = 1E-9;
115 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &
tp);
118 clock_gettime(CLOCK_MONOTONIC, &
tp);
122 if (0 != getrusage(RUSAGE_SELF, &theUsage)) {
125 double const microsecToSec = 1E-6;
128 gettimeofday(&
tp, 0);
130 returnValue.
cpu_ = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec -
startCPUTime_.tv_sec +
131 microsecToSec * (theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec -
startCPUTime_.tv_usec);