From 876cb5ebe2b580c2a97cfee8ff87e3f579399ca1 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Thu, 16 Apr 2026 21:43:11 +0800 Subject: [PATCH] feat: add rss record --- include/Cubed/tools/memory_used.hpp | 26 ++++++++++++++++++++++++++ src/app.cpp | 4 +++- src/debug_collector.cpp | 7 ++++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 include/Cubed/tools/memory_used.hpp diff --git a/include/Cubed/tools/memory_used.hpp b/include/Cubed/tools/memory_used.hpp new file mode 100644 index 0000000..4931d30 --- /dev/null +++ b/include/Cubed/tools/memory_used.hpp @@ -0,0 +1,26 @@ +#pragma once +#ifdef _WIN32 +#include +#include +#else +#include +#include +#include +#endif + +inline size_t get_current_rss() { +#ifdef _WIN32 + PROCESS_MEMORY_COUNTERS_EX pmc; + if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc))) { + return pmc.WorkingSetSize; + } + return 0; +#else + std::ifstream statm("/proc/self/statm"); + long vsz = 0, rss_pages = 0; + statm >> vsz >> rss_pages; + statm.close(); + long page_size = sysconf(_SC_PAGESIZE); + return rss_pages * page_size; +#endif +} \ No newline at end of file diff --git a/src/app.cpp b/src/app.cpp index fb17fe1..bcf6682 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -161,10 +162,11 @@ void App::update() { if (fps_time_count >= 1.0f) { fps = static_cast(frame_count / fps_time_count); std::string title = "Cubed FPS: " + std::to_string(fps); - DebugCollector::get().report("fps", std::string{"FPS: " + std::to_string(fps)}); glfwSetWindowTitle(m_window.get_glfw_window(), title.c_str()); frame_count = 0; fps_time_count = 0.0f; + DebugCollector::get().report("fps", std::string{"FPS: " + std::to_string(fps)}); + DebugCollector::get().report("rss", std::format("RSS: {}mb", get_current_rss() / (1024 * 1024))); } m_texture_manager.update(); m_world.update(delta_time); diff --git a/src/debug_collector.cpp b/src/debug_collector.cpp index bae3835..40a1b8a 100644 --- a/src/debug_collector.cpp +++ b/src/debug_collector.cpp @@ -17,7 +17,7 @@ void DebugCollector::init_text() { Text fps_text("fps"); Text player_pos_text("player_pos"); Text rendered_chunk_text("rendered_chunk"); - + Text rss_text("rss"); version_text .position(0.0f, 100.0f) .scale(0.8f) @@ -34,6 +34,10 @@ void DebugCollector::init_text() { .text("Rendered Chunk: 0") .scale(0.8f) .position(0.0, 200.0f); + rss_text + .text("RSS: 0mb") + .scale(0.8f) + .position(0.0f, 300.0f); std::string os; Text os_text("os"); @@ -54,6 +58,7 @@ void DebugCollector::init_text() { m_texts.insert({player_pos_text.uuid(), std::move(player_pos_text)}); m_texts.insert({rendered_chunk_text.uuid(), std::move(rendered_chunk_text)}); m_texts.insert({os_text.uuid(), std::move(os_text)}); + m_texts.insert({rss_text.uuid(), std::move(rss_text)}); } std::unordered_map& DebugCollector::all_texts() {