Compare commits

..

3 Commits

3 changed files with 42 additions and 12 deletions

View File

@@ -4,9 +4,20 @@
#include <Cubed/tools/log.hpp> #include <Cubed/tools/log.hpp>
#ifdef _WIN32 #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <psapi.h>
typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
#elif defined(__linux__)
#include <sys/resource.h>
#include <unistd.h>
#include <fstream>
#endif
namespace Tools {
inline bool get_os_version(std::string& str) { inline bool get_os_version(std::string& str) {
#ifdef _WIN32
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll"); HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
if (!hntdll) return false; if (!hntdll) return false;
@@ -27,12 +38,7 @@ inline bool get_os_version(std::string& str) {
str = "Windows Build " + std::to_string(osvi.dwBuildNumber); str = "Windows Build " + std::to_string(osvi.dwBuildNumber);
} }
return true; return true;
}
#elif defined(__linux__) #elif defined(__linux__)
#include <fstream>
inline bool get_os_version(std::string& str) {
std::ifstream file("/etc/os-release"); std::ifstream file("/etc/os-release");
if (!file.is_open()) { if (!file.is_open()) {
Logger::error("Can't Open /etc/os-release"); Logger::error("Can't Open /etc/os-release");
@@ -56,12 +62,29 @@ inline bool get_os_version(std::string& str) {
} }
} }
return false; return false;
}
#else #else
inline bool get_os_version(std::string& str) {
str = "Unknown OS"; str = "Unknown OS";
return false; return false;
}
#endif #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;
#elif defined(__linux__)
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;
#else
return 0; // Unsupported platform
#endif
}
}

View File

@@ -4,6 +4,7 @@
#include <Cubed/map_table.hpp> #include <Cubed/map_table.hpp>
#include <Cubed/tools/cubed_assert.hpp> #include <Cubed/tools/cubed_assert.hpp>
#include <Cubed/tools/log.hpp> #include <Cubed/tools/log.hpp>
#include <Cubed/tools/system_info.hpp>
#include <Cubed/tools/perlin_noise.hpp> #include <Cubed/tools/perlin_noise.hpp>
#include <exception> #include <exception>
@@ -161,10 +162,11 @@ void App::update() {
if (fps_time_count >= 1.0f) { if (fps_time_count >= 1.0f) {
fps = static_cast<int>(frame_count / fps_time_count); fps = static_cast<int>(frame_count / fps_time_count);
std::string title = "Cubed FPS: " + std::to_string(fps); 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()); glfwSetWindowTitle(m_window.get_glfw_window(), title.c_str());
frame_count = 0; frame_count = 0;
fps_time_count = 0.0f; fps_time_count = 0.0f;
DebugCollector::get().report("fps", std::string{"FPS: " + std::to_string(fps)});
DebugCollector::get().report("rss", std::format("RSS: {}mb", Tools::get_current_rss() / (1024 * 1024)));
} }
m_texture_manager.update(); m_texture_manager.update();
m_world.update(delta_time); m_world.update(delta_time);

View File

@@ -1,6 +1,6 @@
#include <Cubed/debug_collector.hpp> #include <Cubed/debug_collector.hpp>
#include <Cubed/tools/system_version.hpp> #include <Cubed/tools/system_info.hpp>
#include <Cubed/tools/cubed_hash.hpp> #include <Cubed/tools/cubed_hash.hpp>
DebugCollector::DebugCollector() { DebugCollector::DebugCollector() {
@@ -17,7 +17,7 @@ void DebugCollector::init_text() {
Text fps_text("fps"); Text fps_text("fps");
Text player_pos_text("player_pos"); Text player_pos_text("player_pos");
Text rendered_chunk_text("rendered_chunk"); Text rendered_chunk_text("rendered_chunk");
Text rss_text("rss");
version_text version_text
.position(0.0f, 100.0f) .position(0.0f, 100.0f)
.scale(0.8f) .scale(0.8f)
@@ -34,13 +34,17 @@ void DebugCollector::init_text() {
.text("Rendered Chunk: 0") .text("Rendered Chunk: 0")
.scale(0.8f) .scale(0.8f)
.position(0.0, 200.0f); .position(0.0, 200.0f);
rss_text
.text("RSS: 0mb")
.scale(0.8f)
.position(0.0f, 300.0f);
std::string os; std::string os;
Text os_text("os"); Text os_text("os");
os_text os_text
.scale(0.8f) .scale(0.8f)
.position(0.0f, 250.0f); .position(0.0f, 250.0f);
if (get_os_version(os)) { if (Tools::get_os_version(os)) {
os_text os_text
.text("OS: " + os); .text("OS: " + os);
Logger::info("System: {}", os); Logger::info("System: {}", os);
@@ -54,6 +58,7 @@ void DebugCollector::init_text() {
m_texts.insert({player_pos_text.uuid(), std::move(player_pos_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({rendered_chunk_text.uuid(), std::move(rendered_chunk_text)});
m_texts.insert({os_text.uuid(), std::move(os_text)}); m_texts.insert({os_text.uuid(), std::move(os_text)});
m_texts.insert({rss_text.uuid(), std::move(rss_text)});
} }
std::unordered_map<std::size_t, Text>& DebugCollector::all_texts() { std::unordered_map<std::size_t, Text>& DebugCollector::all_texts() {