Skip to content

Process::TotalProcessorTime is about 42 times lower than expected on ARM64 Mac #91958

Closed

Description

@ForNeVeR

Description

Let's consider this process on my system that has PID of 66358 (as shown by the Activity Monitor):
image

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.

Activity

  1. ghost added
    untriaged
    on Sep 12, 2023
  2. added
    os-macos
    help wanted
    and removed
    untriaged
    on Sep 13, 2023
  3. added this to the 9.0.0 milestone on Sep 13, 2023
  4. adamsitnik commented on Sep 13, 2023

    @adamsitnik
    Member

    Hi @ForNeVeR

    Thank you for a detailed bug report. Since you have tracked down the issue, would you be also interested in sending a PR with a fix?

  5. ForNeVeR commented on Sep 13, 2023

    @ForNeVeR
    ContributorAuthor

    Yep, sure, I'll try to get it done.

  6. 8 remaining items

  7. added 10 commits that reference this issue on Sep 25, 2023
    999d6ae
    4ba25eb
    8932990
    354d181
    d31f96c
    473d7fc
    ce50c65
  8. added a commit that references this issue on Oct 16, 2023
    fb74d89
  9. ghost locked as resolved and limited conversation to collaborators on Nov 15, 2023
  10. added a commit that references this issue on Mar 22, 2024
    5e07e66
  11. added a commit that references this issue on Apr 30, 2024
    8acc1b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Diagnostics.Processhelp wantedos-macos

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions