Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mangohud-next/ipc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ struct SampleStats {
return fps > 0 ? 1000.f / fps : 0.f;
}

uint64_t frame_count() const {
std::lock_guard lock(m);
return n_samples ? seq_last + 1 : 0;
}

std::pair<float, float> minmax_frametime() {
std::lock_guard lock(m);
update_stats();
Expand Down
8 changes: 5 additions & 3 deletions mangohud-next/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ value: [CPU, LOAD]
value: [GPU, 0, LOAD]
```

Single-name references, such as `FPS`, use metrics from the current application. Two-item references use a metric group and key, such as `[CPU, LOAD]`. GPU metrics are indexed, so use the three-item form, such as `[GPU, 0, LOAD]`.
Single-name references, such as FPS, use metrics from the current application. Two-item references use a metric group and key, such as `[RAM, USED]`. GPU metrics are indexed, so use the three-item form, such as `[GPU, 0, LOAD]`. CPU metrics support both aggregate and per-core references. Per-core references use a three-item form like GPU metrics `[CPU, 0, FREQ]`, while aggregate metrics use the two-item references such as `[CPU, LOAD]`.

Available metrics currently include:

| Reference | Keys |
| --- | --- |
| `[GPU, index, KEY]` | `LOAD`, `VRAM_USED`, `GTT_USED`, `VRAM_TOTAL`, `VRAM_CLOCK`, `VRAM_TEMP`, `TEMP`, `JUNCTION_TEMP`, `CORE_CLOCK`, `VOLTAGE`, `POWER`, `POWER_LIMIT`, `FAN_SPEED` |
| `[CPU, KEY]` | `LOAD`, `FREQ`, `TEMP`, `POWER` |
| `[CPU, index, KEY]` | `LOAD`, `FREQ` |
| `[CPU, KEY]` | `LOAD`, `MAX_LOAD`, `FREQ`, `TEMP`, `POWER` |
| `[RAM, KEY]` | `USED`, `TOTAL`, `SWAP_USED` |
| `KEY` | `ENGINE_NAME`, `GPU_NAME`, `VULKAN_DRIVER`, `RESOLUTION`, `FPS`, `FRAMETIME`, `FRAMETIME_MIN`, `FRAMETIME_MAX`, `FRAMETIMES`, `REFRESH_FPS`, `REFRESH_FRAMETIME`, `REFRESH_FRAMETIME_MIN`, `REFRESH_FRAMETIME_MAX`, `REFRESH_FRAMETIMES`, `APP_FPS`, `APP_FRAMETIME`, `APP_FRAMETIME_MIN`, `APP_FRAMETIME_MAX`, `APP_FRAMETIMES`, `HUD_FPS`, `HUD_FRAMETIME`, `HUD_FRAMETIME_MIN`, `HUD_FRAMETIME_MAX`, `HUD_FRAMETIMES` |

Expand All @@ -111,7 +112,8 @@ milliseconds over the same roughly 500 ms sample window as `FPS` and `FRAMETIME`
All numeric frame statistics refresh together every 500 ms of sample time. They
return `0` until two samples establish an interval. The `APP_`, `HUD_`, and
`REFRESH_` variants use their respective sample windows. Graphs retain a separate
200-interval history, including initial zero padding.
200-interval history, including initial zero padding. `FRAME_COUNT` reports the
cumulative number of rendered frames received by the server.

```yaml
hud_table:
Expand Down
33 changes: 33 additions & 0 deletions mangohud-next/server/metrics/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ void Metrics::update() {
new_metrics["CPU"]["TEMP"] = {cpu_metrics.temp, "°C"};
new_metrics["CPU"]["POWER"] = {(int)cpu_metrics.power, "W"};

auto core_metrics = cpu.get_core_info();

if (!core_metrics.empty()) {
const auto max_core = std::max_element(
core_metrics.begin(), core_metrics.end(),
[](const auto& a, const auto& b) {
return a.load < b.load;
}
);

new_metrics["CPU"]["MAX_LOAD"] = {max_core->load, "%"};
}

for (size_t i = 0; i < core_metrics.size(); i++) {
const std::string core_index = "CPU" + std::to_string(i);

new_metrics[core_index]["LOAD"] = {core_metrics[i].load, "%"};
new_metrics[core_index]["FREQ"] = {core_metrics[i].frequency, "MHz"};
}

auto ram_metrics = get_ram_info();
for (auto& [k, v] : ram_metrics)
new_metrics["RAM"][to_uppercase(k)] = {v, "GiB"};
Expand Down Expand Up @@ -194,6 +214,7 @@ void Metrics::update_client() {
metrics["REFRESH_FRAMETIMES"] = {refresh_stats.frametimes_copy()};
metrics["APP_FRAMETIMES"] = {app_stats.frametimes_copy()};
metrics["HUD_FRAMETIMES"] = {hud_stats.frametimes_copy()};
metrics["FRAME_COUNT"] = {frame_stats.frame_count()};
}

{
Expand Down Expand Up @@ -423,6 +444,16 @@ void Metrics::assign_values(hudTable* t, pid_t pid, hudTable* render_table) {
format_into(out.text, "%i", i_value);
}

if (metric.val && std::holds_alternative<uint64_t>(*metric.val)) {
const uint64_t i_value = std::get<uint64_t>(*metric.val);

if (vc.unit_override)
out.unit = vc.unit;
else
out.unit = metric.unit;

out.text = std::to_string(i_value);
}
truncate_text(out.text, out.style.truncate);
parsed_row.push_back(std::move(out));
continue;
Expand Down Expand Up @@ -457,6 +488,8 @@ void Metrics::assign_values(hudTable* t, pid_t pid, hudTable* render_table) {
if (std::holds_alternative<int>(*metric.val))
return static_cast<float>(std::get<int>(*metric.val));

if (std::holds_alternative<uint64_t>(*metric.val))
return static_cast<float>(std::get<uint64_t>(*metric.val));
return fallback;
};

Expand Down
2 changes: 1 addition & 1 deletion mangohud-next/server/metrics/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "../../ipc/ipc.h"
#include "../../render/colors.h"

using MetricValue = std::variant<int, float, std::vector<float>, std::string>;
using MetricValue = std::variant<int, uint64_t, float, std::vector<float>, std::string>;
struct Metric {
std::optional<MetricValue> val;
std::string unit;
Expand Down
Loading