Skip to content

Commit 5f237ae

Browse files
power graph
1 parent f168483 commit 5f237ae

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

src/amdgpu.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ void amdgpu_get_instant_metrics(struct amdgpu_common_metrics *metrics) {
173173
metrics->apu_cpu_temp_c = 0;
174174
}
175175

176+
metrics->average_soc_power_w = amdgpu_metrics->average_socket_power / 1000.f;
177+
176178
indep_throttle_status = amdgpu_metrics->indep_throttle_status;
177179
}
178180

@@ -183,8 +185,10 @@ void amdgpu_get_instant_metrics(struct amdgpu_common_metrics *metrics) {
183185
metrics->is_current_throttled = ((indep_throttle_status >> 16) & 0xFF) != 0;
184186
metrics->is_temp_throttled = ((indep_throttle_status >> 32) & 0xFFFF) != 0;
185187
metrics->is_other_throttled = ((indep_throttle_status >> 56) & 0xFF) != 0;
186-
if (throttling)
188+
if (throttling) {
187189
throttling->indep_throttle_status = indep_throttle_status;
190+
throttling->avg_soc_power = metrics->average_soc_power_w;
191+
}
188192
}
189193

190194
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
206210
UPDATE_METRIC_AVERAGE(gpu_load_percent);
207211
UPDATE_METRIC_AVERAGE_FLOAT(average_gfx_power_w);
208212
UPDATE_METRIC_AVERAGE_FLOAT(average_cpu_power_w);
213+
UPDATE_METRIC_AVERAGE_FLOAT(average_soc_power_w);
209214

210215
UPDATE_METRIC_AVERAGE(current_gfxclk_mhz);
211216
UPDATE_METRIC_AVERAGE(current_uclk_mhz);

src/amdgpu.h

+29-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vector>
1212
#include <sys/param.h>
1313
#include <algorithm>
14+
#include <numeric>
1415

1516
#define METRICS_UPDATE_PERIOD_MS 500
1617
#define METRICS_POLLING_PERIOD_MS 25
@@ -173,6 +174,7 @@ struct amdgpu_common_metrics {
173174
/* Power usage: averaged across the sampling period */
174175
float average_gfx_power_w;
175176
float average_cpu_power_w;
177+
float average_soc_power_w;
176178

177179
/* Clocks: latest value of the clock */
178180
uint16_t current_gfxclk_mhz;
@@ -206,18 +208,39 @@ class Throttling {
206208
public:
207209
std::vector<float> power;
208210
std::vector<float> thermal;
211+
std::vector<float> power_w;
209212
int64_t indep_throttle_status;
213+
bool steamdeck = false;
214+
float avg_soc_power;
215+
float avg_soc_power_graph;
216+
int power_limit;
210217

211218
Throttling()
212219
: power(200, 0.0f),
213-
thermal(200, 0.0f) {}
220+
thermal(200, 0.0f),
221+
power_w(200, 0.0f) {
222+
if (getenv("STEAM_USE_MANGOAPP"))
223+
steamdeck = true;
224+
}
214225

215226
void update(){
216-
if (((indep_throttle_status >> 0) & 0xFF) != 0)
217-
power.push_back(0.1);
218-
else
219-
power.push_back(0);
220-
227+
if (steamdeck) {
228+
if ((indep_throttle_status & (1LL << 4)) != 0)
229+
power.push_back(0.1);
230+
else
231+
power.push_back(0);
232+
233+
power_w.push_back(avg_soc_power);
234+
float sum = std::accumulate(power_w.begin(), power_w.end(), 0.0f);
235+
avg_soc_power_graph = sum / power_w.size();
236+
power_w.erase(power_w.begin());
237+
238+
} else {
239+
if (((indep_throttle_status >> 0) & 0xFF) != 0)
240+
power.push_back(0.1);
241+
else
242+
power.push_back(0);
243+
}
221244

222245
if (((indep_throttle_status >> 32) & 0xFFFF) != 0)
223246
thermal.push_back(0.1);

src/hud_elements.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1327,11 +1327,21 @@ void HudElements::graphs(){
13271327
HUDElements.min = 0;
13281328
HUDElements.TextColored(HUDElements.colors.engine, "%s", "RAM");
13291329
}
1330+
1331+
if (value == "power"){
1332+
if (!throttling)
1333+
return;
1334+
1335+
arr.resize(throttling->power_w.size());
1336+
arr = throttling->power_w;
1337+
HUDElements.max = 15;
1338+
HUDElements.min = 0;
1339+
HUDElements.TextColored(HUDElements.colors.engine, "%s %.1fw/%iw", "Power", throttling->avg_soc_power_graph, 15);
1340+
}
13301341
#endif
13311342
ImGui::PopFont();
13321343
ImGui::Dummy(ImVec2(0.0f,5.0f));
13331344
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
1334-
ImguiNextColumnOrNewRow();
13351345
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_histogram]){
13361346
ImGui::PlotLines("", arr.data(),
13371347
arr.size(), 0,

src/overlay_params.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,8 @@ void presets(int preset, struct overlay_params *params, bool inherit) {
11081108
add_to_options(params, "hdr", "1");
11091109
add_to_options(params, "refresh_rate", "1");
11101110
add_to_options(params, "media_player", "0");
1111+
add_to_options(params, "gpu_name", "0");
1112+
add_to_options(params, "graphs", "power");
11111113
break;
11121114

11131115
}

0 commit comments

Comments
 (0)