seconds() gives difftime to program start, lower priority for getrusage() and times()
This commit is contained in:
parent
26f2fec689
commit
60554855d8
|
|
@ -171,20 +171,20 @@ printres(char *name)
|
|||
perf_timer_stop(&timer);
|
||||
perf_timer_elapsed_sec_ms(&timer, &total_sec, &total_msec);
|
||||
|
||||
#ifdef USE_OMP
|
||||
cpu_elapsed = "elapsed";
|
||||
#ifdef USE_OMP // this order have to be same as
|
||||
cpu_elapsed = "elapsed"; // the order in seconds() misc_time.c
|
||||
#elif defined(HAVE_QUERYPERFORMANCECOUNTER)
|
||||
cpu_elapsed = "elapsed";
|
||||
#elif defined(HAVE_CLOCK_GETTIME)
|
||||
cpu_elapsed = "elapsed";
|
||||
#elif defined(HAVE_GETTIMEOFDAY)
|
||||
cpu_elapsed = "elapsed";
|
||||
#elif defined(HAVE_FTIME)
|
||||
cpu_elapsed = "elapsed";
|
||||
#elif defined(HAVE_TIMES)
|
||||
cpu_elapsed = "CPU";
|
||||
#elif defined(HAVE_GETRUSAGE)
|
||||
cpu_elapsed = "CPU";
|
||||
#elif defined(HAVE_FTIME)
|
||||
cpu_elapsed = "elapsed";
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -118,37 +118,42 @@ seconds(void)
|
|||
{
|
||||
#ifdef USE_OMP
|
||||
// Usage of OpenMP time function
|
||||
return omp_get_wtime();
|
||||
return(omp_get_wtime() - timebegin.secs);
|
||||
#elif defined(HAVE_QUERYPERFORMANCECOUNTER)
|
||||
// Windows (MSC and mingw) specific implementation
|
||||
LARGE_INTEGER frequency, counter;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
QueryPerformanceCounter(&counter);
|
||||
return (double)counter.QuadPart / frequency.QuadPart;
|
||||
return ((double)counter.QuadPart / frequency.QuadPart - timebegin.secs);
|
||||
#elif defined(HAVE_CLOCK_GETTIME)
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ts.tv_sec + ts.tv_nsec / 1e9;
|
||||
return (ts.tv_sec + ts.tv_nsec / 1e9 - timebegin.secs);
|
||||
#elif defined(HAVE_GETTIMEOFDAY)
|
||||
// Usage of gettimeofday
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec + tv.tv_usec / 1e6;
|
||||
#elif defined(HAVE_TIMES)
|
||||
// Usage of times
|
||||
struct tms t;
|
||||
clock_t ticks = times(&t);
|
||||
return (double)ticks / sysconf(_SC_CLK_TCK);
|
||||
#elif defined(HAVE_GETRUSAGE)
|
||||
// Usage of getrusage
|
||||
struct rusage usage;
|
||||
getrusage(RUSAGE_SELF, &usage);
|
||||
return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6;
|
||||
return (tv.tv_sec + tv.tv_usec / 1e6 - timebegin.secs);
|
||||
#elif defined(HAVE_FTIME)
|
||||
// Usage of ftime
|
||||
struct timeb tb;
|
||||
PerfTime timenow;
|
||||
int sec, msec;
|
||||
ftime(&tb);
|
||||
return tb.time + tb.millitm / 1000.0;
|
||||
timenow.seconds = tb.time;
|
||||
timenow.milliseconds = tb.millitm;
|
||||
timediff(&timenow, &timebegin, &sec, &msec);
|
||||
return(sec + (double) msec / 1000.0);
|
||||
#elif defined(HAVE_TIMES)
|
||||
// Usage of times
|
||||
struct tms tmsbuf;
|
||||
clock_t ticks = times(&tmsbuf);
|
||||
return((double) tmsbuf.tms_utime / HZ);
|
||||
#elif defined(HAVE_GETRUSAGE)
|
||||
// Usage of getrusage
|
||||
struct rusage ruse;
|
||||
getrusage(RUSAGE_SELF, &ruse);
|
||||
return ((double)ruse.ru_utime.tv_sec + (double) ruse.ru_utime.tv_usec / 1000000.0);
|
||||
#else
|
||||
#error "No timer function available."
|
||||
#endif
|
||||
|
|
@ -173,8 +178,8 @@ void perf_timer_elapsed_sec_ms(const PerfTimer *timer, int *seconds, int *millis
|
|||
|
||||
void perf_timer_get_time(PerfTime *time)
|
||||
{
|
||||
double secs = seconds();
|
||||
time->seconds = (int)secs;
|
||||
time->milliseconds = (int)((secs - time->seconds) * 1000.0);
|
||||
time->secs = seconds();
|
||||
time->seconds = (int)time->secs;
|
||||
time->milliseconds = (int)((time->secs - time->seconds) * 1000.0);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ typedef struct {
|
|||
} PerfTimer;
|
||||
|
||||
typedef struct {
|
||||
double secs;
|
||||
int seconds;
|
||||
int milliseconds;
|
||||
} PerfTime;
|
||||
|
|
|
|||
|
|
@ -1930,7 +1930,6 @@ void SetAnalyse(
|
|||
static char OldAn2[128]; /* Previous analysis type */
|
||||
static char olds2[128]; /* previous output */
|
||||
static PerfTime timebefore2; /* previous time stamp */
|
||||
int sdiffsec, sdiffmillisec; /* differences current time minus start time stamp */
|
||||
|
||||
/*set the two thread ids */
|
||||
unsigned int ng_idl = threadid_self();
|
||||
|
|
@ -1973,7 +1972,6 @@ void SetAnalyse(
|
|||
/* get current time */
|
||||
perf_timer_get_time(&timenow);
|
||||
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
|
||||
timediff(&timenow, &timebegin, &sdiffsec, &sdiffmillisec);
|
||||
|
||||
s = TMALLOC(char, 128);
|
||||
|
||||
|
|
@ -2034,7 +2032,7 @@ void SetAnalyse(
|
|||
/* info when previous analysis period has finished */
|
||||
if (strcmp(OldAn, Analyse)) {
|
||||
if ((ft_nginfo || ft_ngdebug) && (strcmp(OldAn, "")))
|
||||
printf("%s finished after %5.3f seconds.\n", OldAn, (double)sdiffsec + (double)sdiffmillisec / 1000.);
|
||||
printf("%s finished after %5.3f seconds.\n", OldAn, seconds());
|
||||
if(thread1)
|
||||
strncpy(OldAn1, Analyse, 127);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -223,7 +223,6 @@ SetAnalyse(char *Analyse, /* in: analysis type */
|
|||
static PerfTime timebefore; /* previous time stamp */
|
||||
PerfTime timenow; /* actual time stamp */
|
||||
int diffsec, diffmillisec; /* differences actual minus prev. time stamp */
|
||||
int sdiffsec, sdiffmillisec; /* differences actual minus start time stamp */
|
||||
|
||||
WaitForIdle();
|
||||
|
||||
|
|
@ -235,7 +234,6 @@ SetAnalyse(char *Analyse, /* in: analysis type */
|
|||
/* get actual time */
|
||||
perf_timer_get_time(&timenow);
|
||||
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
|
||||
timediff(&timenow, &timebegin, &sdiffsec, &sdiffmillisec);
|
||||
|
||||
OldPercent = DecaPercent;
|
||||
/* output only into hwAnalyse window and if time elapsed is larger than
|
||||
|
|
@ -262,7 +260,7 @@ SetAnalyse(char *Analyse, /* in: analysis type */
|
|||
/* info when previous analysis period has finished */
|
||||
if (strcmp(OldAn, Analyse)) {
|
||||
if ((ft_nginfo || ft_ngdebug) && (strcmp(OldAn, "")))
|
||||
win_x_printf("%s finished after %5.3f seconds.\n", OldAn, (double)sdiffsec + (double)sdiffmillisec / 1000.);
|
||||
win_x_printf("%s finished after %5.3f seconds.\n", OldAn, seconds());
|
||||
strncpy(OldAn, Analyse, 127);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue