-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Mac OS sensor/support #46
Comments
Hi, Thanks for the try. This was somehow expected. The powercaprapl sensor is based on a linux kernel module. We will need to create a new sensor for mac os I guess. Discussions about that have started in the ARM related issue (about apple m1) that may be redundant but just to mention. I have an old macbook air somewhere so I may start digging on that topic but not before february/march. If anyone with a macbook (maybe better to start with x86 macbooks to tackle one topic at a time) is willing to give it a shot before, it would be awesome :) |
I'd be happy to help but that might be a bit too much for me… |
Ah, here's what you can get out. You can access the RAPL code with a command like so:
this runs powermetrics, pulling out only the cpu_power info, and formats it as a dialect of XML (the I can't see a way to read a stream of info through :( |
FWIW I just realized I'm oftentimes using CoconutBattery, which is a macOS utility to view battery state and usage. It has a "show watt usage" thing. I'd be curious to know how it does that. It doesn't seem to be open source (hmm… should I be using it then? 😝), but the author's email is at the bottom of the landing page. (I don't know their github @, else we could have pinged them here…) |
Great to see there are userspace tools that get such metrics, this is a good sign ! Looking at your message @florimondmanca I just want to mention that battery based metrics, may be a bit different than rapl. Like building a macos sensor based on battery metrics wouldn't work on a mac mini server for instance. It's not necessary an issue, if we name the sensor appropriately and document it to indicate that this is only suitable for a laptop. (it reminds me of powertop, that gets metrics from battery related sensors if available and fallbacks to something else if not...) @mrchrisadams it would be interessting to look at what libraries/bsd internals powermetrics calls. Maybe there we could get a stream/more suitable sort of data ? |
@luiscruz yes maybe we could build. But the powercaprapl sensor being the only available right now it wouldn't be very helpful for mac users to have a binary that gets no metrics :/ |
So, on OS X there is this: https://github.com/beltex/dshb - a nice open source CLI exposing the similar stats as coconut battery. Under the hood, that uses this library, in Swift: https://github.com/beltex/SystemKit And that in turn uses an open sourced library from apple: And this issue here in system kit is about where I ran out of steam when looking at it. I think you'd need to find someone who really understands the powermetrics code to provide pointers, and get an idea of what it's reading to get these numbers. I don't think the powermetrics is open, and but this post here might shed some more light: The metrics are exposed, because iStat pro shows me stuff like this on my mac: But I don't have experience working this close to the metal with OS X. |
The |
Absolutely. We need to rewrite a part of the sensors logic. I should start this refactoring next week as I plan to work on the windows support (#74). |
From reading @luiscruz 's recent, accessible, and quite fun to read piece on measuring energy in computers - syspower is a small OSS programme that can read power usage on non-Apple-Silicon Macs: https://github.com/s4y/syspower/ It's written in C++, is less than 200 lines long, and quite well documented. |
@mrchrisadams 👍 I just tried it out on my macOS laptop, seems to work brilliantly. The default command line program outputs a periodic bundle as follows:
All values are in watts (W), according to the code comments. The value ~13W seems reasonable to me for a mostly idle MBP 2012. Also:
Which seems consistent. It'd be fun to try and integrate this into Edit: okay, seems like the refactor based on conditional compilation is a prerequisite to this in any case. |
Nice! If you come across a solution for Apple M1 CPUs please let me know! 🙏 |
Hello, I just looked into Intel Power Gadgets which uses a kernel driver to read/write from/into MSRs. Obviously, required MSRs are not available but I have a list of the used MSRs (which are mainly the same used by the Windows version): However, I use to run a modified Linux kernel which implements these MSRs so it could be possible to inject (a/k/a write) values into these MSRs and make them available to Scaphandre inside the VM (I already did that for Windows VMs). I also looked into the solution purposed by @mrchrisadams but syspower does not return any value on my Mac OS VM. I did not dig more than that. Now I'm thinking about writing an OS X driver with the capability to read MSRs values, like the Windows driver. As the Scaphandre engine is being rewritten to support multiple OSes, the same method would be applied to read from OS X or Windows NT, right @bpetit? |
hi @Vic063 - I've never come across the term MSR, so I'm having a hard time following along on the last comment. Would you mind sharing a link explaining what they are? |
Hello @mrchrisadams For example, MSRs linked to RAPL can be internally used to protect the processor from over-voltage when someone tries to overclock its CPU. You can find more explanations here: [https://en.wikipedia.org/wiki/Model-specific_register](Model-specific register - Wikipedia) |
Hi ! Yes @Vic063 I think we could use the same methodology in the Scaphandre codebase, as for Windows, to plug to a dedicated MSR based driver. Even if we find a less invasive way to monitor power consumption on MacOS at some point, it may be included in a new sensor, in addition to this one anyway. So your help would be very helpful here 😁 (we also have to release the windows driver codebase soon :P). I also add to this topic this recent very interesting blog post : https://www.rdegges.com/2022/how-to-calculate-the-energy-consumption-of-a-mac/ It seems the author talks mostly about battery data, which is something we could have used for Linux technically, but didn't use because it didn't fit a server use case. However, on this MacOs topic, I have the feeling that most of the use cases are for laptops (if anyone has a mac mini or a mac server raise a hand ! 😂). So maybe, if getting RAPL data on macos is too time consuming, we could use the data from battery consumption as a first iteration ? WDYT ? (I don't say we should do it, but having a sensor based on those data seems interesting too, in this context, especially for MacOS and M1 CPU that are ARM CPU and don't provide RAPL for example...). We could also join him as he seems very interested in the topic ! 🤝 |
Happy to test stuff out for ya -- the approach I outlined in that article is using Apple's In my experience, this is the best way to do it if you want to get an accurate reading (I verified it was accurate using hardware monitors) for the OVERALL energy consumption of the device. The downside (I think?) for your usecase is that it returns the number of watts overall, it isn't looking at how many volts particular components are using at any given moment (CPU vs GPU etc.). |
Firefox 104 introduced a new power profiler for Windows (Windows 11 or Windows 10 with an EMI) and Mac (Apple Silicon only). This provides output in watts in the profiler UI, but the internals are measuring in picowatt-hour. On Mac it's using the task_info API. Discussed in https://www.green-coding.org/blog/firefox-104-energy-measurements/ |
Bug description
Cannot build using Mac OS.
To Reproduce
cargo build
Relevant Output
Environment
Context
I have just realised that this project is targeting linux distributions only. That kinda makes sense from a production perspective. From a dev perspective is quite limiting. Any ideas?
The text was updated successfully, but these errors were encountered: