Use single IO stats instance

xone-gamepad
jackun 2 years ago
parent e12042ca3d
commit e555a942fb
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -272,7 +272,7 @@ int main(int, char**)
new_frame = false; new_frame = false;
} }
check_keybinds(sw_stats, *params, vendorID); check_keybinds(*params, vendorID);
// Start the Dear ImGui frame // Start the Dear ImGui frame
{ {
if (render(window)) { if (render(window)) {

@ -188,7 +188,7 @@ void imgui_render(unsigned int width, unsigned int height)
if (!state.imgui_ctx) if (!state.imgui_ctx)
return; return;
check_keybinds(sw_stats, params, vendorID); check_keybinds(params, vendorID);
update_hud_info(sw_stats, params, vendorID); update_hud_info(sw_stats, params, vendorID);
ImGuiContext *saved_ctx = ImGui::GetCurrentContext(); ImGuiContext *saved_ctx = ImGui::GetCurrentContext();

@ -316,7 +316,7 @@ void HudElements::io_stats(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_read]){ if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_read]){
ImGui::TableNextColumn(); ImGui::TableNextColumn();
float val = HUDElements.sw_stats->io.per_second.read; const float val = g_io_stats.per_second.read;
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, val < 100 ? "%.1f" : "%.f", val); right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, val < 100 ? "%.1f" : "%.f", val);
ImGui::SameLine(0,1.0f); ImGui::SameLine(0,1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1); ImGui::PushFont(HUDElements.sw_stats->font1);
@ -325,7 +325,7 @@ void HudElements::io_stats(){
} }
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_write]){ if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_write]){
ImGui::TableNextColumn(); ImGui::TableNextColumn();
float val = HUDElements.sw_stats->io.per_second.write; const float val = g_io_stats.per_second.write;
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, val < 100 ? "%.1f" : "%.f", val); right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, val < 100 ? "%.1f" : "%.f", val);
ImGui::SameLine(0,1.0f); ImGui::SameLine(0,1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1); ImGui::PushFont(HUDElements.sw_stats->font1);

@ -2,34 +2,33 @@
#include "string_utils.h" #include "string_utils.h"
#include <fstream> #include <fstream>
void getIoStats(void *args) { struct iostats g_io_stats;
iostats *io = reinterpret_cast<iostats *>(args);
if (io) {
Clock::time_point now = Clock::now(); /* ns */
std::chrono::duration<float> time_diff = now - io->last_update;
io->prev.read_bytes = io->curr.read_bytes; void getIoStats(iostats& io) {
io->prev.write_bytes = io->curr.write_bytes; Clock::time_point now = Clock::now(); /* ns */
std::chrono::duration<float> time_diff = now - io.last_update;
std::string line; io.prev.read_bytes = io.curr.read_bytes;
std::ifstream f("/proc/self/io"); io.prev.write_bytes = io.curr.write_bytes;
while (std::getline(f, line)) {
if (starts_with(line, "read_bytes:")) {
try_stoull(io->curr.read_bytes, line.substr(12));
}
else if (starts_with(line, "write_bytes:")) {
try_stoull(io->curr.write_bytes, line.substr(13));
}
}
if (io->last_update.time_since_epoch().count()) {
io->diff.read = (io->curr.read_bytes - io->prev.read_bytes) / (1024.f * 1024.f);
io->diff.write = (io->curr.write_bytes - io->prev.write_bytes) / (1024.f * 1024.f);
io->per_second.read = io->diff.read / time_diff.count(); std::string line;
io->per_second.write = io->diff.write / time_diff.count(); std::ifstream f("/proc/self/io");
while (std::getline(f, line)) {
if (starts_with(line, "read_bytes:")) {
try_stoull(io.curr.read_bytes, line.substr(12));
}
else if (starts_with(line, "write_bytes:")) {
try_stoull(io.curr.write_bytes, line.substr(13));
} }
}
if (io.last_update.time_since_epoch().count()) {
io.diff.read = (io.curr.read_bytes - io.prev.read_bytes) / (1024.f * 1024.f);
io.diff.write = (io.curr.write_bytes - io.prev.write_bytes) / (1024.f * 1024.f);
io->last_update = now; io.per_second.read = io.diff.read / time_diff.count();
io.per_second.write = io.diff.write / time_diff.count();
} }
io.last_update = now;
} }

@ -25,6 +25,7 @@ struct iostats {
Clock::time_point last_update; Clock::time_point last_update;
}; };
void getIoStats(void *args); extern iostats g_io_stats;
void getIoStats(iostats& io);
#endif //MANGOHUD_IOSTATS_H #endif //MANGOHUD_IOSTATS_H

@ -3,7 +3,7 @@
#include "logging.h" #include "logging.h"
#include "keybinds.h" #include "keybinds.h"
void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID){ void check_keybinds(struct overlay_params& params, uint32_t vendorID){
using namespace std::chrono_literals; using namespace std::chrono_literals;
bool pressed = false; // FIXME just a placeholder until wayland support bool pressed = false; // FIXME just a placeholder until wayland support
auto now = Clock::now(); /* us */ auto now = Clock::now(); /* us */
@ -32,8 +32,7 @@ void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& par
logger->stop_logging(); logger->stop_logging();
} else { } else {
logger->start_logging(); logger->start_logging();
std::thread(update_hw_info, std::ref(sw_stats), std::ref(params), std::thread(update_hw_info, std::ref(params), vendorID)
vendorID)
.detach(); .detach();
benchmark.fps_data.clear(); benchmark.fps_data.clear();
} }

@ -49,7 +49,7 @@ bool gpu_metrics_exists = false;
bool steam_focused = false; bool steam_focused = false;
vector<float> frametime_data = {}; vector<float> frametime_data = {};
void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID) void update_hw_info(struct overlay_params& params, uint32_t vendorID)
{ {
if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats] || logger->is_active()) { if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats] || logger->is_active()) {
cpuStats.UpdateCPUData(); cpuStats.UpdateCPUData();
@ -66,7 +66,7 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] || logger->is_active()) { if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] || logger->is_active()) {
if (vendorID == 0x1002 && getAmdGpuInfo_actual) if (vendorID == 0x1002 && getAmdGpuInfo_actual)
getAmdGpuInfo_actual(); getAmdGpuInfo_actual();
if (gpu_metrics_exists) if (gpu_metrics_exists)
amdgpu_get_metrics(); amdgpu_get_metrics();
@ -82,7 +82,7 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par
if (params.enabled[OVERLAY_PARAM_ENABLED_procmem]) if (params.enabled[OVERLAY_PARAM_ENABLED_procmem])
update_procmem(); update_procmem();
if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write]) if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write])
getIoStats(&sw_stats.io); getIoStats(g_io_stats);
#endif #endif
currentLogData.gpu_load = gpu_info.load; currentLogData.gpu_load = gpu_info.load;
@ -109,7 +109,6 @@ struct hw_info_updater
{ {
bool quit = false; bool quit = false;
std::thread thread {}; std::thread thread {};
struct swapchain_stats* sw_stats = nullptr;
struct overlay_params* params = nullptr; struct overlay_params* params = nullptr;
uint32_t vendorID; uint32_t vendorID;
bool update_hw_info_thread = false; bool update_hw_info_thread = false;
@ -130,12 +129,11 @@ struct hw_info_updater
thread.join(); thread.join();
} }
void update(struct swapchain_stats* sw_stats_, struct overlay_params* params_, uint32_t vendorID_) void update(struct overlay_params* params_, uint32_t vendorID_)
{ {
std::unique_lock<std::mutex> lk_hw_updating(m_hw_updating, std::try_to_lock); std::unique_lock<std::mutex> lk_hw_updating(m_hw_updating, std::try_to_lock);
if (lk_hw_updating.owns_lock()) if (lk_hw_updating.owns_lock())
{ {
sw_stats = sw_stats_;
params = params_; params = params_;
vendorID = vendorID_; vendorID = vendorID_;
update_hw_info_thread = true; update_hw_info_thread = true;
@ -149,10 +147,10 @@ struct hw_info_updater
cv_hwupdate.wait(lk_cv_hwupdate, [&]{ return update_hw_info_thread || quit; }); cv_hwupdate.wait(lk_cv_hwupdate, [&]{ return update_hw_info_thread || quit; });
if (quit) break; if (quit) break;
if (sw_stats && params) if (params)
{ {
std::unique_lock<std::mutex> lk_hw_updating(m_hw_updating); std::unique_lock<std::mutex> lk_hw_updating(m_hw_updating);
update_hw_info(*sw_stats, *params, vendorID); update_hw_info(*params, vendorID);
} }
update_hw_info_thread = false; update_hw_info_thread = false;
} }
@ -190,7 +188,7 @@ void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct ove
if (elapsed >= params.fps_sampling_period) { if (elapsed >= params.fps_sampling_period) {
if (!hw_update_thread) if (!hw_update_thread)
hw_update_thread = std::make_unique<hw_info_updater>(); hw_update_thread = std::make_unique<hw_info_updater>();
hw_update_thread->update(&sw_stats, &params, vendorID); hw_update_thread->update(&params, vendorID);
sw_stats.fps = fps; sw_stats.fps = fps;

@ -62,7 +62,6 @@ struct swapchain_stats {
size_t font_params_hash = 0; size_t font_params_hash = 0;
std::string time; std::string time;
double fps; double fps;
struct iostats io;
uint64_t last_present_time; uint64_t last_present_time;
unsigned n_frames_since_update; unsigned n_frames_since_update;
uint64_t last_fps_update; uint64_t last_fps_update;
@ -153,10 +152,10 @@ void position_layer(struct swapchain_stats& data, struct overlay_params& params,
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan); void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID); void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID, uint64_t frametime_ns); void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID, uint64_t frametime_ns);
void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID); void update_hw_info(struct overlay_params& params, uint32_t vendorID);
void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_params& params); void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_params& params);
void init_cpu_stats(overlay_params& params); void init_cpu_stats(overlay_params& params);
void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID); void check_keybinds(overlay_params& params, uint32_t vendorID);
void init_system_info(void); void init_system_info(void);
void FpsLimiter(struct fps_limit& stats); void FpsLimiter(struct fps_limit& stats);
void get_device_name(int32_t vendorID, int32_t deviceID, struct swapchain_stats& sw_stats); void get_device_name(int32_t vendorID, int32_t deviceID, struct swapchain_stats& sw_stats);
@ -174,4 +173,4 @@ extern void process_control_socket(struct instance_data *instance_data);
void render_mpris_metadata(overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing); void render_mpris_metadata(overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing);
#endif #endif
#endif //MANGOHUD_OVERLAY_H #endif //MANGOHUD_OVERLAY_H

@ -425,7 +425,7 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
struct device_data *device_data = data->device; struct device_data *device_data = data->device;
struct instance_data *instance_data = device_data->instance; struct instance_data *instance_data = device_data->instance;
update_hud_info(data->sw_stats, instance_data->params, device_data->properties.vendorID); update_hud_info(data->sw_stats, instance_data->params, device_data->properties.vendorID);
check_keybinds(data->sw_stats, instance_data->params, device_data->properties.vendorID); check_keybinds(instance_data->params, device_data->properties.vendorID);
#ifdef __linux__ #ifdef __linux__
if (instance_data->params.control >= 0) { if (instance_data->params.control >= 0) {
control_client_check(device_data); control_client_check(device_data);
@ -1521,7 +1521,7 @@ static VkResult overlay_CreateSwapchainKHR(
#endif #endif
} }
swapchain_data->sw_stats.driverName = driverProps.driverInfo; swapchain_data->sw_stats.driverName = driverProps.driverInfo;
return result; return result;
} }

Loading…
Cancel
Save