Move physical memory size getter to a separate source file.

This commit is contained in:
Bartosz Taudul 2024-05-04 16:45:21 +02:00
parent fee5982abd
commit 66a32de0f7
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
5 changed files with 60 additions and 39 deletions

View File

@ -17,6 +17,7 @@ set(TRACY_SERVER_SOURCES
TracyMemory.cpp TracyMemory.cpp
TracyMmap.cpp TracyMmap.cpp
TracyPrint.cpp TracyPrint.cpp
TracySysUtil.cpp
TracyTaskDispatch.cpp TracyTaskDispatch.cpp
TracyTextureCompression.cpp TracyTextureCompression.cpp
TracyThreadCompress.cpp TracyThreadCompress.cpp

View File

@ -20,19 +20,10 @@
#include "TracySourceView.hpp" #include "TracySourceView.hpp"
#include "TracyTexture.hpp" #include "TracyTexture.hpp"
#include "TracyView.hpp" #include "TracyView.hpp"
#include "../server/TracySysUtil.hpp"
#include "../public/common/TracyStackFrames.hpp" #include "../public/common/TracyStackFrames.hpp"
#include "imgui_internal.h" #include "imgui_internal.h"
#ifdef _WIN32
# include <windows.h>
#elif defined __linux__
# include <sys/sysinfo.h>
#elif defined __APPLE__ || defined BSD
# include <sys/types.h>
# include <sys/sysctl.h>
#endif
#include "IconsFontAwesome6.h" #include "IconsFontAwesome6.h"
#ifndef M_PI_2 #ifndef M_PI_2
@ -49,6 +40,7 @@ View::View( void(*cbMainThread)(const std::function<void()>&, bool), const char*
, m_staticView( false ) , m_staticView( false )
, m_viewMode( ViewMode::LastFrames ) , m_viewMode( ViewMode::LastFrames )
, m_viewModeHeuristicTry( true ) , m_viewModeHeuristicTry( true )
, m_totalMemory( GetPhysicalMemorySize() )
, m_forceConnectionPopup( true, true ) , m_forceConnectionPopup( true, true )
, m_tc( *this, m_worker, config.threadedRendering ) , m_tc( *this, m_worker, config.threadedRendering )
, m_frames( nullptr ) , m_frames( nullptr )
@ -64,7 +56,6 @@ View::View( void(*cbMainThread)(const std::function<void()>&, bool), const char*
, m_userData() , m_userData()
, m_cbMainThread( cbMainThread ) , m_cbMainThread( cbMainThread )
{ {
InitMemory();
InitTextEditor(); InitTextEditor();
m_vd.frameTarget = config.targetFps; m_vd.frameTarget = config.targetFps;
@ -75,6 +66,7 @@ View::View( void(*cbMainThread)(const std::function<void()>&, bool), FileRead& f
, m_filename( f.GetFilename() ) , m_filename( f.GetFilename() )
, m_staticView( true ) , m_staticView( true )
, m_viewMode( ViewMode::Paused ) , m_viewMode( ViewMode::Paused )
, m_totalMemory( GetPhysicalMemorySize() )
, m_tc( *this, m_worker, config.threadedRendering ) , m_tc( *this, m_worker, config.threadedRendering )
, m_frames( m_worker.GetFramesBase() ) , m_frames( m_worker.GetFramesBase() )
, m_messagesScrollBottom( false ) , m_messagesScrollBottom( false )
@ -90,7 +82,6 @@ View::View( void(*cbMainThread)(const std::function<void()>&, bool), FileRead& f
m_notificationTime = 4; m_notificationTime = 4;
m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() ); m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() );
InitMemory();
InitTextEditor(); InitTextEditor();
m_vd.zvStart = m_worker.GetFirstTime(); m_vd.zvStart = m_worker.GetFirstTime();
m_vd.zvEnd = m_worker.GetLastTime(); m_vd.zvEnd = m_worker.GetLastTime();
@ -120,32 +111,6 @@ View::~View()
if( m_playback.texture ) FreeTexture( m_playback.texture, m_cbMainThread ); if( m_playback.texture ) FreeTexture( m_playback.texture, m_cbMainThread );
} }
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() void View::InitTextEditor()
{ {
m_sourceView = std::make_unique<SourceView>(); m_sourceView = std::make_unique<SourceView>();

View File

@ -222,7 +222,6 @@ private:
uint32_t count; uint32_t count;
}; };
void InitMemory();
void InitTextEditor(); void InitTextEditor();
bool DrawImpl(); bool DrawImpl();

43
server/TracySysUtil.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "TracySysUtil.hpp"
#ifdef _WIN32
# include <windows.h>
#elif defined __linux__
# include <sys/sysinfo.h>
#elif defined __APPLE__ || defined BSD
# include <sys/types.h>
# include <sys/sysctl.h>
#endif
namespace tracy
{
size_t GetPhysicalMemorySize()
{
#ifdef _WIN32
MEMORYSTATUSEX statex;
statex.dwLength = sizeof( statex );
GlobalMemoryStatusEx( &statex );
return statex.ullTotalPhys;
#elif defined __linux__
struct sysinfo sysInfo;
sysinfo( &sysInfo );
return sysInfo.totalram;
#elif defined __APPLE__
size_t memSize;
size_t sz = sizeof( memSize );
sysctlbyname( "hw.memsize", &memSize, &sz, nullptr, 0 );
return memSize;
#elif defined BSD
size_t memSize;
size_t sz = sizeof( memSize );
sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 );
return memSize;
#else
return 0;
#endif
}
}

13
server/TracySysUtil.hpp Normal file
View File

@ -0,0 +1,13 @@
#ifndef __TRACYSYSUTIL_HPP__
#define __TRACYSYSUTIL_HPP__
#include <stdlib.h>
namespace tracy
{
size_t GetPhysicalMemorySize();
}
#endif