added gpu mem and core clocks to hud

pull/58/head
FlightlessMango 4 years ago
parent f8398c3e7a
commit 4d5f62386b

@ -7,8 +7,8 @@
using namespace std;
int gpuLoad = 0, gpuTemp = 0, cpuTemp = 0;
FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *cpuTempFile = nullptr, *amdGpuVramTotalFile = nullptr, *amdGpuVramUsedFile = nullptr;
int gpuLoad = 0, gpuTemp = 0, cpuTemp = 0, gpuMemClock, gpuCoreClock;
FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *cpuTempFile = nullptr, *amdGpuVramTotalFile = nullptr, *amdGpuVramUsedFile = nullptr, *amdGpuCoreClockFile = nullptr, *amdGpuMemoryClockFile = nullptr;
float gpuMemUsed = 0, gpuMemTotal = 0;
int numCpuCores = std::thread::hardware_concurrency();
@ -19,6 +19,8 @@ struct amdGpu {
int temp;
int64_t memoryUsed;
int64_t memoryTotal;
int MemClock;
int CoreClock;
};
extern struct amdGpu amdgpu;
@ -66,6 +68,8 @@ void *getNvidiaGpuInfo(void *){
gpuLoad = nvidiaUtilization.gpu;
gpuTemp = nvidiaTemp;
gpuMemUsed = float(nvidiaMemory.used / (1024 * 1024)) / 1000;
gpuCoreClock = nvidiaCoreClock;
gpuMemClock = nvidiaMemClock * 2;
}
pthread_detach(gpuThread);
@ -107,6 +111,36 @@ void *getAmdGpuUsage(void *){
amdgpu.memoryUsed /= (1024 * 1024);
gpuMemUsed = float(amdgpu.memoryUsed) / 1000;
}
if (amdGpuCoreClockFile) {
rewind(amdGpuCoreClockFile);
fflush(amdGpuCoreClockFile);
char line[255];
while (fgets(line, sizeof(line), amdGpuCoreClockFile)){
std::string row = line;
row.erase(row.begin());
if (row.find("*") != std::string::npos){
row = std::regex_replace(row, std::regex(R"([^0-9])"), "");
amdgpu.CoreClock = stoi(row);
gpuCoreClock = amdgpu.CoreClock;
}
}
}
if (amdGpuMemoryClockFile) {
rewind(amdGpuMemoryClockFile);
fflush(amdGpuMemoryClockFile);
char line[255];
while (fgets(line, sizeof(line), amdGpuMemoryClockFile)){
std::string row = line;
row.erase(row.begin());
if (row.find("*") != std::string::npos){
row = std::regex_replace(row, std::regex(R"([^0-9])"), "");
amdgpu.MemClock = stoi(row) * 2;
gpuMemClock = amdgpu.MemClock;
}
}
}
pthread_detach(gpuThread);
return NULL;

@ -135,7 +135,7 @@ bool libnvml_loader::Load(const std::string& library_name) {
return false;
}
#if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
#if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
nvmlDeviceGetMemoryInfo =
reinterpret_cast<decltype(this->nvmlDeviceGetMemoryInfo)>(
dlsym(library_, "nvmlDeviceGetMemoryInfo"));
@ -148,6 +148,19 @@ bool libnvml_loader::Load(const std::string& library_name) {
return false;
}
#if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
nvmlDeviceGetClockInfo =
reinterpret_cast<decltype(this->nvmlDeviceGetClockInfo)>(
dlsym(library_, "nvmlDeviceGetClockInfo"));
#endif
#if defined(LIBRARY_LOADER_NVML_H_DT_NEEDED)
nvmlDeviceGetClockInfo = &::nvmlDeviceGetClockInfo;
#endif
if (!nvmlDeviceGetClockInfo) {
CleanUp(true);
return false;
}
loaded_ = true;
return true;
}

@ -30,6 +30,7 @@ class libnvml_loader {
decltype(&::nvmlDeviceGetHandleByIndex_v2) nvmlDeviceGetHandleByIndex_v2;
decltype(&::nvmlDeviceGetHandleByPciBusId_v2) nvmlDeviceGetHandleByPciBusId_v2;
decltype(&::nvmlDeviceGetMemoryInfo) nvmlDeviceGetMemoryInfo;
decltype(&::nvmlDeviceGetClockInfo) nvmlDeviceGetClockInfo;
private:
void CleanUp(bool unload);

@ -3,8 +3,7 @@
#include <nvml.h>
extern nvmlReturn_t result;
extern unsigned int nvidiaTemp, processSamplesCount, lastSeenTimeStamp, *vgpuInstanceSamplesCount;
extern nvmlValueType_t *sampleValType;
extern unsigned int nvidiaTemp, processSamplesCount, *vgpuInstanceSamplesCount, nvidiaCoreClock, nvidiaMemClock;
extern nvmlDevice_t nvidiaDevice;
extern struct nvmlUtilization_st nvidiaUtilization;
extern struct nvmlMemory_st nvidiaMemory;

@ -6,7 +6,7 @@ libnvml_loader nvml("libnvidia-ml.so.1");
nvmlReturn_t result;
nvmlDevice_t nvidiaDevice;
bool nvmlSuccess = false;
unsigned int nvidiaTemp;
unsigned int nvidiaTemp, nvidiaCoreClock, nvidiaMemClock;
struct nvmlUtilization_st nvidiaUtilization;
struct nvmlMemory_st nvidiaMemory {};
@ -30,4 +30,6 @@ void getNvidiaInfo(){
nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization);
nvml.nvmlDeviceGetTemperature(nvidiaDevice, NVML_TEMPERATURE_GPU, &nvidiaTemp);
nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock);
}

@ -820,6 +820,10 @@ void init_gpu_stats(struct device_data *device_data)
amdGpuVramTotalFile = fopen((path + "/device/mem_info_vram_total").c_str(), "r");
if (!amdGpuVramUsedFile)
amdGpuVramUsedFile = fopen((path + "/device/mem_info_vram_used").c_str(), "r");
if (!amdGpuMemoryClockFile)
amdGpuMemoryClockFile = fopen((path + "/device/pp_dpm_mclk").c_str(), "r");
if (!amdGpuCoreClockFile)
amdGpuCoreClockFile = fopen((path + "/device/pp_dpm_sclk").c_str(), "r");
path = path + "/device/hwmon/";
string tempFolder;
@ -1117,7 +1121,7 @@ static void compute_swapchain_display(struct swapchain_data *data)
if (!instance_data->params.no_display){
ImGui::Begin("Main", &open, ImGuiWindowFlags_NoDecoration);
ImGui::BeginTable("hud", 3);
ImGui::BeginTable("hud", instance_data->params.tableCols);
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_time]){
ImGui::TableNextRow();
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.00f), "%s", data->time.c_str());
@ -1133,6 +1137,14 @@ static void compute_swapchain_display(struct swapchain_data *data)
ImGui::TableNextCell();
ImGui::Text("%i%s", gpuTemp, "°C");
}
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock]){
ImGui::TableNextCell();
ImGui::Text("%i", gpuCoreClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data->font1);
ImGui::Text("MHz");
ImGui::PopFont();
}
}
if(instance_data->params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats]){
ImGui::TableNextRow();
@ -1205,6 +1217,14 @@ static void compute_swapchain_display(struct swapchain_data *data)
ImGui::PushFont(data->font1);
ImGui::Text("GB");
ImGui::PopFont();
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_gpu_mem_clock]){
ImGui::TableNextCell();
ImGui::Text("%i", gpuMemClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data->font1);
ImGui::Text("MHz");
ImGui::PopFont();
}
}
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_ram]){
ImGui::TableNextRow();

@ -343,10 +343,17 @@ parse_overlay_config(struct overlay_params *params,
// Command buffer gets reused and timestamps cause hangs for some reason, force off for now
params->enabled[OVERLAY_PARAM_ENABLED_gpu_timing] = false;
params->tableCols = 3;
if (!params->font_size)
params->font_size = 24;
//increase hud width if io read and write
if (params->enabled[OVERLAY_PARAM_ENABLED_io_read] && params->enabled[OVERLAY_PARAM_ENABLED_io_write])
if (params->enabled[OVERLAY_PARAM_ENABLED_io_read] && params->enabled[OVERLAY_PARAM_ENABLED_io_write] && params->width == 280)
params->width = 15 * params->font_size;
if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock] && params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp]){
params->tableCols = 4;
params->width = 20 * params->font_size;
}
}

@ -54,6 +54,8 @@ extern "C" {
OVERLAY_PARAM_BOOL(read_cfg) \
OVERLAY_PARAM_BOOL(io_read) \
OVERLAY_PARAM_BOOL(io_write) \
OVERLAY_PARAM_BOOL(gpu_mem_clock) \
OVERLAY_PARAM_BOOL(gpu_core_clock) \
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
OVERLAY_PARAM_CUSTOM(output_file) \
OVERLAY_PARAM_CUSTOM(position) \
@ -111,6 +113,7 @@ struct overlay_params {
unsigned offset_y;
unsigned vsync;
unsigned crosshair_color;
unsigned tableCols;
float font_size;
float background_alpha;
KeySym toggle_hud;

Loading…
Cancel
Save