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

feature: Use ps as fallback to query CPU usage under macOS (#380) #390

Conversation

Frederick888
Copy link
Contributor

@Frederick888 Frederick888 commented Jan 14, 2021

Description

When running without elevated permissions under macOS, sysinfo cannot
query states of processes by root user, which results in 0.0% CPU usage
for all this kind of processes (and state = Unknown).

Here we use ps, which has SUID, as a fallback to query CPU usages.
This can be potentially applied to other properties if needed in the
future (we'll need a proper struct and parser).

Issue

Closes: #380

Type of change

  • New feature (non-breaking change which adds functionality)

Test methodology

Furthermore, please tick which platforms this change was tested on:

  • Windows
  • macOS
  • Linux

Checklist

  • Change has been tested to work, and does not cause new breakage unless intended
  • Code has been self-reviewed
  • Documentation has been added/updated if needed (README, help menu, etc.)
  • Passes CI pipeline (clippy check and cargo test check)
  • Areas your change affects have been linted using rustfmt (cargo fmt)
  • No merge conflicts arise from the change

Other information

I admit this is quite hacky and I'm not sure if it's worth the effort maintaining, but unfortunately users are not always able to run btm with elevated permissions and this has come quite helpful to myself.

…Tsang#380)

When running without elevated permissions under macOS, sysinfo cannot
query states of processes by root user, which results in 0.0% CPU usage
for all this kind of processes (and state = Unknown).

Here we use `ps`, which has SUID, as a fallback to query CPU usages.
This can be potentially applied to other properties if needed in the
future (we'll need a proper struct and parser).
@Frederick888 Frederick888 force-pushed the macos-non-root-cpu-usage-workaround branch from 2629c1b to b297377 Compare January 14, 2021 01:06
@ClementTsang
Copy link
Owner

Sorry for the late response, been a bit busy recently - I'll take a look within a day or two of the PR.

@ClementTsang
Copy link
Owner

Sorry for taking so long, LGTM and works fine in my macOS environment.

@all-contributors add @Frederick888 for code

@allcontributors
Copy link
Contributor

@ClementTsang

I've put up a pull request to add @Frederick888! 🎉

@ClementTsang ClementTsang merged commit b8d3b68 into ClementTsang:master Jan 22, 2021
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.

CPU utilization is not shown for certain processes on macOS
2 participants