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;
}
check_keybinds(sw_stats, *params, vendorID);
check_keybinds(*params, vendorID);
// Start the Dear ImGui frame
{
if (render(window)) {

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

@ -316,7 +316,7 @@ void HudElements::io_stats(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_read]){
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);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);
@ -325,7 +325,7 @@ void HudElements::io_stats(){
}
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_io_write]){
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);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);

@ -2,34 +2,33 @@
#include "string_utils.h"
#include <fstream>
void getIoStats(void *args) {
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;
struct iostats g_io_stats;
io->prev.read_bytes = io->curr.read_bytes;
io->prev.write_bytes = io->curr.write_bytes;
void getIoStats(iostats& io) {
Clock::time_point now = Clock::now(); /* ns */
std::chrono::duration<float> time_diff = now - io.last_update;
std::string line;
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.prev.read_bytes = io.curr.read_bytes;
io.prev.write_bytes = io.curr.write_bytes;
io->per_second.read = io->diff.read / time_diff.count();
io->per_second.write = io->diff.write / time_diff.count();
std::string line;
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;
};
void getIoStats(void *args);
extern iostats g_io_stats;
void getIoStats(iostats& io);
#endif //MANGOHUD_IOSTATS_H

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

@ -49,7 +49,7 @@ bool gpu_metrics_exists = false;
bool steam_focused = false;
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()) {
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 (vendorID == 0x1002 && getAmdGpuInfo_actual)
getAmdGpuInfo_actual();
if (gpu_metrics_exists)
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])
update_procmem();
if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write])
getIoStats(&sw_stats.io);
getIoStats(g_io_stats);
#endif
currentLogData.gpu_load = gpu_info.load;
@ -109,7 +109,6 @@ struct hw_info_updater
{
bool quit = false;
std::thread thread {};
struct swapchain_stats* sw_stats = nullptr;
struct overlay_params* params = nullptr;
uint32_t vendorID;
bool update_hw_info_thread = false;
@ -130,12 +129,11 @@ struct hw_info_updater
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);
if (lk_hw_updating.owns_lock())
{
sw_stats = sw_stats_;
params = params_;
vendorID = vendorID_;
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; });
if (quit) break;
if (sw_stats && params)
if (params)
{
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;
}
@ -190,7 +188,7 @@ void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, struct ove
if (elapsed >= params.fps_sampling_period) {
if (!hw_update_thread)
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;

@ -62,7 +62,6 @@ struct swapchain_stats {
size_t font_params_hash = 0;
std::string time;
double fps;
struct iostats io;
uint64_t last_present_time;
unsigned n_frames_since_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 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_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_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 FpsLimiter(struct fps_limit& 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);
#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 instance_data *instance_data = device_data->instance;
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__
if (instance_data->params.control >= 0) {
control_client_check(device_data);
@ -1521,7 +1521,7 @@ static VkResult overlay_CreateSwapchainKHR(
#endif
}
swapchain_data->sw_stats.driverName = driverProps.driverInfo;
return result;
}

Loading…
Cancel
Save