-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
GPU monitoring (percentage and time) in Darwin/macOS #1597
Comments
@BenBE cc @Explorer09
I attach below a sample program that prints the overall GPU usage, which could be a first step to solve the first point, once properly adapted to the htop context.
#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CoreFoundation.h>
int main() {
io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOGPU"));
if (!service) {
printf("GPU not found\n");
return 1;
}
CFMutableDictionaryRef properties = NULL;
if (IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions) != KERN_SUCCESS) {
fprintf(stderr, "Failed to get GPU properties\n");
IOObjectRelease(service);
return 1;
}
CFDictionaryRef perfStats = CFDictionaryGetValue(properties, CFSTR("PerformanceStatistics"));
if (perfStats && CFGetTypeID(perfStats) == CFDictionaryGetTypeID()) {
CFNumberRef rendererUtil, tilerUtil;
rendererUtil = CFDictionaryGetValue(perfStats, CFSTR("Renderer Utilization %"));
tilerUtil = CFDictionaryGetValue(perfStats, CFSTR("Tiler Utilization %"));
int renderer, tiler;
if (rendererUtil) CFNumberGetValue(rendererUtil, kCFNumberIntType, &renderer);
if (tilerUtil) CFNumberGetValue(tilerUtil, kCFNumberIntType, &tiler);
printf("Renderer Utilization: %d%%\n", renderer);
printf("Tiler Utilization: %d%%\n", tiler);
} else {
printf("PerformanceStatistics not found\n");
}
CFRelease(properties);
IOObjectRelease(service);
} |
I added a commit with a draft of the GPU usage meter for macOS. At this point I just replicated the @BenBE Do you have any suggestion? |
@aestriplex Thank you for your effort.
(By the way, you seem to be the first time contributing to htop. Hello and welcome.)
|
Unless the GPU stuff isn't too much code, putting things in The IIRC there's a open PR re the time unit display in #1583, thus avoid to touch that code if possible. When refactoring the GPU meter to the platform-independent code, split the refactoring and the new Darwin implementation to a separate commit. |
Thank you all for your comments, and sorry it took me a while to respond. @Explorer09 Thank you for the welcome message. Ok, I'll move For what concerns the time unit display code that I moved, I'll bring it back in @BenBE Ok, I'll split those changes in two separate commit. Once I have the two commits (hopefully tomorrow) I'll open the pull request. |
The |
I further investigated the point 2. made above, that is, the issue of GPU utilization by process. As I mentioned, Apple has not released any public API for this purpose. The question was whether a way could be found to get a good approximation of this value in some other way. After a bit of research and some testing, I came to the conclusion that no, there is no way that is reliable and stable (over time) to get this kind of metric. The best thing in my opinion is simply not to implement it. After all, more open systems offer more information, and this is nothing new (think of metrics regarding systems on Linux; you couldn't do anything similar with launchd on Mac). On the other hand, even tools such as nvtop simply make an estimate of the processes using the GPU and their relative consumption, but if you compare it with Activity Monitor (the only tool that officially supports this feature), the values are very approximate, not to say simply wrong. |
This is a feature ticket, for people who are more familiar with Darwin/macOS to try and implement.
The Activity Monitor app in macOS has GPU Percentage and GPU Time columns for process monitoring. There is also a "GPU History" feature that shows the GPU usage as a graph.
This webpage (from a third party, not Apple) has brief descriptions and screenshots about the GPU monitoring in macOS: https://www.alphr.com/view-gpu-usage-mac/
It might be possible for such feature to be implemented in htop, too.
After #1288, we have GPU monitoring in Linux now. The GPU meter and columns shouldn't be limited to Linux.
The text was updated successfully, but these errors were encountered: