Open tgharib opened 9 years ago
I guess it might also be useful to add RAM usage and GPU VRAM usage although I feel like I'm pushing it with the feature requests. I better look at the code and see if I can write these features.
The problem with GPU usage is that I am not sure how to get it from NVIDIA's driver. I had a look at their library and didn't find a way to get GPU usage.
@nickguletskii You may want to use this:
nvidia-settings -q GPUUtilization
I have no idea how it translates in terms of API and library that could included in the code, but I use this ABI on a regular basis, to monitor how heavy a game or a program is on my system, for example by using this into a terminal :
> watch -n 1 "nvidia-settings -t --query GPUUtilization 2>/dev/null | awk -F, '{print \$1\"%\"\$2\"%\"}'"
Thank you. I looked into the issue and found that this info can be extracted from NVML. Please see: https://github.com/nickguletskii/GLXOSD/issues/29
NVML does not return the correct values under all hardware. For example, using a GTX 760, "nvidia-smi -q" returns:
Utilization
Gpu : N/A
Memory : N/A
Encoder : N/A
Decoder : N/A
NVML is actually fairly useless in comparison to what NVCtrl provides. I think it's only intended to be used in a headless environment. NVCtrl.h provides something that works (this is used by nvidia-settings):
/*
* NV_CTRL_STRING_GPU_UTILIZATION - Returns the current percentage usage
* of the various components of the GPU.
*
* Current valid tokens are "graphics", "memory", "video" and "PCIe".
* Not all tokens will be reported on all GPUs, and additional tokens
* may be added in the future.
*
* Utilization values are returned as a comma-separated list of
* "token=value" pairs.
* Valid tokens:
*
* Token Value
* "graphics" integer - the percentage usage of graphics engine.
* "memory" integer - the percentage usage of FB.
* "video" integer - the percentage usage of video engine.
* "PCIe" integer - the percentage usage of PCIe bandwidth.
*
*
* Example:
*
* graphics=45, memory=6, video=0, PCIe=0
*
* This attribute may be queried through XNVCTRLQueryTargetStringAttribute()
* using an NV_CTRL_TARGET_TYPE_GPU.
*/
#define NV_CTRL_STRING_GPU_UTILIZATION 53 /* R--G */
An example implementation:
#include <X11/Xlib.h>
#include <NVCtrl/NVCtrlLib.h>
#include <stdio.h>
#include <stdlib.h>
Display *display;
char* get_attr_target_string(int attr, int target_type, int target_id) {
char* c;
if (!XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) {
fprintf(stderr, "Failed to query attribute.");
exit(EXIT_FAILURE);
}
return c;
}
int main(int argc, char** argv) {
if (!(display = XOpenDisplay(NULL))) {
fprintf(stderr, "Cannot open display \"%s\".\n", XDisplayName(NULL));
exit(EXIT_FAILURE);
}
int attr = NV_CTRL_STRING_GPU_UTILIZATION;
char* utilization = get_attr_target_string(attr, NV_CTRL_TARGET_TYPE_GPU, 0);
printf("%s\n", utilization);
free(utilization);
XCloseDisplay(display);
exit(EXIT_SUCCESS);
}
$ gcc -O2 -fPIC utilization.c -lX11 -lXext -lXNVCtrl -o utilization
$ ./utilization
graphics=0, memory=8, video=0, PCIe=0
@ruany is right. I failed to realize this but the NVML API you're trying to use is kind of going deprecated.
The NV-CONTROL X Extension API is the one that should be used it appears.
You can find a definition within nvidia-settings utility sources code.
ftp://download.nvidia.com/XFree86/nvidia-settings/
./doc/NV-CONTROL-API.txt.
As of GLXOSD v3, the OSD can be configured to show GPU utilisation. There is still no support for displaying CPU utilisation though.
@nickguletskii Great, thanks! Is it just the whole GPU Utilisation or can we fine grain between graphics, memory and PCI?
This would explain why I was seeing different data with GLXOSD when swapping out cards. With a GTX 1070, all data is accounted for and appears as expected (very nice work!).
With a GTX 680 though, the only data returned by NVML is the temperature. It's a shame, I wanted to compare the two cards in real time. Just in case, I made sure to test multiple driver versions (367.50, 370.28,375.20). They all behave the same with both cards.
Regardless of how you proceed, great job with GLXOSD thus far. It's coming closer to being a solid rival to Rivatuner and MSI Afterburner. Thank you for your hard work :+1:
By CPU usage, I mean CPU utilization e.g. 49%.