fetch nvidia vram used from nvctrl

This commit is contained in:
FlightlessMango 2020-02-05 03:25:25 +01:00 committed by jackun
parent 23280e0e78
commit 6affdb8c51
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3
5 changed files with 26 additions and 2 deletions

View File

@ -14,6 +14,8 @@
#include <sstream> #include <sstream>
#include <regex> #include <regex>
#include "nvidia_info.h" #include "nvidia_info.h"
#include "memory.h"
#include "nvctrl.h"
using namespace std; using namespace std;
@ -74,6 +76,7 @@ void *getNvidiaGpuInfo(void *){
getNvidiaInfo(); getNvidiaInfo();
gpuLoad = nvidiaUtilization.gpu; gpuLoad = nvidiaUtilization.gpu;
gpuTemp = nvidiaTemp; gpuTemp = nvidiaTemp;
gpuMemUsed = nvidiaMemUsed();
} }
pthread_detach(nvidiaSmiThread); pthread_detach(nvidiaSmiThread);

View File

@ -40,8 +40,10 @@ vklayer_files = files(
'nvml.cpp', 'nvml.cpp',
'file_utils.cpp', 'file_utils.cpp',
'memory.cpp', 'memory.cpp',
'nvctrl.cpp',
) )
lib_xnvctrl = cc.find_library('XNVCtrl')
vklayer_mesa_overlay = shared_library( vklayer_mesa_overlay = shared_library(
'MangoHud', 'MangoHud',
util_files, util_files,
@ -64,7 +66,8 @@ vklayer_mesa_overlay = shared_library(
vulkan_wsi_deps, vulkan_wsi_deps,
libimgui_core_dep, libimgui_core_dep,
dep_dl, dep_dl,
dep_pthread], dep_pthread,
lib_xnvctrl],
include_directories : inc_common, include_directories : inc_common,
link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']), link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']),
install : true install : true

13
src/nvctrl.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "nvctrl.h"
Display *display = XOpenDisplay(NULL);
int nvidiaMemUsed(){
int ret;
XNVCTRLQueryTargetAttribute(display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_USED_DEDICATED_GPU_MEMORY,
&ret);
return ret;
}

5
src/nvctrl.h Normal file
View File

@ -0,0 +1,5 @@
#include <X11/Xlib.h>
#include "NVCtrl/NVCtrl.h"
#include "NVCtrl/NVCtrlLib.h"
int nvidiaMemUsed(void);

View File

@ -29,5 +29,5 @@ void getNvidiaInfo(){
nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice);
nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization); nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization);
nvml.nvmlDeviceGetTemperature(nvidiaDevice, NVML_TEMPERATURE_GPU, &nvidiaTemp); nvml.nvmlDeviceGetTemperature(nvidiaDevice, NVML_TEMPERATURE_GPU, &nvidiaTemp);
nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory); // nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory);
} }