Repository navigation
win: don't wrap uv_getrusage() times at 24 hours - #5415
Merged
Merged
Conversation
uv_getrusage() and uv_getrusage_thread() ran the CPU time from GetProcessTimes() and GetThreadTimes() through FileTimeToSystemTime() and added up wHour, wMinute and wSecond. That function treats the value as a date, so anything past 24 hours moved into wDay and got dropped: 25 hours of CPU time read as 1 hour. A busy process on a machine with many cores gets there within hours, and the reported time then jumps backwards. Compute the seconds and microseconds from the FILETIME ticks instead. This also stops rounding tv_usec to whole milliseconds.
bnoordhuis
approved these changes
Nov 6, 2026
bnoordhuis
left a comment
Member
There was a problem hiding this comment.
LGTM with a suggestion, and good catch.
Move NSEC_PER_TICK and TICKS_PER_SEC from fs.c to internal.h, and use them in uv__filetime_to_timeval() and its test, so there is one definition.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uv_getrusage() and uv_getrusage_thread() convert CPU time with FileTimeToSystemTime() and add up wHour, wMinute and wSecond. That function treats the value as a date, so anything over 24 hours moves into wDay and is lost: 25 hours of CPU time reads as 1 hour. A busy process on a many-core machine gets there within hours, and the reported time then jumps backwards.
This computes seconds and microseconds from the FILETIME ticks directly. tv_usec also stops being rounded to whole milliseconds.
A test can't burn 24 hours of CPU, so the conversion is a small inline helper in internal.h and the new test checks that. With the old conversion in the helper it fails with
tv.tv_sec == sec (0 == 86400).