1#include <Foundation/FoundationInternal.h>
2PL_FOUNDATION_INTERNAL_HEADER
4#include <Foundation/System/SystemInformation.h>
6#include <Foundation/IO/OSFile.h>
19 plUInt64 numBytesRead = status.
Read(buffer, PL_ARRAY_SIZE(buffer));
25 if (tracerPid ==
nullptr)
32 while (*tracerPid ==
' ' || *tracerPid ==
'\t')
37 return *tracerPid ==
'0' ? false :
true;
40void plSystemInformation::Initialize()
42 if (s_SystemInformation.m_bIsInitialized)
45 s_SystemInformation.m_CpuFeatures.
Detect();
48 s_SystemInformation.m_uiCPUCoreCount = sysconf(_SC_NPROCESSORS_ONLN);
50 plUInt64 uiPageCount = sysconf(_SC_PHYS_PAGES);
51 plUInt64 uiPageSize = sysconf(_SC_PAGE_SIZE);
53 s_SystemInformation.m_uiInstalledMainMemory = uiPageCount * uiPageSize;
54 s_SystemInformation.m_uiMemoryPageSize = uiPageSize;
57#if PL_ENABLED(PL_PLATFORM_64BIT)
58 s_SystemInformation.m_bB64BitOS =
true;
60 s_SystemInformation.m_bB64BitOS =
false;
61# if PL_ENABLED(PL_PLATFORM_OSX)
62# error "32 Bit builds are not supported on OSX"
66#if defined BUILDSYSTEM_BUILDTYPE
67 s_SystemInformation.m_szBuildConfiguration = BUILDSYSTEM_BUILDTYPE;
69 s_SystemInformation.m_szBuildConfiguration =
"undefined";
73#if PL_ENABLED(PL_PLATFORM_LINUX)
74 s_SystemInformation.m_szPlatformName =
"Linux";
75#elif PL_ENABLED(PL_PLATFORM_ANDROID)
76 s_SystemInformation.m_szPlatformName =
"Android";
78# error "Platform name not defined on current posix platform"
82 if (gethostname(s_SystemInformation.m_sHostName,
sizeof(s_SystemInformation.m_sHostName)) == -1)
84 strcpy(s_SystemInformation.m_sHostName,
"");
87 s_SystemInformation.m_bIsInitialized =
true;
92 return static_cast<plUInt64
>(sysconf(_SC_AVPHYS_PAGES)) *
static_cast<plUInt64
>(sysconf(_SC_PAGESIZE));
97 PL_ASSERT_NOT_IMPLEMENTED;
101#if PL_ENABLED(PL_PLATFORM_ARCH_X86)
106 void cpuid(int32_t out[4], int32_t eax, int32_t ecx)
108 __cpuid_count(eax, ecx, out[0], out[1], out[2], out[3]);
111 uint64_t xgetbv(
unsigned int index)
114 __asm__ __volatile__(
"xgetbv"
115 :
"=a"(eax),
"=d"(edx)
117 return ((uint64_t)edx << 32) | eax;
This is an abstraction for the most important file operations.
Definition OSFile.h:170
void Close()
Closes the file, if it is currently opened.
Definition OSFile.cpp:93
plUInt64 Read(void *pBuffer, plUInt64 uiBytes)
Reads up to the given number of bytes from the file. Returns the actual number of bytes that was read...
Definition OSFile.cpp:143
plResult Open(plStringView sFile, plFileOpenMode::Enum openMode, plFileShareMode::Enum fileShareMode=plFileShareMode::Default)
Opens a file for reading or writing. Returns PL_SUCCESS if the file could be opened successfully.
Definition OSFile.cpp:33
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
const char * FindSubString(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringView.cpp:60
void Detect()
CPU feature detection code copied from https://github.com/Mysticial/FeatureDetector.
Definition SystemInformation.cpp:168
@ Read
Open file for reading.
Definition OSFile.h:26