I'm trying to get the idle residency of the CPU in macOS (C-State C0 residency on x86 unsure on arm64). I am aware you can find this info by running something like sudo powermetrics -i1 -n1 -s cpu_power | grep residency in the terminal, but I need a way to pull this info using C, C , Objective-C, or even Assembly...especially in a way that doesn't need admin privileges.
All I can find regarding this topic is this: Time each CPU core spends in C0 power state, but the answers are not the clearest. Please help!
CodePudding user response:
The powermetrics tool use private API to do this: IOReportStateGetResidency
You could try to import it and with some reversing use yourself too:
https://opensource.apple.com/source/PowerManagement/PowerManagement-637.1.2/pmset/pmset.c
Other than that, there is an example of direct usage of mwait asm, but it is for kernel mode (you will need to write a kext to try to run it on macos):
I know nothing about is it possible to do this without being root or not, and since the API is private - this is for you to research.
