flightlessmango / MangoHud

A Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more. Discord: https://discordapp.com/invite/Gj5YmBb
MIT License
6.35k stars 281 forks source link

How to display highest/maximum GPU/CPU load values? #783

Open asdf-Counter-Strike2-ZE opened 2 years ago

asdf-Counter-Strike2-ZE commented 2 years ago

Hi, how to add to the GPU load or CPU load another value which displays the highest load that was reached?

asdf-Counter-Strike2-ZE commented 2 years ago

I added it myself. This is for the GPU maximum load and it would be similar for anything else like minimum and maximum CPU load: Edit hud_elements.cpp and add

define CHAR_FAHRENHEIT "\xe2\x84\x89"

auto maximum_gpu_load = 0;

// Cut from https://github.com/ocornut/imgui/pull/2943

[...]

if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock] || HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_power]){ ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("Maximum"); ImGui::SameLine(0, 1.0f); if(gpu_info.load > maximum_gpu_load) maximum_gpu_load = gpu_info.load; right_aligned_text(text_color, HUDElements.ralign_width, "%i", maximum_gpu_load); ImGui::SameLine(0, 1.0f); ImGui::Text("%%"); ImGui::TableNextRow(); ImGui::TableNextColumn(); }

(too bad quotes ignore spaces and ``` dont allow for making text bold..there's always go to be something haha..probably a reason for it tho)

I use Arch Linux so to rebuild without the .cpp file being overwritten: On first ever use, use normal makepkg -si, then make your edit to the .cpp file, then edit PKGBUILD and comment out:

#source=("git+https://github.com/flightlessmango/MangoHud.git#tag=v$_pkgver"
#        'git+https://github.com/flightlessmango/minhook.git'
#        "https://github.com/ocornut/imgui/archive/v${_imgui_ver}/imgui-${_imgui_ver}.tar.gz"
#        "https://wrapdb.mesonbuild.com/v2/imgui_${_imgui_ver}-1/get_patch#/imgui-${_imgui_ver}-1-wrap.zip")
#sha256sums=('SKIP'
#            'SKIP'
#            'f7c619e03a06c0f25e8f47262dbc32d61fd033d2c91796812bf0f8c94fca78fb'
#            '6d00b442690b6a5c5d8f898311daafbce16d370cf64f53294c3b8c5c661e435f')

then build using makepkg -f -si. You will get error in package_mangohud() so just remove the 2 folders doc and man in /home/USERNAME/PKGBUILD/mangohud/src/common manually before using makepkg -f -si.

The code I added can of course be be fully incorporated into its own function, a configuration can be added and so on. Hope this gets added soon as having this is kinda useful and is easy to add.

ma

Edit I added also an average feature. MangoHud's fps_sampling_period applies it to the one and only FPS value. Now I have two with different sample sizes (I probably could have used some of MH's sampling code for that or C++'s structures). See diff/patch for v0.6.7 with these two changes below. It's not a PR since the patch doesn't follow any quality guidelines.

--- a/hud_elements.cpp  2022-05-12 14:28:41.000000000 +0200
+++ b/hud_elements.cpp  2022-06-09 16:59:46.922736000 +0200
@@ -21,6 +21,12 @@
 #define CHAR_CELSIUS    "\xe2\x84\x83"
 #define CHAR_FAHRENHEIT "\xe2\x84\x89"

+#define BUFFER_SAMPLES_SIZE 2000
+auto maximum_gpu_load = 0;
+unsigned long buffer_full = 0, head=0;
+int average_gpu_fps[BUFFER_SAMPLES_SIZE];
+float sum = 0, average;
+
 // Cut from https://github.com/ocornut/imgui/pull/2943
 // Probably move to ImGui
 float SRGBToLinear(float in)
@@ -173,6 +179,16 @@
             ImGui::Text("°C");
         }
         if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock] || HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_power]){
+            // Maximum load
+            ImGui::TableNextRow(); ImGui::TableNextColumn();
+            ImGui::Text("max.   ");
+            ImGui::SameLine(0, 1.0f);
+            if(gpu_info.load > maximum_gpu_load)
+                maximum_gpu_load = gpu_info.load;
+            right_aligned_text(text_color, HUDElements.ralign_width, "%i", maximum_gpu_load);
+            ImGui::SameLine(0, 1.0f);
+            ImGui::Text("%%");
+          
             ImGui::TableNextRow(); ImGui::TableNextColumn();
         }
         if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock]){
@@ -195,6 +211,7 @@
             ImGui::Text("W");
             ImGui::PopFont();
         }
+        
     }
 }

@@ -454,6 +471,37 @@
         ImGui::PushFont(HUDElements.sw_stats->font1);
         ImGui::Text("FPS");
         ImGui::PopFont();
+        
+        // Average FPS
+        ImGui::TableNextRow(); 
+        ImGui::TableNextColumn();
+        ImGui::Text("avg.");
+        ImGui::SameLine(0, 1.0f);
+        ImGui::TableNextColumn();
+        average_gpu_fps[head] = HUDElements.sw_stats->fps;
+        head = (head + 1) % BUFFER_SAMPLES_SIZE;
+        if(buffer_full < BUFFER_SAMPLES_SIZE)
+            buffer_full++;
+        
+        for(int i = 0; i < BUFFER_SAMPLES_SIZE; i++) {
+            sum += average_gpu_fps[i];
+        }
+        
+        // don't wait until the buffer gets full and use what we already have
+        if(buffer_full < BUFFER_SAMPLES_SIZE)
+            average = sum / buffer_full;
+        else
+            average = sum / BUFFER_SAMPLES_SIZE;
+        
+        right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", average);
+        sum = 0;
+        ImGui::SameLine(0, 1.0f);
+        ImGui::PushFont(HUDElements.sw_stats->font1);
+        ImGui::Text("FPS");
+        ImGui::PopFont();
+        ImGui::TableNextRow(); 
+        ImGui::TableNextColumn();
+        
         if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_frametime]){
             ImGui::TableNextColumn();
             right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", 1000 / HUDElements.sw_stats->fps);

avg