version 1.2, 2015/09/13 12:41:01 |
version 1.3, 2017/11/24 13:48:12 |
|
|
* Functions that need to be overridden by non-POSIX operating systems. |
* Functions that need to be overridden by non-POSIX operating systems. |
*/ |
*/ |
|
|
#include <sys/times.h> |
#include <sys/resource.h> |
|
#include <sys/time.h> |
|
|
#include <unistd.h> |
#include <time.h> |
|
|
#include "apps.h" |
#include "apps.h" |
|
|
double |
static double |
app_tminterval(int stop, int usertime) |
real_interval(int stop) |
{ |
{ |
double ret = 0; |
static struct timespec start; |
struct tms rus; |
struct timespec elapsed, now; |
clock_t now = times(&rus); |
|
static clock_t tmstart; |
|
|
|
if (usertime) |
clock_gettime(CLOCK_MONOTONIC, &now); |
now = rus.tms_utime; |
if (stop) { |
|
timespecsub(&now, &start, &elapsed); |
|
return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0; |
|
} |
|
start = now; |
|
return 0.0; |
|
} |
|
|
if (stop == TM_START) |
static double |
tmstart = now; |
user_interval(int stop) |
else { |
{ |
long int tck = sysconf(_SC_CLK_TCK); |
static struct timeval start; |
ret = (now - tmstart) / (double) tck; |
struct timeval elapsed; |
|
struct rusage now; |
|
|
|
getrusage(RUSAGE_SELF, &now); |
|
if (stop) { |
|
timersub(&now.ru_utime, &start, &elapsed); |
|
return elapsed.tv_sec + elapsed.tv_usec / 1000000.0; |
} |
} |
|
start = now.ru_utime; |
|
return 0.0; |
|
} |
|
|
return (ret); |
double |
|
app_tminterval(int stop, int usertime) |
|
{ |
|
return (usertime) ? user_interval(stop) : real_interval(stop); |
} |
} |
|
|
int |
int |