-
Couldn't load subscription status.
- Fork 5.2k
Description
Description
Let's consider this process on my system that has PID of 66358 (as shown by the Activity Monitor):

It has about 22 hours of CPU time.
Reproduction Steps
Write and run this program:
using System.Diagnostics;
var process = Process.GetProcessById(66358);
Console.WriteLine(process.TotalProcessorTime);
Console.WriteLine(process.TotalProcessorTime * 42);Expected behavior
This program should output about 22 hours in the first line, and some nonsensical value in the second line.
Actual behavior
00:00:32.3739259
00:22:39.7048878
Regression?
No response
Known Workarounds
Multiply the result by 42 on ARM64 Mac :)
Configuration
Macbook Pro M2 Max, ARM64
.NET SDK 7.0.202
Other information
This is not the first time this API behaves problematically on macOS. The previous fix was dotnet/corefx#37637
I suspect that the fix was incorrect: in reality, we should call mach_timebase_info to get the coefficient to convert the value returned by the underlying API to nanoseconds, and apparently that value may be system-dependent.