From 5f237ae8827109af2a5df375085d83b4528efefd Mon Sep 17 00:00:00 2001 From: flightlessmango Date: Wed, 29 Nov 2023 03:29:24 +0100 Subject: [PATCH] power graph --- src/amdgpu.cpp | 7 ++++++- src/amdgpu.h | 35 +++++++++++++++++++++++++++++------ src/hud_elements.cpp | 12 +++++++++++- src/overlay_params.cpp | 2 ++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/amdgpu.cpp b/src/amdgpu.cpp index 0f28feac..af60cfbc 100644 --- a/src/amdgpu.cpp +++ b/src/amdgpu.cpp @@ -173,6 +173,8 @@ void amdgpu_get_instant_metrics(struct amdgpu_common_metrics *metrics) { metrics->apu_cpu_temp_c = 0; } + metrics->average_soc_power_w = amdgpu_metrics->average_socket_power / 1000.f; + indep_throttle_status = amdgpu_metrics->indep_throttle_status; } @@ -183,8 +185,10 @@ void amdgpu_get_instant_metrics(struct amdgpu_common_metrics *metrics) { metrics->is_current_throttled = ((indep_throttle_status >> 16) & 0xFF) != 0; metrics->is_temp_throttled = ((indep_throttle_status >> 32) & 0xFFFF) != 0; metrics->is_other_throttled = ((indep_throttle_status >> 56) & 0xFF) != 0; - if (throttling) + if (throttling) { throttling->indep_throttle_status = indep_throttle_status; + throttling->avg_soc_power = metrics->average_soc_power_w; + } } void amdgpu_get_samples_and_copy(struct amdgpu_common_metrics metrics_buffer[METRICS_SAMPLE_COUNT], bool &gpu_load_needs_dividing) { @@ -206,6 +210,7 @@ void amdgpu_get_samples_and_copy(struct amdgpu_common_metrics metrics_buffer[MET UPDATE_METRIC_AVERAGE(gpu_load_percent); UPDATE_METRIC_AVERAGE_FLOAT(average_gfx_power_w); UPDATE_METRIC_AVERAGE_FLOAT(average_cpu_power_w); + UPDATE_METRIC_AVERAGE_FLOAT(average_soc_power_w); UPDATE_METRIC_AVERAGE(current_gfxclk_mhz); UPDATE_METRIC_AVERAGE(current_uclk_mhz); diff --git a/src/amdgpu.h b/src/amdgpu.h index 54e56036..6e250ec3 100644 --- a/src/amdgpu.h +++ b/src/amdgpu.h @@ -11,6 +11,7 @@ #include #include #include +#include #define METRICS_UPDATE_PERIOD_MS 500 #define METRICS_POLLING_PERIOD_MS 25 @@ -173,6 +174,7 @@ struct amdgpu_common_metrics { /* Power usage: averaged across the sampling period */ float average_gfx_power_w; float average_cpu_power_w; + float average_soc_power_w; /* Clocks: latest value of the clock */ uint16_t current_gfxclk_mhz; @@ -206,18 +208,39 @@ class Throttling { public: std::vector power; std::vector thermal; + std::vector power_w; int64_t indep_throttle_status; + bool steamdeck = false; + float avg_soc_power; + float avg_soc_power_graph; + int power_limit; Throttling() : power(200, 0.0f), - thermal(200, 0.0f) {} + thermal(200, 0.0f), + power_w(200, 0.0f) { + if (getenv("STEAM_USE_MANGOAPP")) + steamdeck = true; + } void update(){ - if (((indep_throttle_status >> 0) & 0xFF) != 0) - power.push_back(0.1); - else - power.push_back(0); - + if (steamdeck) { + if ((indep_throttle_status & (1LL << 4)) != 0) + power.push_back(0.1); + else + power.push_back(0); + + power_w.push_back(avg_soc_power); + float sum = std::accumulate(power_w.begin(), power_w.end(), 0.0f); + avg_soc_power_graph = sum / power_w.size(); + power_w.erase(power_w.begin()); + + } else { + if (((indep_throttle_status >> 0) & 0xFF) != 0) + power.push_back(0.1); + else + power.push_back(0); + } if (((indep_throttle_status >> 32) & 0xFFFF) != 0) thermal.push_back(0.1); diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 723859af..0d07ec68 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -1327,11 +1327,21 @@ void HudElements::graphs(){ HUDElements.min = 0; HUDElements.TextColored(HUDElements.colors.engine, "%s", "RAM"); } + + if (value == "power"){ + if (!throttling) + return; + + arr.resize(throttling->power_w.size()); + arr = throttling->power_w; + HUDElements.max = 15; + HUDElements.min = 0; + HUDElements.TextColored(HUDElements.colors.engine, "%s %.1fw/%iw", "Power", throttling->avg_soc_power_graph, 15); + } #endif ImGui::PopFont(); ImGui::Dummy(ImVec2(0.0f,5.0f)); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); - ImguiNextColumnOrNewRow(); if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_histogram]){ ImGui::PlotLines("", arr.data(), arr.size(), 0, diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index aadee0be..20107a3f 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -1108,6 +1108,8 @@ void presets(int preset, struct overlay_params *params, bool inherit) { add_to_options(params, "hdr", "1"); add_to_options(params, "refresh_rate", "1"); add_to_options(params, "media_player", "0"); + add_to_options(params, "gpu_name", "0"); + add_to_options(params, "graphs", "power"); break; }