Пример #1
0
Time getThreadCPUTime(void)
{
#if USE_PAPI
    long long usec;
    if ((usec = PAPI_get_virt_usec()) < 0) {
	barf("PAPI_get_virt_usec: %lld", usec);
    }
    return USToTime(usec);

#elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
    {
        static int checked_sysconf = 0;
        static int sysconf_result = 0;
        
        if (!checked_sysconf) {
            sysconf_result = sysconf(_SC_THREAD_CPUTIME);
            checked_sysconf = 1;
        }
        if (sysconf_result != -1) {
            // clock_gettime() gives us per-thread CPU time.  It isn't
            // reliable on Linux, but it's the best we have.
            struct timespec ts;
            int res;
            res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
            if (res == 0) {
                return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec);
            }
        }
    }
#endif
    return getProcessCPUTime();
}
Пример #2
0
double
mut_user_time( void )
{
    Time cpu;
    cpu = getProcessCPUTime();
    return mut_user_time_until(cpu);
}
Пример #3
0
Ticks
getThreadCPUTime(void)
{
    FILETIME creationTime, exitTime, userTime, kernelTime = {0,0};

    if (isWin9x()) return getProcessCPUTime();

    if (!GetThreadTimes(GetCurrentThread(), &creationTime,
			&exitTime, &kernelTime, &userTime)) {
	return 0;
    }

    return fileTimeToTicks(userTime);
}
Пример #4
0
Ticks getThreadCPUTime(void)
{
#if USE_PAPI
    long long usec;
    if ((usec = PAPI_get_virt_usec()) < 0) {
	barf("PAPI_get_virt_usec: %lld", usec);
    }
    return ((usec * TICKS_PER_SECOND) / 1000000);

#elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
    if (sysconf(_POSIX_THREAD_CPUTIME) != -1) {
        // clock_gettime() gives us per-thread CPU time.  It isn't
        // reliable on Linux, but it's the best we have.
        struct timespec ts;
        int res;
        res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
        if (res == 0) {
            return ((Ticks)ts.tv_sec * TICKS_PER_SECOND +
                    ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
        }
    }
#endif
    return getProcessCPUTime();
}
Пример #5
0
void getProcessTimes(Time *user, Time *elapsed)
{
    *user    = getProcessCPUTime();
    *elapsed = getProcessElapsedTime();
}