Added graphs

pull/379/head
FlightlessMango 4 years ago
parent 6e7747c73c
commit cc38924997

@ -25,7 +25,7 @@ void parseConfigLine(std::string line, std::unordered_map<std::string,std::strin
trim(param); trim(param);
trim(value); trim(value);
if (!param.empty()){ if (!param.empty()){
HUDElements.options.push_back(param); HUDElements.options.push_back({param, value});
options[param] = value; options[param] = value;
} }
} }

@ -3,23 +3,6 @@
#include "cpu.h" #include "cpu.h"
#include "memory.h" #include "memory.h"
#include "mesa/util/macros.h" #include "mesa/util/macros.h"
// void HudElements::newRow(){
// ImGui::TableNextRow();
// }
// void HudElements::text(){
// auto text = HUDElements.options.at(HUDElements.place);
// text.erase(std::remove(text.begin(), text.end(), '%'), text.end());
// size_t underscores_found = text.find("_");
// // remove all underscores
// for (size_t i = 0; i < underscores_found; i++)
// {
// text.replace(text.find("_"), 1, " ");
// }
// printf("%s\n", text.c_str());
// ImGui::Text(text.c_str());
// }
void HudElements::time(){ void HudElements::time(){
ImGui::TableNextRow(); ImGui::TableNextRow();
@ -102,31 +85,31 @@ void HudElements::cpu_stats(){
ImGui::TableNextCell(); ImGui::TableNextCell();
auto text_color = HUDElements.sw_stats->colors.text; auto text_color = HUDElements.sw_stats->colors.text;
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change]){ if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change]){
int cpu_load_percent = int(cpuStats.GetCPUDataTotal().percent); int cpu_load_percent = int(cpuStats.GetCPUDataTotal().percent);
struct LOAD_DATA cpu_data = {HUDElements.sw_stats->colors.cpu_load_high, struct LOAD_DATA cpu_data = {HUDElements.sw_stats->colors.cpu_load_high,
HUDElements.sw_stats->colors.cpu_load_med, HUDElements.sw_stats->colors.cpu_load_med,
HUDElements.sw_stats->colors.cpu_load_low, HUDElements.sw_stats->colors.cpu_load_low,
HUDElements.params->cpu_load_value[0], HUDElements.params->cpu_load_value[0],
HUDElements.params->cpu_load_value[1] HUDElements.params->cpu_load_value[1]
}; };
auto load_color = change_on_load_temp(cpu_data, cpu_load_percent); auto load_color = change_on_load_temp(cpu_data, cpu_load_percent);
right_aligned_text(load_color, HUDElements.ralign_width, "%d", cpu_load_percent); right_aligned_text(load_color, HUDElements.ralign_width, "%d", cpu_load_percent);
ImGui::SameLine(0, 1.0f); ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color, "%%"); ImGui::TextColored(load_color, "%%");
} }
else { else {
right_aligned_text(text_color, HUDElements.ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent)); right_aligned_text(text_color, HUDElements.ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f); ImGui::SameLine(0, 1.0f);
ImGui::Text("%%"); ImGui::Text("%%");
} }
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp]){ if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp]){
ImGui::TableNextCell(); ImGui::TableNextCell();
right_aligned_text(HUDElements.sw_stats->colors.text, HUDElements.ralign_width, "%i", cpuStats.GetCPUDataTotal().temp); right_aligned_text(HUDElements.sw_stats->colors.text, HUDElements.ralign_width, "%i", cpuStats.GetCPUDataTotal().temp);
ImGui::SameLine(0, 1.0f); ImGui::SameLine(0, 1.0f);
ImGui::Text("°C"); ImGui::Text("°C");
} }
} }
} }
@ -360,39 +343,149 @@ void HudElements::media_player(){
#endif #endif
} }
void HudElements::sort_elements(std::string string){ void HudElements::graphs(){
if (string == "version")
ordered_functions.push_back(version); ImGui::Dummy(ImVec2(0.0f, real_font_size.y));
if (string == "time") std::string value = HUDElements.ordered_functions[HUDElements.place].second;
ordered_functions.push_back(time); std::vector<float> arr;
if (string == "gpu_stats")
ordered_functions.push_back(gpu_stats); for (size_t i = 0; i < 50; i++)
if (string == "cpu_stats") {
ordered_functions.push_back(cpu_stats); arr.push_back(0);
if (string == "core_load") }
ordered_functions.push_back(core_load); if (value == "cpu_load"){
if (string == "io_stats") for (auto& it : graph_data){
ordered_functions.push_back(io_stats); arr.push_back(float(it.cpu_load));
if (string == "vram") arr.erase(arr.begin());
ordered_functions.push_back(vram); }
if (string == "ram") HUDElements.max = 100; HUDElements.min = 0;
ordered_functions.push_back(ram); ImGui::PushFont(HUDElements.sw_stats->font1);
if (string == "fps") ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "CPU Load");
ordered_functions.push_back(fps); ImGui::PopFont();
if (string == "engine_version") }
ordered_functions.push_back(engine_version);
if (string == "gpu_name") if (value == "gpu_load"){
ordered_functions.push_back(gpu_name); for (auto& it : graph_data){
if (string == "vulkan_driver") arr.push_back(float(it.gpu_load));
ordered_functions.push_back(vulkan_driver); arr.erase(arr.begin());
if (string == "arch") }
ordered_functions.push_back(arch); HUDElements.max = 100; HUDElements.min = 0;
if (string == "wine") ImGui::PushFont(HUDElements.sw_stats->font1);
ordered_functions.push_back(wine); ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "GPU Load");
if (string == "frame_timing") ImGui::PopFont();
ordered_functions.push_back(frame_timing); }
if (string == "media_player")
ordered_functions.push_back(media_player); if (value == "gpu_core_clock"){
for (auto& it : graph_data){
arr.push_back(float(it.gpu_core_clock));
arr.erase(arr.begin());
}
if (int(arr.back()) > HUDElements.gpu_core_max)
HUDElements.gpu_core_max = arr.back();
HUDElements.max = HUDElements.gpu_core_max;
HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "GPU Core Clock");
ImGui::PopFont();
}
if (value == "gpu_mem_clock"){
for (auto& it : graph_data){
arr.push_back(float(it.gpu_mem_clock));
arr.erase(arr.begin());
}
if (int(arr.back()) > HUDElements.gpu_mem_max)
HUDElements.gpu_mem_max = arr.back();
HUDElements.max = HUDElements.gpu_mem_max;
HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "GPU Mem Clock");
ImGui::PopFont();
}
if (value == "vram"){
for (auto& it : graph_data){
arr.push_back(float(it.gpu_vram_used));
arr.erase(arr.begin());
}
HUDElements.max = gpu_info.memoryTotal;
HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "VRAM");
ImGui::PopFont();
}
if (value == "ram"){
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_ram])
HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_ram] = true;
for (auto& it : graph_data){
arr.push_back(float(it.ram_used));
arr.erase(arr.begin());
}
HUDElements.max = memmax;
HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "RAM");
ImGui::PopFont();
}
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
ImGui::TableNextRow();
ImGui::PlotLines("", arr.data(),
arr.size(), 0,
NULL, HUDElements.min, HUDElements.max,
ImVec2(ImGui::GetContentRegionAvailWidth() * 2.5, 50));
ImGui::PopStyleColor(1);
}
void HudElements::sort_elements(std::pair<std::string, std::string> option){
auto param = option.first;
auto value = option.second;
if (param == "version")
ordered_functions.push_back({version, value});
if (param == "time")
ordered_functions.push_back({time, value});
if (param == "gpu_stats")
ordered_functions.push_back({gpu_stats, value});
if (param == "cpu_stats")
ordered_functions.push_back({cpu_stats, value});
if (param == "core_load")
ordered_functions.push_back({core_load, value});
if (param == "io_stats")
ordered_functions.push_back({io_stats, value});
if (param == "vram")
ordered_functions.push_back({vram, value});
if (param == "ram")
ordered_functions.push_back({ram, value});
if (param == "fps")
ordered_functions.push_back({fps, value});
if (param == "engine_version")
ordered_functions.push_back({engine_version, value});
if (param == "gpu_name")
ordered_functions.push_back({gpu_name, value});
if (param == "vulkan_driver")
ordered_functions.push_back({vulkan_driver, value});
if (param == "arch")
ordered_functions.push_back({arch, value});
if (param == "wine")
ordered_functions.push_back({wine, value});
if (param == "frame_timing")
ordered_functions.push_back({frame_timing, value});
if (param == "media_player")
ordered_functions.push_back({media_player, value});
if (param == "graphs"){
std::vector<std::string> permitted_params = {
"gpu_load", "cpu_load", "gpu_core_clock", "gpu_mem_clock",
"vram", "ram"
};
std::stringstream ss; ss << value;
while (std::getline(ss, value, '+')) {
if (std::find(permitted_params.begin(), permitted_params.end(), value) != permitted_params.end())
ordered_functions.push_back({graphs, value});
else
printf("MANGOHUD: Unrecognized graph type: %s\n", value.c_str());
}
}
} }
HudElements HUDElements; HudElements HUDElements;

