diff --git a/mangohud-next/ipc/client.h b/mangohud-next/ipc/client.h index 1aae68e7eb..22158744f9 100644 --- a/mangohud-next/ipc/client.h +++ b/mangohud-next/ipc/client.h @@ -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 minmax_frametime() { std::lock_guard lock(m); update_stats(); diff --git a/mangohud-next/server/README.md b/mangohud-next/server/README.md index f901f089dc..440b5966ee 100644 --- a/mangohud-next/server/README.md +++ b/mangohud-next/server/README.md @@ -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` | @@ -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: diff --git a/mangohud-next/server/metrics/metrics.cpp b/mangohud-next/server/metrics/metrics.cpp index 586361bfbb..b7c0728a98 100644 --- a/mangohud-next/server/metrics/metrics.cpp +++ b/mangohud-next/server/metrics/metrics.cpp @@ -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"}; @@ -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()}; } { @@ -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(*metric.val)) { + const uint64_t i_value = std::get(*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; @@ -457,6 +488,8 @@ void Metrics::assign_values(hudTable* t, pid_t pid, hudTable* render_table) { if (std::holds_alternative(*metric.val)) return static_cast(std::get(*metric.val)); + if (std::holds_alternative(*metric.val)) + return static_cast(std::get(*metric.val)); return fallback; }; diff --git a/mangohud-next/server/metrics/metrics.h b/mangohud-next/server/metrics/metrics.h index 340bc9a9b1..30cf515792 100644 --- a/mangohud-next/server/metrics/metrics.h +++ b/mangohud-next/server/metrics/metrics.h @@ -12,7 +12,7 @@ #include "../../ipc/ipc.h" #include "../../render/colors.h" -using MetricValue = std::variant, std::string>; +using MetricValue = std::variant, std::string>; struct Metric { std::optional val; std::string unit;