mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +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:
parent
5f8b738ea5
commit
270a5d4e0c
@ -54,6 +54,11 @@
|
|||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__APPLE__))
|
||||||
|
#include <mach/task.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : GetProcessCPU
|
//function : GetProcessCPU
|
||||||
//purpose :
|
//purpose :
|
||||||
@ -77,27 +82,36 @@ void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real&
|
|||||||
//function : GetThreadCPU
|
//function : GetThreadCPU
|
||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
void OSD_Chronometer::GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds)
|
void OSD_Chronometer::GetThreadCPU (Standard_Real& theUserSeconds,
|
||||||
|
Standard_Real& theSystemSeconds)
|
||||||
{
|
{
|
||||||
UserSeconds = SystemSeconds = 0.;
|
theUserSeconds = theSystemSeconds = 0.0;
|
||||||
|
#if (defined(__APPLE__))
|
||||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
|
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()
|
// on Linux, only user times are available for threads via clock_gettime()
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
if ( ! clock_gettime(CLOCK_THREAD_CPUTIME_ID,&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)
|
#elif defined(SOLARIS)
|
||||||
// on Solaris, both user and system times are available as LWP times
|
// on Solaris, both user and system times are available as LWP times
|
||||||
struct rusage rut;
|
struct rusage rut;
|
||||||
if ( ! getrusage (RUSAGE_LWP, &rut) )
|
if (!getrusage (RUSAGE_LWP, &rut))
|
||||||
{
|
{
|
||||||
UserSeconds = rut.ru_utime.tv_sec + 0.000001 * rut.ru_utime.tv_usec;
|
theUserSeconds = 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;
|
theSystemSeconds = rut.ru_stime.tv_sec + 0.000001 * rut.ru_stime.tv_usec;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#pragma error "OS is not supported yet; code to be ported"
|
#pragma error "OS is not supported yet; code to be ported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user