-
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
58 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,41 @@ | ||
#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) { | ||
omrthread_t self = omrthread_self(); | ||
|
||
int64_t cpuTime = omrthread_get_cpu_time(self); | ||
if (-1 == cpuTime) { | ||
return -1; | ||
} | ||
|
||
#if defined (LINUX) | ||
struct rusage rUsage = {0}; | ||
int64_t userTime = -1; | ||
int rc = getrusage(RUSAGE_THREAD, &rUsage); | ||
if (0 == rc) { | ||
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); | ||
} else { | ||
userTime = rc; | ||
} | ||
#else /* defined (LINUX) */ | ||
int64_t userTime = omrthread_get_user_time(self); | ||
#endif /* defined (LINUX) */ | ||
|
||
if (-1 == userTime) { | ||
return -1; | ||
} | ||
|
||
threadTime->sysTime = cpuTime - userTime; | ||
threadTime->userTime = userTime; | ||
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