-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
area-System.Threadingin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
Stopwatch.GetTimestamp() doesn't take into account suspend/sleep time on Unix but does on Windows.
Discovered in PowerShell repo PowerShell/PowerShell#18469
Reproduction Steps
- Get
Stopwatch.GetTimestamp()value - Sleep/hibernate your notebook
- Wait a while and wake up the notebook
- Get
Stopwatch.GetTimestamp()value
Expected behavior
Stopwatch.GetTimestamp() value takes into account the sleep time.
Actual behavior
Stopwatch.GetTimestamp() value doesn't take into account the sleep time on Unix.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
Related code
runtime/src/native/libs/System.Native/pal_time.c
Lines 84 to 97 in d320fd9
| uint64_t SystemNative_GetTimestamp(void) | |
| { | |
| #if HAVE_CLOCK_GETTIME_NSEC_NP | |
| return clock_gettime_nsec_np(CLOCK_UPTIME_RAW); | |
| #else | |
| struct timespec ts; | |
| int result = clock_gettime(CLOCK_MONOTONIC, &ts); | |
| assert(result == 0); // only possible errors are if MONOTONIC isn't supported or &ts is an invalid address | |
| (void)result; // suppress unused parameter warning in release builds | |
| return ((uint64_t)(ts.tv_sec) * SecondsToNanoSeconds) + (uint64_t)(ts.tv_nsec); | |
| #endif | |
| } |
uses - the bug seems to be right here. Should it be CLOCK_UPTIME_RAWCLOCK_BOOTTIME?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Threadingin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged