Fix system info and stats parsing

pull/20/head
jackun 4 years ago
parent 217b65f0e9
commit 6d3d869586
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -17,7 +17,7 @@
using namespace std; using namespace std;
int gpuLoad, gpuTemp, cpuTemp; int gpuLoad = 0, gpuTemp = 0, cpuTemp = 0;
FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *cpuTempFile = nullptr; FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *cpuTempFile = nullptr;

@ -8,9 +8,9 @@
using namespace std; using namespace std;
string os, cpu, gpu, ram, kernel, driver, deviceName; string os, cpu, gpu, ram, kernel, driver;
bool sysInfoFetched; bool sysInfoFetched = false;
int gpuLoadLog,cpuLoadLog,log_period; int gpuLoadLog = 0, cpuLoadLog = 0, log_period = 0;
struct logData{ struct logData{
double fps; double fps;

@ -44,6 +44,8 @@
#include "vk_enum_to_str.h" #include "vk_enum_to_str.h"
#include <vulkan/vk_util.h> #include <vulkan/vk_util.h>
#include "string_utils.h"
#include "file_utils.h"
#include "cpu_gpu.h" #include "cpu_gpu.h"
#include "logging.h" #include "logging.h"
#include "keybinds.h" #include "keybinds.h"
@ -103,6 +105,7 @@ struct device_data {
/* For a single frame */ /* For a single frame */
struct frame_stat frame_stats; struct frame_stat frame_stats;
bool gpu_stats = false;
}; };
/* Mapped from VkCommandBuffer */ /* Mapped from VkCommandBuffer */
@ -825,59 +828,107 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
} }
if (!sysInfoFetched) { if (!sysInfoFetched) {
deviceName = device_data->properties.deviceName;
ram = exec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'"); ram = exec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'");
trim(ram);
cpu = exec("cat /proc/cpuinfo | grep 'model name' | tail -n1 | sed 's/^.*: //' | sed 's/([^)]*)/()/g' | tr -d '(/)'"); cpu = exec("cat /proc/cpuinfo | grep 'model name' | tail -n1 | sed 's/^.*: //' | sed 's/([^)]*)/()/g' | tr -d '(/)'");
trim(cpu);
kernel = exec("uname -r"); kernel = exec("uname -r");
trim(kernel);
os = exec("cat /etc/*-release | grep 'PRETTY_NAME' | cut -d '=' -f 2-"); os = exec("cat /etc/*-release | grep 'PRETTY_NAME' | cut -d '=' -f 2-");
os.erase(remove( os.begin(), os.end(), '\"' ),os.end()); os.erase(remove(os.begin(), os.end(), '\"' ), os.end());
gpu = exec("lspci | grep VGA | head -n1 | awk -vRS=']' -vFS='[' '{print $2}' | sed '/^$/d' | tail -n1"); trim(os);
gpu = device_data->properties.deviceName;
driver = exec("glxinfo | grep 'OpenGL version' | sed 's/^.*: //' | cut -d' ' --output-delimiter=$'\n' -f1- | grep -v '(' | grep -v ')' | tr '\n' ' ' | cut -c 1-"); driver = exec("glxinfo | grep 'OpenGL version' | sed 's/^.*: //' | cut -d' ' --output-delimiter=$'\n' -f1- | grep -v '(' | grep -v ')' | tr '\n' ' ' | cut -c 1-");
ram.pop_back(); trim(driver);
cpu.pop_back(); //driver = itox(device_data->properties.driverVersion);
kernel.pop_back();
os.pop_back();
gpu.pop_back();
driver.pop_back();
log_period = (log_period_env) ? std::stoi(log_period_env) : 100; #ifndef NDEBUG
std::cout << "Ram:" << ram << "\n"
<< "Cpu:" << cpu << "\n"
<< "Kernel:" << kernel << "\n"
<< "Os:" << os << "\n"
<< "Gpu:" << gpu << "\n"
<< "Driver:" << driver << std::endl;
#endif
if (!log_period_env || !try_stoi(log_period, log_period_env))
log_period = 100;
if (log_period == 0) if (log_period == 0)
out.open("/tmp/mango", ios::out | ios::app); out.open("/tmp/mango", ios::out | ios::app);
if(log_duration_env) if (log_duration_env && !try_stoi(duration, log_duration_env))
duration = std::stoi(log_duration_env); duration = 0;
if (device_data->properties.vendorID == 0x8086){
libnvml_loader nvml("libnvidia-ml.so.1");
if (nvml.IsLoaded()) {
device_data->properties.vendorID = 0x10de;
device_data->gpu_stats = true;
}
}
if (device_data->properties.vendorID == 0x10de)
device_data->gpu_stats = checkNvidia();
// coreCounting(); // coreCounting();
if (deviceName.find("Radeon") != std::string::npos || deviceName.find("AMD") != std::string::npos) { if (device_data->properties.vendorID == 0x8086 || gpu.find("Radeon") != std::string::npos || gpu.find("AMD") != std::string::npos) {
amdGpuFile = fopen("/sys/class/drm/card0/device/gpu_busy_percent", "r"); string path;
string tempFolder = exec("ls /sys/class/drm/card0/device/hwmon/"); string drm = "/sys/class/drm/";
tempFolder.pop_back(); auto dirs = ls(drm.c_str(), "card");
string tempLocation = "/sys/class/drm/card0/device/hwmon/" + tempFolder + "/temp1_input"; for (auto& dir : dirs) {
amdTempFile = fopen(tempLocation.c_str(), "r"); path = drm + dir;
#ifndef NDEBUG
std::cerr << "amdgpu path check: " << path << "/device/vendor" << std::endl;
#endif
string line = read_line(path + "/device/vendor");
trim(line);
if (line != "0x1002")
continue;
#ifndef NDEBUG
std::cerr << "using amdgpu path: " << path << std::endl;
#endif
if (file_exists(path + "/device/gpu_busy_percent")) {
amdGpuFile = fopen((path + "/device/gpu_busy_percent").c_str(), "r");
path = path + "/device/hwmon/";
string tempFolder;
if (find_folder(path, "hwmon", tempFolder)) {
path = path + tempFolder + "/temp1_input";
amdTempFile = fopen(path.c_str(), "r");
device_data->gpu_stats = true;
device_data->properties.vendorID = 0x1002;
break;
}
}
}
} }
if (cpu.find("Intel") != std::string::npos){
string cpuTempFolder = exec("ls /sys/devices/platform/coretemp.0/hwmon/"); if (cpu.find("Intel") != std::string::npos) {
cpuTempFolder.pop_back();
cpuTempLocation = "/sys/devices/platform/coretemp.0/hwmon/" + cpuTempFolder + "/temp1_input";
cpuTempFile = fopen(cpuTempLocation.c_str(), "r");
} else {
string name;
string path; string path;
for (size_t i = 0; i < 10; i++) if (find_folder("/sys/devices/platform/coretemp.0/hwmon/", "hwmon", path)) {
path = "/sys/devices/platform/coretemp.0/hwmon/" + path + "/temp1_input";
if (file_exists(path))
cpuTempFile = fopen(path.c_str(), "r");
}
} else {
string name, path;
string hwmon = "/sys/class/hwmon/";
auto dirs = ls(hwmon.c_str());
for (auto& dir : dirs)
{ {
path = "/sys/class/hwmon/hwmon" + to_string(i) + "/name"; path = hwmon + dir;
name = exec("cat " + path); name = read_line(path + "/name");
name.pop_back(); std::cerr << "hwmon: sensor name: " << name << std::endl;
if (name == "k10temp" || name == "zenpower"){ if (name == "k10temp" || name == "zenpower"){
cpuTempLocation = "/sys/class/hwmon/hwmon" + to_string(i) + "/temp1_input"; path += "/temp1_input";
break; break;
} }
} }
if (cpuTempLocation.empty()) { if (!file_exists(path)) {
cout << "MANGOHUD: Could not find temp location" << endl; cout << "MANGOHUD: Could not find temp location" << endl;
} else { } else {
cpuTempFile = fopen(cpuTempLocation.c_str(), "r"); cpuTempFile = fopen(path.c_str(), "r");
} }
} }
// Adjust height for DXVK/VKD3D version number // Adjust height for DXVK/VKD3D version number
@ -888,12 +939,6 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
instance_data->params.height += 24 / 2; instance_data->params.height += 24 / 2;
} }
} }
if (device_data->properties.vendorID == 0x8086){
libnvml_loader nvml("libnvidia-ml.so.1");
if (nvml.IsLoaded())
device_data->properties.vendorID = 0x10de;
}
sysInfoFetched = true; sysInfoFetched = true;
} }
@ -917,14 +962,17 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
elapsed >= instance_data->params.fps_sampling_period) { elapsed >= instance_data->params.fps_sampling_period) {
cpuStats.UpdateCPUData(); cpuStats.UpdateCPUData();
cpuLoadLog = cpuStats.GetCPUDataTotal().percent; cpuLoadLog = cpuStats.GetCPUDataTotal().percent;
pthread_create(&cpuInfoThread, NULL, &cpuInfo, NULL); if (cpuTempFile)
pthread_create(&cpuInfoThread, NULL, &cpuInfo, NULL);
// get gpu usage if (device_data->gpu_stats) {
if (device_data->properties.vendorID == 0x10de) // get gpu usage
pthread_create(&nvidiaSmiThread, NULL, &getNvidiaGpuInfo, NULL); if (device_data->properties.vendorID == 0x10de)
pthread_create(&nvidiaSmiThread, NULL, &getNvidiaGpuInfo, NULL);
if (device_data->properties.vendorID == 0x1002) if (device_data->properties.vendorID == 0x1002)
pthread_create(&gpuThread, NULL, &getAmdGpuUsage, NULL); pthread_create(&gpuThread, NULL, &getAmdGpuUsage, NULL);
}
// update variables for logging // update variables for logging
// cpuLoadLog = cpuArray[0].value; // cpuLoadLog = cpuArray[0].value;
@ -1075,7 +1123,7 @@ static void compute_swapchain_display(struct swapchain_data *data)
} }
if (displayHud){ if (displayHud){
if (device_data->properties.vendorID == 0x10de || device_data->properties.vendorID == 0x1002){ if (device_data->gpu_stats){
ImGui::TextColored(ImVec4(0.180, 0.592, 0.384, 1.00f), "GPU"); ImGui::TextColored(ImVec4(0.180, 0.592, 0.384, 1.00f), "GPU");
ImGui::SameLine(hudFirstRow); ImGui::SameLine(hudFirstRow);
ImGui::Text("%i%%", gpuLoad); ImGui::Text("%i%%", gpuLoad);

Loading…
Cancel
Save