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(value);
if (!param.empty()){
HUDElements.options.push_back(param);
HUDElements.options.push_back({param, value});
options[param] = value;
}
}

@ -3,23 +3,6 @@
#include "cpu.h"
#include "memory.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(){
ImGui::TableNextRow();
@ -102,31 +85,31 @@ void HudElements::cpu_stats(){
ImGui::TableNextCell();
auto text_color = HUDElements.sw_stats->colors.text;
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change]){
int cpu_load_percent = int(cpuStats.GetCPUDataTotal().percent);
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_low,
HUDElements.params->cpu_load_value[0],
HUDElements.params->cpu_load_value[1]
};
int cpu_load_percent = int(cpuStats.GetCPUDataTotal().percent);
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_low,
HUDElements.params->cpu_load_value[0],
HUDElements.params->cpu_load_value[1]
};
auto load_color = change_on_load_temp(cpu_data, cpu_load_percent);
right_aligned_text(load_color, HUDElements.ralign_width, "%d", cpu_load_percent);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color, "%%");
auto load_color = change_on_load_temp(cpu_data, cpu_load_percent);
right_aligned_text(load_color, HUDElements.ralign_width, "%d", cpu_load_percent);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color, "%%");
}
else {
right_aligned_text(text_color, HUDElements.ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
right_aligned_text(text_color, HUDElements.ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
}
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp]){
ImGui::TableNextCell();
right_aligned_text(HUDElements.sw_stats->colors.text, HUDElements.ralign_width, "%i", cpuStats.GetCPUDataTotal().temp);
ImGui::SameLine(0, 1.0f);
ImGui::Text("°C");
ImGui::TableNextCell();
right_aligned_text(HUDElements.sw_stats->colors.text, HUDElements.ralign_width, "%i", cpuStats.GetCPUDataTotal().temp);
ImGui::SameLine(0, 1.0f);
ImGui::Text("°C");
}
}
}
@ -360,39 +343,149 @@ void HudElements::media_player(){
#endif
}
void HudElements::sort_elements(std::string string){
if (string == "version")
ordered_functions.push_back(version);
if (string == "time")
ordered_functions.push_back(time);
if (string == "gpu_stats")
ordered_functions.push_back(gpu_stats);
if (string == "cpu_stats")
ordered_functions.push_back(cpu_stats);
if (string == "core_load")
ordered_functions.push_back(core_load);
if (string == "io_stats")
ordered_functions.push_back(io_stats);
if (string == "vram")
ordered_functions.push_back(vram);
if (string == "ram")
ordered_functions.push_back(ram);
if (string == "fps")
ordered_functions.push_back(fps);
if (string == "engine_version")
ordered_functions.push_back(engine_version);
if (string == "gpu_name")
ordered_functions.push_back(gpu_name);
if (string == "vulkan_driver")
ordered_functions.push_back(vulkan_driver);
if (string == "arch")
ordered_functions.push_back(arch);
if (string == "wine")
ordered_functions.push_back(wine);
if (string == "frame_timing")
ordered_functions.push_back(frame_timing);
if (string == "media_player")
ordered_functions.push_back(media_player);
void HudElements::graphs(){
ImGui::Dummy(ImVec2(0.0f, real_font_size.y));
std::string value = HUDElements.ordered_functions[HUDElements.place].second;
std::vector<float> arr;
for (size_t i = 0; i < 50; i++)
{
arr.push_back(0);
}
if (value == "cpu_load"){
for (auto& it : graph_data){
arr.push_back(float(it.cpu_load));
arr.erase(arr.begin());
}
HUDElements.max = 100; HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "CPU Load");
ImGui::PopFont();
}
if (value == "gpu_load"){
for (auto& it : graph_data){
arr.push_back(float(it.gpu_load));
arr.erase(arr.begin());
}
HUDElements.max = 100; HUDElements.min = 0;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TextColored(HUDElements.sw_stats->colors.engine, "%s", "GPU Load");
ImGui::PopFont();
}
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;

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

@ -14,6 +14,7 @@
struct benchmark_stats benchmark;
struct fps_limit fps_limit_stats {};
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)
{
@ -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_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();
}
@ -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);
uint32_t f_idx = sw_stats.n_frames % ARRAY_SIZE(sw_stats.frames_stats);
uint64_t now = os_time_get(); /* us */
double elapsed = (double)(now - sw_stats.last_fps_update); /* us */
fps = 1000000.0f * sw_stats.n_frames_since_update / elapsed;
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;
if (elapsed >= params.fps_sampling_period) {
std::thread(update_hw_info, std::ref(sw_stats), std::ref(params), vendorID).detach();
sw_stats.fps = fps;

@ -12,6 +12,7 @@
#include "hud_elements.h"
#include "version.h"
#include "gpu.h"
#include "logging.h"
#ifdef HAVE_DBUS
#include "dbus_info.h"
extern float g_overflow;
@ -101,6 +102,7 @@ extern int32_t deviceID;
extern struct benchmark_stats benchmark;
extern ImVec2 real_font_size;
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 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];
while ((num = parse_string(env, key, value)) != 0) {
env += num;
HUDElements.sort_elements(key);
HUDElements.sort_elements({key, value});
if (!strcmp("full", key)) {
bool read_cfg = params->enabled[OVERLAY_PARAM_ENABLED_read_cfg];
#define OVERLAY_PARAM_BOOL(name) \

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

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

Loading…
Cancel
Save