summaryrefslogtreecommitdiff
path: root/src/pal/src/misc/time.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/src/misc/time.cpp')
-rw-r--r--src/pal/src/misc/time.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/pal/src/misc/time.cpp b/src/pal/src/misc/time.cpp
index f84eb3ebc9..2f20c60914 100644
--- a/src/pal/src/misc/time.cpp
+++ b/src/pal/src/misc/time.cpp
@@ -27,12 +27,15 @@ Abstract:
#include <sys/time.h>
#include <errno.h>
#include <string.h>
+#include <sched.h>
#if HAVE_MACH_ABSOLUTE_TIME
#include <mach/mach_time.h>
static mach_timebase_info_data_t s_TimebaseInfo;
#endif
+using namespace CorUnix;
+
SET_DEFAULT_DEBUG_CHANNEL(MISC);
/*++
@@ -281,17 +284,43 @@ QueryPerformanceFrequency(
return retval;
}
+/*++
+Function:
+ QueryThreadCycleTime
+
+Puts the execution time (in nanoseconds) for the thread pointed to by ThreadHandle, into the unsigned long
+pointed to by CycleTime. ThreadHandle must refer to the current thread. Returns TRUE on success, FALSE on
+failure.
+--*/
+
BOOL
PALAPI
QueryThreadCycleTime(
-IN HANDLE ThreadHandle,
-OUT PULONG64 CycleTime)
+ IN HANDLE ThreadHandle,
+ OUT PULONG64 CycleTime
+ )
{
- // UNIXTODO: Implement this!
- ERROR("Needs Implementation!!!");
- return FALSE;
-}
+ ULONG64 calcTime;
+ FILETIME kernelTime, userTime;
+ BOOL retval = TRUE;
+
+ if(!GetThreadTimesInternal(ThreadHandle, &kernelTime, &userTime))
+ {
+ ASSERT("Could not get cycle time for current thread");
+ retval = FALSE;
+ goto EXIT;
+ }
+
+ calcTime = ((ULONG64)kernelTime.dwHighDateTime << 32);
+ calcTime += (ULONG64)kernelTime.dwLowDateTime;
+ calcTime += ((ULONG64)userTime.dwHighDateTime << 32);
+ calcTime += (ULONG64)userTime.dwLowDateTime;
+ *CycleTime = calcTime;
+
+EXIT:
+ return retval;
+}
/*++
Function: