Skip to content

win: don't wrap uv_getrusage() times at 24 hours - #5415

Merged
bnoordhuis merged 2 commits into
libuv:v1.xfrom
b84330808:win-getrusage-24h
Nov 9, 2026
Merged

bnoordhuis merged 2 commits into
libuv:v1.xfrom
b84330808:win-getrusage-24h

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

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).

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 bnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion, and good catch.

Comment thread test/test-getrusage.c Resolved
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.
@bnoordhuis
bnoordhuis merged commit 8f805cf into libuv:v1.x Nov 9, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants