separation between rusage and second() calculation, no timediff() for second()
This commit is contained in:
parent
2d699dafad
commit
f58705b473
|
|
@ -906,13 +906,13 @@ AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stddef.h sys/file.h sys/param
|
|||
# Check time and resources headers and functions:
|
||||
AC_STRUCT_TM
|
||||
AC_STRUCT_TIMEZONE
|
||||
AC_CHECK_FUNCS([localtime])
|
||||
AC_CHECK_FUNCS([time localtime])
|
||||
|
||||
AC_CHECK_FUNCS([clock_gettime gettimeofday ftime times])
|
||||
|
||||
# Do not use time or getrusage function for CPU time measurement under OpenMP
|
||||
# Do not use getrusage function for CPU time measurement under OpenMP
|
||||
if test "x$enable_openmp" = xno; then
|
||||
AC_CHECK_FUNCS([time getrusage])
|
||||
AC_CHECK_FUNCS([getrusage])
|
||||
fi
|
||||
AC_CHECK_FUNCS([utimes])
|
||||
AC_CHECK_FUNCS([getrlimit ulimit], [break])
|
||||
|
|
|
|||
|
|
@ -80,18 +80,27 @@ init_rlimits(void)
|
|||
#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY || defined HAVE_FTIME
|
||||
PortableTime timebegin;
|
||||
#endif
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
GTimer gtimer;
|
||||
#endif
|
||||
#ifdef HAVE_TIMES
|
||||
TTimer ttimer;
|
||||
#endif
|
||||
|
||||
void
|
||||
init_time(void)
|
||||
{
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY || defined HAVE_FTIME
|
||||
get_portable_time(&timebegin);
|
||||
#else
|
||||
# ifdef HAVE_TIMES
|
||||
# else
|
||||
# if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY || defined HAVE_FTIME
|
||||
get_portable_time(&timebegin);
|
||||
# endif
|
||||
# endif
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
start_timer(>imer);
|
||||
#else
|
||||
#ifdef HAVE_TIMES
|
||||
clock_t start_clock;
|
||||
start_clock = start_timer(&ttimer);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -179,24 +188,20 @@ printres(char *name)
|
|||
cpu_elapsed = "elapsed";
|
||||
#else
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
int ret;
|
||||
struct rusage ruse;
|
||||
memset(&ruse, 0, sizeof(ruse));
|
||||
ret = getrusage(RUSAGE_SELF, &ruse);
|
||||
if (ret == -1)
|
||||
perror("getrusage(): ");
|
||||
stop_timer(>imer);
|
||||
|
||||
total_sec = (int) (ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec);
|
||||
total_msec = (int) (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec) / 1000;
|
||||
total_sec = (int) (gtimer.end.ru_utime.tv_sec + gtimer.start.ru_stime.tv_sec);
|
||||
total_msec = (int) (gtimer.end.ru_utime.tv_usec + gtimer.start.ru_stime.tv_usec) / 1000;
|
||||
cpu_elapsed = "CPU";
|
||||
#else
|
||||
#ifdef HAVE_TIMES
|
||||
struct tms ruse;
|
||||
times(&ruse);
|
||||
clock_t x = ruse.tms_utime + ruse.tms_stime;
|
||||
clock_t stop_clock = stop_timer(&ttimer);
|
||||
clock_t user_time = (ttimer.end.tms_utime - ttimer.start.tms_utime);
|
||||
clock_t system_time = (ttimer.end.tms_stime - ttimer.start.tms_stime);
|
||||
clock_t x = user_time + system_time;
|
||||
clock_t hz = (clock_t) sysconf(_SC_CLK_TCK);
|
||||
total_sec = x / hz;
|
||||
total_msec = ((x % hz) * 1000) / hz;
|
||||
total_sec = (int) (x / hz);
|
||||
total_msec = (int) (((x % hz) * 1000) / hz);
|
||||
cpu_elapsed = "CPU";
|
||||
#else
|
||||
# define NO_RUDATA
|
||||
|
|
@ -204,7 +209,6 @@ printres(char *name)
|
|||
# endif
|
||||
# endif
|
||||
|
||||
|
||||
#ifndef NO_RUDATA
|
||||
|
||||
if (total_msec >= 1000) {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ void get_portable_time(PortableTime *pt) {
|
|||
|
||||
/*
|
||||
* How many seconds have elapsed in running time.
|
||||
* This is the routine called in IFseconds
|
||||
* This is the routine called in IFseconds where start / stop is handled
|
||||
* and we don't need calculate timediff here.
|
||||
*/
|
||||
|
||||
double
|
||||
|
|
@ -105,8 +106,7 @@ seconds(void)
|
|||
int sec, msec;
|
||||
|
||||
get_portable_time(&timenow);
|
||||
timediff(&timenow, &timebegin, &sec, &msec);
|
||||
return(sec + (double) msec / 1000.0);
|
||||
return((double) timenow.seconds + (double) timenow.milliseconds / 1000.0);
|
||||
#else
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
int ret;
|
||||
|
|
@ -125,7 +125,7 @@ seconds(void)
|
|||
struct tms tmsbuf;
|
||||
|
||||
times(&tmsbuf);
|
||||
return((double) tmsbuf.tms_utime / HZ);
|
||||
return((double) tmsbuf.tms_utime / (clock_t) sysconf(_SC_CLK_TCK));
|
||||
|
||||
#else /* unknown */
|
||||
|
||||
|
|
@ -135,3 +135,33 @@ seconds(void)
|
|||
#endif /* TIMES */
|
||||
#endif /* CLOCK_GETTIME || GETTIMEOFDAY || FTIME */
|
||||
}
|
||||
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
void start_timer(GTimer *timer) {
|
||||
int ret;
|
||||
ret = getrusage(RUSAGE_SELF, &timer->start);
|
||||
if(ret == -1) {
|
||||
perror("getrusage(): ");
|
||||
}
|
||||
}
|
||||
void stop_timer(GTimer *timer) {
|
||||
int ret;
|
||||
ret = getrusage(RUSAGE_SELF, &timer->end);
|
||||
if(ret == -1) {
|
||||
perror("getrusage(): ");
|
||||
}
|
||||
}
|
||||
#endif /* GETRUSAGE */
|
||||
|
||||
#ifdef HAVE_TIMES
|
||||
clock_t start_timer(TTimer *timer) {
|
||||
clock_t start_clock;
|
||||
start_clock = times(&timer->start);
|
||||
return start_clock;
|
||||
}
|
||||
clock_t stop_timer(TTimer *timer) {
|
||||
clock_t stop_clock;
|
||||
stop_clock = times(&timer->end);
|
||||
return stop_clock;
|
||||
}
|
||||
#endif /* TIMES */
|
||||
|
|
|
|||
|
|
@ -21,4 +21,28 @@ void timediff(PortableTime *, PortableTime *, int *, int *);
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETRUSAGE
|
||||
|
||||
typedef struct {
|
||||
struct rusage start;
|
||||
struct rusage end;
|
||||
} GTimer;
|
||||
|
||||
void start_timer(GTimer *);
|
||||
void stop_timer(GTimer *);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TIMES
|
||||
|
||||
typedef struct {
|
||||
struct tms start;
|
||||
struct tms end;
|
||||
} TTimer;
|
||||
|
||||
clock_t start_timer(TTimer *);
|
||||
clock_t stop_timer(TTimer *);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue