polserver/pol-core/clib/xmain.cpp
turleypol a5e6206164 Added cmake option to run clang-tidy
used everywhere nullptr
2018-10-09 16:36:35 +02:00

48 lines
1.1 KiB
C++

/** @file
*
* @par History
* - 2009/07/20 MuadDib: Removed calls and use of StackWalker for leak detection. vld is now used,
* much better.
* Removed StackWalker.cpp/.h from the vcproj files also.
*/
#include <stddef.h>
#include <stdio.h>
#if defined( WINDOWS )
#include "Header_Windows.h"
#pragma comment( lib, "psapi.lib" ) // 32bit is a bit dumb..
#else
#include <unistd.h>
#endif
namespace Pol
{
namespace Clib
{
// TODO: create a system.cpp/h and put the following function with some other features in a separate
// static class "system"
size_t getCurrentMemoryUsage()
{
#if defined( _WIN32 )
PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo( GetCurrentProcess(), &info, sizeof( info ) );
return (size_t)info.WorkingSetSize;
#else
long rss = 0L;
FILE* fp = nullptr;
if ( ( fp = fopen( "/proc/self/statm", "r" ) ) == nullptr )
return (size_t)0L; /* Can't open? */
if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
{
fclose( fp );
return (size_t)0L; /* Can't read? */
}
fclose( fp );
return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE );
#endif
}
}
}