diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 0920b388..7e5db1e3 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -46,6 +46,15 @@ # include "../nfd/nfd.h" #endif +#ifdef _WIN32 +# include +#elif defined __linux__ +# include +#elif defined __APPLE__ || defined BSD +# include +# include +#endif + #include "IconsFontAwesome5.h" #ifndef M_PI_2 @@ -132,6 +141,7 @@ View::View( void(*cbMainThread)(std::function), const char* addr, uint16 assert( s_instance == nullptr ); s_instance = this; + InitMemory(); InitTextEditor( fixedWidth ); } @@ -155,6 +165,7 @@ View::View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fix m_notificationTime = 4; m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() ); + InitMemory(); InitTextEditor( fixedWidth ); SetViewToLastFrames(); m_userData.StateShouldBePreserved(); @@ -184,6 +195,32 @@ View::~View() s_instance = nullptr; } +void View::InitMemory() +{ +#ifdef _WIN32 + MEMORYSTATUSEX statex; + statex.dwLength = sizeof( statex ); + GlobalMemoryStatusEx( &statex ); + m_totalMemory = statex.ullTotalPhys; +#elif defined __linux__ + struct sysinfo sysInfo; + sysinfo( &sysInfo ); + m_totalMemory = sysInfo.totalram; +#elif defined __APPLE__ + size_t memSize; + size_t sz = sizeof( memSize ); + sysctlbyname( "hw.memsize", &memSize, &sz, nullptr, 0 ); + m_totalMemory = memSize; +#elif defined BSD + size_t memSize; + size_t sz = sizeof( memSize ); + sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 ); + m_totalMemory = memSize; +#else + m_totalMemory = 0; +#endif +} + void View::InitTextEditor( ImFont* font ) { m_sourceView = std::make_unique( font, m_gwcb ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index ae7cd429..feda3cc5 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -138,6 +138,7 @@ private: LastRange }; + void InitMemory(); void InitTextEditor( ImFont* font ); const char* ShortenNamespace( const char* name ) const; @@ -328,6 +329,7 @@ private: ViewMode m_viewMode; bool m_viewModeHeuristicTry = false; DecayValue m_forceConnectionPopup = false; + uint64_t m_totalMemory; ViewData m_vd;