@ -2,6 +2,8 @@
#include "overlay.h" #include "overlay.h"
#include "overlay_params.h" #include "overlay_params.h"
#include <functional> #include <functional>
#include <map>
#include <sstream>
class HudElements{ class HudElements{
public: public:
@ -10,9 +12,11 @@ class HudElements{
float ralign_width; float ralign_width;
float old_scale; float old_scale;
bool is_vulkan; bool is_vulkan;
std::vector<std::string> options; int place;
std::vector<void(*)()> ordered_functions; std::vector<std::pair<std::string, std::string>> options;
void sort_elements(std::string string); std::vector<std::pair<void(*)(), std::string >> ordered_functions;
int min, max, gpu_core_max, gpu_mem_max;
void sort_elements(std::pair<std::string, std::string> option);
static void version(); static void version();
static void time(); static void time();
static void gpu_stats(); static void gpu_stats();
@ -29,6 +33,7 @@ class HudElements{
static void wine(); static void wine();
static void frame_timing(); static void frame_timing();
static void media_player(); static void media_player();
static void graphs();
}; };
extern HudElements HUDElements; extern HudElements HUDElements;

@ -14,6 +14,7 @@
struct benchmark_stats benchmark; struct benchmark_stats benchmark;
struct fps_limit fps_limit_stats {}; struct fps_limit fps_limit_stats {};
ImVec2 real_font_size; ImVec2 real_font_size;
std::vector<logData> graph_data;
void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID) void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID)
{ {
@ -55,7 +56,11 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par
currentLogData.cpu_load = cpuStats.GetCPUDataTotal().percent; currentLogData.cpu_load = cpuStats.GetCPUDataTotal().percent;
currentLogData.cpu_temp = cpuStats.GetCPUDataTotal().temp; currentLogData.cpu_temp = cpuStats.GetCPUDataTotal().temp;
// Save data for graphs
if (graph_data.size() > 50)
graph_data.erase(graph_data.begin());
graph_data.push_back({0, 0, cpuStats.GetCPUDataTotal().percent, gpu_info.load, cpuStats.GetCPUDataTotal().temp,
gpu_info.temp, gpu_info.CoreClock, gpu_info.MemClock, gpu_info.memoryUsed, memused});
logger->notify_data_valid(); logger->notify_data_valid();
} }
@ -63,7 +68,6 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa
if(not logger) logger = std::make_unique<Logger>(&params); if(not logger) logger = std::make_unique<Logger>(&params);
uint32_t f_idx = sw_stats.n_frames % ARRAY_SIZE(sw_stats.frames_stats); uint32_t f_idx = sw_stats.n_frames % ARRAY_SIZE(sw_stats.frames_stats);
uint64_t now = os_time_get(); /* us */ uint64_t now = os_time_get(); /* us */
double elapsed = (double)(now - sw_stats.last_fps_update); /* us */ double elapsed = (double)(now - sw_stats.last_fps_update); /* us */
fps = 1000000.0f * sw_stats.n_frames_since_update / elapsed; fps = 1000000.0f * sw_stats.n_frames_since_update / elapsed;
if (logger->is_active()) if (logger->is_active())
@ -76,7 +80,6 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa
frametime = now - sw_stats.last_present_time; frametime = now - sw_stats.last_present_time;
if (elapsed >= params.fps_sampling_period) { if (elapsed >= params.fps_sampling_period) {
std::thread(update_hw_info, std::ref(sw_stats), std::ref(params), vendorID).detach(); std::thread(update_hw_info, std::ref(sw_stats), std::ref(params), vendorID).detach();
sw_stats.fps = fps; sw_stats.fps = fps;

@ -12,6 +12,7 @@
#include "hud_elements.h" #include "hud_elements.h"
#include "version.h" #include "version.h"
#include "gpu.h" #include "gpu.h"
#include "logging.h"
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
#include "dbus_info.h" #include "dbus_info.h"
extern float g_overflow; extern float g_overflow;
@ -101,6 +102,7 @@ extern int32_t deviceID;
extern struct benchmark_stats benchmark; extern struct benchmark_stats benchmark;
extern ImVec2 real_font_size; extern ImVec2 real_font_size;
extern std::string wineVersion; extern std::string wineVersion;
extern std::vector<logData> graph_data;
void position_layer(struct swapchain_stats& data, struct overlay_params& params, ImVec2 window_size); void position_layer(struct swapchain_stats& data, struct overlay_params& params, ImVec2 window_size);
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan); void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);

