Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running time of macOS process #1619

Open
aestriplex opened this issue Feb 23, 2025 · 2 comments
Open

Running time of macOS process #1619

aestriplex opened this issue Feb 23, 2025 · 2 comments
Labels
enhancement Extension or improvement to existing feature MacOS 🍏 MacOS / Darwin related issues

Comments

@aestriplex
Copy link
Contributor

At the moment, the running time of processes on macOS is not updated correctly. I made two commit to try to fix this problem. The branch is rebased on the PR #1617.

Summary:

  • Removed the call to Platform_machTicksToNanoseconds. The proc_taskinfo structure contains the running time (both system and user) of the process. We should just take those value in nanoseconds and convert them in the proper unit. How the kernel handles this calculation (starting from low level cpu-dependent details) should not concern us.
  • I also removed the static function nanosecondsToCentiseconds because for some reason we lose precision (± 1ms) with that calculation. If we divide directly by 1e7, we get a more precise measure. Probably it's a good idea to have an inline function or (maybe better) a macro, just to give a name to that operation and avoid the magic number;
  • Since the GPU percentage update depends on the running time of the process, I updated the condition in the if statement. In fact, suppose we are at the nth iteration of the DarwinProcess_setFromLibprocPidinfo function. We should update the CPU usage value if the total CPU running time of the process is greater than the CPU running time of the process in the previous iteration. To do that, we do not need to use the timeIntervalNS.

TODO:

  • remove the static double Platform_nanosecondsPerMachTick var in Darwin/Platform.c as well. It's only used in the (removed) Platform_machTicksToNanoseconds.
  • remove the Platform_calculateNanosecondsPerMachTick function in Darwin/PlatformHelpers.c. It's only used to set the static double Platform_nanosecondsPerMachTick var once.

I attach here 3 sshot. The first one is the current version (3.3.0), the second one is the darwin-running-time brach, and the last one is top.

  • 3.3.0:
Image
  • darwin-running-time:
Image
  • top:
Image
aestriplex added a commit to aestriplex/htop that referenced this issue Feb 23, 2025
@BenBE BenBE added enhancement Extension or improvement to existing feature MacOS 🍏 MacOS / Darwin related issues labels Feb 24, 2025
@BenBE
Copy link
Member

BenBE commented Feb 24, 2025

Please avoid function-like macros and prefer static inline functions with proper arguments. The compiler will inline as appropriate.

Shouldn't percent_cpu be zero if the process's running time didn't change? Or am I missing something?

BTW: Please do a PR for this branch. It makes commenting the changes easier. If still working on things, marking the PR as draft is fine.

@aestriplex
Copy link
Contributor Author

@BenBE I move this on a pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Extension or improvement to existing feature MacOS 🍏 MacOS / Darwin related issues
Projects
None yet
Development

No branches or pull requests

2 participants