X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49e85177c669d793e84242983a1b1f430e47184e..460be8e161f05ae0e620a9a0a24d13c86c714271:/src/xbt/xbt_os_time.c diff --git a/src/xbt/xbt_os_time.c b/src/xbt/xbt_os_time.c index 2f45c1c14f..b9912ace94 100644 --- a/src/xbt/xbt_os_time.c +++ b/src/xbt/xbt_os_time.c @@ -18,10 +18,25 @@ #endif //Freebsd doesn't provide this clock_gettime flag yet, because it was added too recently (after 1993) -#ifdef __FreeBSD__ +#if defined (CLOCK_PROF) && ! defined (CLOCK_PROCESS_CPUTIME_ID) #define CLOCK_PROCESS_CPUTIME_ID CLOCK_PROF #endif +#ifdef MACOS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + double xbt_os_time(void) { #ifdef HAVE_GETTIMEOFDAY @@ -251,6 +266,10 @@ void xbt_os_cputimer_start(xbt_os_timer_t timer) timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); +#elif defined(HAVE_GETTIMEOFDAY)//return time and not cputime in this case + timer->elapse.tv_sec = 0; + timer->elapse.tv_usec = 0; + gettimeofday(&(timer->start), NULL); #elif defined(_XBT_WIN32) timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; @@ -279,6 +298,10 @@ void xbt_os_cputimer_resume(xbt_os_timer_t timer) timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); +#elif defined(HAVE_GETTIMEOFDAY) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; + gettimeofday(&(timer->start), NULL); #elif defined(_XBT_WIN32) timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; @@ -306,6 +329,8 @@ void xbt_os_cputimer_stop(xbt_os_timer_t timer) { #ifdef HAVE_POSIX_GETTIME clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->stop)); +#elif defined(HAVE_GETTIMEOFDAY) + gettimeofday(&(timer->stop), NULL); #elif defined(_XBT_WIN32) # if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) THROW_UNIMPLEMENTED; @@ -332,6 +357,19 @@ void xbt_os_threadtimer_start(xbt_os_timer_t timer) timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->start)); +#elif defined(HAVE_GETTIMEOFDAY) && defined(MACOS) //attempt for timing of the thread on OSX + timer->elapse.tv_sec = 0; + timer->elapse.tv_usec = 0; + int count = THREAD_BASIC_INFO_COUNT; + thread_basic_info_data_t thi_data; + thread_basic_info_t thi = &thi_data; + thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); + timer->start.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; + timer->start.tv_sec = thi->system_time.seconds + thi->user_time.seconds; +#elif defined(HAVE_GETTIMEOFDAY)//return time and not cputime in this case + timer->elapse.tv_sec = 0; + timer->elapse.tv_usec = 0; + gettimeofday(&(timer->start), NULL); #elif defined(_XBT_WIN32) struct timeval tv; # if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) @@ -359,6 +397,19 @@ void xbt_os_threadtimer_resume(xbt_os_timer_t timer) timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->start)); +#elif defined(HAVE_GETTIMEOFDAY) && defined(MACOS) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; + int count = THREAD_BASIC_INFO_COUNT; + thread_basic_info_data_t thi_data; + thread_basic_info_t thi = &thi_data; + thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); + timer->start.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; + timer->start.tv_sec = thi->system_time.seconds + thi->user_time.seconds; +#elif defined(HAVE_GETTIMEOFDAY) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; + gettimeofday(&(timer->start), NULL); #elif defined(_XBT_WIN32) timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; @@ -385,6 +436,15 @@ void xbt_os_threadtimer_stop(xbt_os_timer_t timer) { #ifdef HAVE_POSIX_GETTIME clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->stop)); +#elif defined(HAVE_GETTIMEOFDAY) && defined(MACOS) + int count = THREAD_BASIC_INFO_COUNT; + thread_basic_info_data_t thi_data; + thread_basic_info_t thi = &thi_data; + thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); + timer->stop.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; + timer->stop.tv_sec = thi->system_time.seconds + thi->user_time.seconds; +#elif defined(HAVE_GETTIMEOFDAY)//if nothing else is available, return just time + gettimeofday(&(timer->stop), NULL); #elif defined(_XBT_WIN32) # if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) THROW_UNIMPLEMENTED;