@ -441,7 +441,7 @@ parse_overlay_env(struct overlay_params *params,
char key[256], value[256]; char key[256], value[256];
while ((num = parse_string(env, key, value)) != 0) { while ((num = parse_string(env, key, value)) != 0) {
env += num; env += num;
HUDElements.sort_elements(key); HUDElements.sort_elements({key, value});
if (!strcmp("full", key)) { if (!strcmp("full", key)) {
bool read_cfg = params->enabled[OVERLAY_PARAM_ENABLED_read_cfg]; bool read_cfg = params->enabled[OVERLAY_PARAM_ENABLED_read_cfg];
#define OVERLAY_PARAM_BOOL(name) \ #define OVERLAY_PARAM_BOOL(name) \

@ -53,6 +53,7 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_BOOL(wine) \ OVERLAY_PARAM_BOOL(wine) \
OVERLAY_PARAM_BOOL(gpu_load_change) \ OVERLAY_PARAM_BOOL(gpu_load_change) \
OVERLAY_PARAM_BOOL(cpu_load_change) \ OVERLAY_PARAM_BOOL(cpu_load_change) \
OVERLAY_PARAM_BOOL(graphs) \
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \ OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
OVERLAY_PARAM_CUSTOM(output_folder) \ OVERLAY_PARAM_CUSTOM(output_folder) \
OVERLAY_PARAM_CUSTOM(output_file) \ OVERLAY_PARAM_CUSTOM(output_file) \
@ -92,7 +93,7 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_CUSTOM(background_color) \ OVERLAY_PARAM_CUSTOM(background_color) \
OVERLAY_PARAM_CUSTOM(io_color) \ OVERLAY_PARAM_CUSTOM(io_color) \
OVERLAY_PARAM_CUSTOM(text_color) \ OVERLAY_PARAM_CUSTOM(text_color) \
OVERLAY_PARAM_CUSTOM (wine_color) \ OVERLAY_PARAM_CUSTOM(wine_color) \
OVERLAY_PARAM_CUSTOM(alpha) \ OVERLAY_PARAM_CUSTOM(alpha) \
OVERLAY_PARAM_CUSTOM(log_duration) \ OVERLAY_PARAM_CUSTOM(log_duration) \
OVERLAY_PARAM_CUSTOM(pci_dev) \ OVERLAY_PARAM_CUSTOM(pci_dev) \
@ -107,9 +108,8 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_CUSTOM(help) \ OVERLAY_PARAM_CUSTOM(help) \
OVERLAY_PARAM_CUSTOM(gpu_load_value) \ OVERLAY_PARAM_CUSTOM(gpu_load_value) \
OVERLAY_PARAM_CUSTOM(cpu_load_value) \ OVERLAY_PARAM_CUSTOM(cpu_load_value) \
OVERLAY_PARAM_CUSTOM(gpu_load_color) \ OVERLAY_PARAM_CUSTOM(gpu_load_color) \
OVERLAY_PARAM_CUSTOM(cpu_load_color) OVERLAY_PARAM_CUSTOM(cpu_load_color) \
enum overlay_param_position { enum overlay_param_position {
LAYER_POSITION_TOP_LEFT, LAYER_POSITION_TOP_LEFT,

@ -952,8 +952,11 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
if (!params.no_display){ if (!params.no_display){
ImGui::Begin("Main", &open, ImGuiWindowFlags_NoDecoration); ImGui::Begin("Main", &open, ImGuiWindowFlags_NoDecoration);
ImGui::BeginTable("hud", params.tableCols, ImGuiTableFlags_NoClipX); ImGui::BeginTable("hud", params.tableCols, ImGuiTableFlags_NoClipX);
for (auto& func : HUDElements.ordered_functions) HUDElements.place = 0;
func(); for (auto& func : HUDElements.ordered_functions){
func.first();
HUDElements.place += 1;
}
ImGui::EndTable(); ImGui::EndTable();
if(logger->is_active()) if(logger->is_active())

Loading…
Cancel
Save