1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0023019: OSD_Chronometer fails to compile due to lack of clock_gettime() on Mac OS X

Usage of task_info() system function in OSD_Chronometer::GetThreadCPU() to retrieve process info.
This commit is contained in:
kgv 2012-03-13 10:18:47 +04:00
parent 5f8b738ea5
commit 270a5d4e0c

View File

@ -54,6 +54,11 @@
# include <limits.h>
#endif
#if (defined(__APPLE__))
#include <mach/task.h>
#include <mach/mach.h>
#endif
//=======================================================================
//function : GetProcessCPU
//purpose :
@ -77,24 +82,33 @@ void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real&
//function : GetThreadCPU
//purpose :
//=======================================================================
void OSD_Chronometer::GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds)
void OSD_Chronometer::GetThreadCPU (Standard_Real& theUserSeconds,
Standard_Real& theSystemSeconds)
{
UserSeconds = SystemSeconds = 0.;
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
theUserSeconds = theSystemSeconds = 0.0;
#if (defined(__APPLE__))
struct task_thread_times_info aTaskInfo;
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
if (KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO,
(task_info_t )&aTaskInfo, &aTaskInfoCount))
{
theUserSeconds = Standard_Real(aTaskInfo.user_time.seconds) + 0.000001 * aTaskInfo.user_time.microseconds;
theSystemSeconds = Standard_Real(aTaskInfo.system_time.seconds) + 0.000001 * aTaskInfo.system_time.microseconds;
}
#elif defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
// on Linux, only user times are available for threads via clock_gettime()
struct timespec t;
if (!clock_gettime (CLOCK_THREAD_CPUTIME_ID, &t))
{
UserSeconds = t.tv_sec + 0.000000001 * t.tv_nsec;
theUserSeconds = t.tv_sec + 0.000000001 * t.tv_nsec;
}
#elif defined(SOLARIS)
// on Solaris, both user and system times are available as LWP times
struct rusage rut;
if (!getrusage (RUSAGE_LWP, &rut))
{
UserSeconds = rut.ru_utime.tv_sec + 0.000001 * rut.ru_utime.tv_usec;
SystemSeconds = rut.ru_stime.tv_sec + 0.000001 * rut.ru_stime.tv_usec;
theUserSeconds = rut.ru_utime.tv_sec + 0.000001 * rut.ru_utime.tv_usec;
theSystemSeconds = rut.ru_stime.tv_sec + 0.000001 * rut.ru_stime.tv_usec;
}
#else
#pragma error "OS is not supported yet; code to be ported"