VirtualBox

Changeset 99901 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
May 22, 2023 2:15:10 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157544
Message:

IPRT: Cleaned up RTThreadGetExecutionTimeMilli and associated testcase.

Location:
trunk/src/VBox/Runtime/r3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/os2/thread-os2.cpp

    r98103 r99901  
    325325
    326326
    327 RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pKernelTime, uint64_t *pUserTime)
    328 {
     327RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pcMsKernelTime, uint64_t *pcMsUserTime)
     328{
     329    RT_NOREF(pcMsKernelTime, pcMsUserTime);
    329330    return VERR_NOT_IMPLEMENTED;
    330331}
  • trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp

    r98103 r99901  
    732732
    733733/** @todo move this into platform specific files. */
    734 RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pKernelTime, uint64_t *pUserTime)
     734RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pcMsKernelTime, uint64_t *pcMsUserTime)
    735735{
    736736#if defined(RT_OS_SOLARIS)
    737737    struct rusage ts;
    738     int rc = getrusage(RUSAGE_LWP, &ts);
    739     if (rc)
    740         return RTErrConvertFromErrno(rc);
    741 
    742     *pKernelTime = ts.ru_stime.tv_sec * 1000 + ts.ru_stime.tv_usec / 1000;
    743     *pUserTime   = ts.ru_utime.tv_sec * 1000 + ts.ru_utime.tv_usec / 1000;
     738    int const rc = getrusage(RUSAGE_LWP, &ts);
     739    AsserReturn(rc == 0, RTErrConvertFromErrno(rc));
     740
     741    *pcMsKernelTime = ts.ru_stime.tv_sec * 1000 + ts.ru_stime.tv_usec / 1000;
     742    *pcMsUserTime   = ts.ru_utime.tv_sec * 1000 + ts.ru_utime.tv_usec / 1000;
    744743    return VINF_SUCCESS;
    745744
    746745#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
    747     /* on Linux, getrusage(RUSAGE_THREAD, ...) is available since 2.6.26 */
     746    /* on Linux, getrusage(RUSAGE_THREAD, ...) is available since 2.6.26. maybe it's slower? */
    748747    struct timespec ts;
    749     int rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
    750     if (rc)
    751         return RTErrConvertFromErrno(rc);
    752 
    753     *pKernelTime = 0;
    754     *pUserTime = (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
     748    int const rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
     749    AssertReturn(rc == 0, RTErrConvertFromErrno(rc));
     750
     751    *pcMsKernelTime = 0;
     752    *pcMsUserTime   = (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
    755753    return VINF_SUCCESS;
    756754
     
    761759    AssertReturn(krc == KERN_SUCCESS, RTErrConvertFromDarwinKern(krc));
    762760
    763     *pKernelTime = ThreadInfo.system_time.seconds * 1000 + ThreadInfo.system_time.microseconds / 1000;
    764     *pUserTime   = ThreadInfo.user_time.seconds   * 1000 + ThreadInfo.user_time.microseconds   / 1000;
    765 
     761    *pcMsKernelTime = ThreadInfo.system_time.seconds * 1000 + ThreadInfo.system_time.microseconds / 1000;
     762    *pcMsUserTime   = ThreadInfo.user_time.seconds   * 1000 + ThreadInfo.user_time.microseconds   / 1000;
    766763    return VINF_SUCCESS;
     764
    767765#elif defined(RT_OS_HAIKU)
    768766    thread_info       ThreadInfo;
     
    770768    AssertReturn(status == B_OK, RTErrConvertFromErrno(status));
    771769
    772     *pKernelTime = ThreadInfo.kernel_time / 1000;
    773     *pUserTime   = ThreadInfo.user_time / 1000;
    774 
     770    *pcMsKernelTime = ThreadInfo.kernel_time / 1000;
     771    *pcMsUserTime   = ThreadInfo.user_time / 1000;
    775772    return VINF_SUCCESS;
     773
    776774#else
     775    RT_NOREF(pcMsKernelTime, pcMsUserTime);
    777776    return VERR_NOT_IMPLEMENTED;
    778777#endif
  • trunk/src/VBox/Runtime/r3/win/thread-win.cpp

    r98103 r99901  
    529529
    530530
    531 RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pKernelTime, uint64_t *pUserTime)
     531RTR3DECL(int) RTThreadGetExecutionTimeMilli(uint64_t *pcMsKernelTime, uint64_t *pcMsUserTime)
    532532{
    533533    uint64_t u64CreationTime, u64ExitTime, u64KernelTime, u64UserTime;
     
    535535    if (GetThreadTimes(GetCurrentThread(), (LPFILETIME)&u64CreationTime, (LPFILETIME)&u64ExitTime, (LPFILETIME)&u64KernelTime, (LPFILETIME)&u64UserTime))
    536536    {
    537         *pKernelTime = u64KernelTime / 10000;    /* GetThreadTimes returns time in 100 ns units */
    538         *pUserTime   = u64UserTime / 10000;    /* GetThreadTimes returns time in 100 ns units */
     537        *pcMsKernelTime = u64KernelTime / 10000;    /* GetThreadTimes returns time in 100 ns units */
     538        *pcMsUserTime   = u64UserTime / 10000;    /* GetThreadTimes returns time in 100 ns units */
    539539        return VINF_SUCCESS;
    540540    }
    541541
    542     int iLastError = GetLastError();
    543     AssertMsgFailed(("GetThreadTimes failed, LastError=%d\n", iLastError));
    544     return RTErrConvertFromWin32(iLastError);
     542    DWORD const dwErr = GetLastError();
     543    AssertMsgFailed(("GetThreadTimes failed, LastError=%d\n", dwErr));
     544    return RTErrConvertFromWin32(dwErr);
    545545}
    546546
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette