-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add omrthread_get_self_thread_time()
This function returns the user and system cpu time of the calling thread. Related: eclipse-openj9/openj9#20186 Signed-off-by: Gengchen Tuo <[email protected]>
- Loading branch information
Showing
7 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,7 @@ list(APPEND OBJECTS | |
omrsignal.c | ||
omrsock.c | ||
omrsockptb.c | ||
omrthread.c | ||
) | ||
|
||
if(NOT OMR_OS_WINDOWS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#if defined (LINUX) | ||
#define _GNU_SOURCE | ||
#include <sys/resource.h> | ||
#endif /* defined (LINUX) */ | ||
|
||
#include <stdlib.h> | ||
|
||
#include "omrport.h" | ||
#include "omrportpriv.h" | ||
#include "omrthread.h" | ||
|
||
int32_t omrthread_get_self_thread_time(struct OMRPortLibrary *portLibrary, omrthread_thread_time_t *threadTime) { | ||
#if defined (LINUX) | ||
struct rusage rUsage = {0}; | ||
int rc = getrusage(RUSAGE_THREAD, &rUsage); | ||
|
||
if (-1 == rc) { | ||
return -1; | ||
} | ||
|
||
threadTime->userTime = (SEC_TO_NANO_CONVERSION_CONSTANT * (int64_t)rUsage.ru_utime.tv_sec) + | ||
(MICRO_TO_NANO_CONVERSION_CONSTANT * (int64_t)rUsage.ru_utime.tv_usec); | ||
threadTime->sysTime = (SEC_TO_NANO_CONVERSION_CONSTANT * (int64_t)rUsage.ru_stime.tv_sec) + | ||
(MICRO_TO_NANO_CONVERSION_CONSTANT * (int64_t)rUsage.ru_stime.tv_usec); | ||
#else /* defined (LINUX) */ | ||
omrthread_t self = omrthread_self(); | ||
|
||
int64_t userTime = omrthread_get_user_time(self); | ||
int64_t cpuTime = omrthread_get_cpu_time(self); | ||
|
||
if (-1 == cpuTime || -1 == userTime) { | ||
return -1; | ||
} | ||
|
||
threadTime->sysTime = cpuTime - userTime; | ||
threadTime->userTime = userTime; | ||
#endif /* defined (LINUX) */ | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters