SysInfo caching for Linux
This commit is contained in:
@@ -73,7 +73,12 @@ namespace OpenVulkano
|
||||
|
||||
size_t SystemInfo::GetSystemRam()
|
||||
{
|
||||
return ReadMemInfo("MemTotal");
|
||||
static size_t ram;
|
||||
if (ram == 0)
|
||||
{
|
||||
ram = ReadMemInfo("MemTotal");
|
||||
}
|
||||
return ram;
|
||||
}
|
||||
|
||||
size_t SystemInfo::GetSystemRamAvailable()
|
||||
@@ -98,27 +103,47 @@ namespace OpenVulkano
|
||||
|
||||
size_t SystemInfo::GetAppVirtualMemoryMax()
|
||||
{
|
||||
rlimit limit;
|
||||
if (getrlimit(RLIMIT_AS, &limit) == 0)
|
||||
static size_t vramMax;
|
||||
if (vramMax == 0)
|
||||
{
|
||||
return limit.rlim_cur;
|
||||
rlimit limit;
|
||||
if (getrlimit(RLIMIT_AS, &limit) == 0)
|
||||
{
|
||||
vramMax = limit.rlim_cur;
|
||||
}
|
||||
Logger::PERF->error("Failed to query max application memory");
|
||||
}
|
||||
Logger::PERF->error("Failed to query max application memory");
|
||||
return 0;
|
||||
return vramMax;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetUserName()
|
||||
{
|
||||
char* name = getlogin();
|
||||
if (!name) return "unknown";
|
||||
return name;
|
||||
static std::string userName;
|
||||
if (userName.emtpy())
|
||||
{
|
||||
char* name = getlogin();
|
||||
if (!name)
|
||||
{
|
||||
userName = "unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = name;
|
||||
}
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetHostName()
|
||||
{
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
gethostname(hostname, HOST_NAME_MAX + 1);
|
||||
return hostname;
|
||||
static std::string hostName;
|
||||
if (hostName.emtpy())
|
||||
{
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
gethostname(hostname, HOST_NAME_MAX + 1);
|
||||
hostName = hostname;
|
||||
}
|
||||
return hostName;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetDeviceName()
|
||||
@@ -128,30 +153,44 @@ namespace OpenVulkano
|
||||
|
||||
std::string SystemInfo::GetDeviceVendorName()
|
||||
{
|
||||
std::ifstream dmiStream("/sys/class/dmi/id/board_vendor");
|
||||
if (!dmiStream)
|
||||
static std::string vendor;
|
||||
if (vendor.emtpy())
|
||||
{
|
||||
Logger::PERF->error("Failed to read /sys/class/dmi/id/board_vendor");
|
||||
return "Unknown";
|
||||
std::ifstream dmiStream("/sys/class/dmi/id/board_vendor");
|
||||
if (!dmiStream)
|
||||
{
|
||||
Logger::PERF->error("Failed to read /sys/class/dmi/id/board_vendor");
|
||||
vendor = "Unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string motherboardName;
|
||||
std::getline(dmiStream, motherboardName);
|
||||
vendor = motherboardName;
|
||||
}
|
||||
}
|
||||
|
||||
std::string motherboardName;
|
||||
std::getline(dmiStream, motherboardName);
|
||||
return motherboardName;
|
||||
return vendor;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetDeviceModelName()
|
||||
{
|
||||
std::ifstream dmiStream("/sys/class/dmi/id/board_name");
|
||||
if (!dmiStream)
|
||||
static std::string modelName;
|
||||
if (modelName.emtpy())
|
||||
{
|
||||
Logger::PERF->error("Failed to read /sys/class/dmi/id/board_name");
|
||||
return "Unknown";
|
||||
std::ifstream dmiStream("/sys/class/dmi/id/board_name");
|
||||
if (!dmiStream)
|
||||
{
|
||||
Logger::PERF->error("Failed to read /sys/class/dmi/id/board_name");
|
||||
modelName = "Unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string motherboardName;
|
||||
std::getline(dmiStream, motherboardName);
|
||||
modelName = motherboardName;
|
||||
}
|
||||
}
|
||||
|
||||
std::string motherboardName;
|
||||
std::getline(dmiStream, motherboardName);
|
||||
return motherboardName;
|
||||
return modelName;
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -275,7 +314,12 @@ namespace OpenVulkano
|
||||
|
||||
size_t SystemInfo::GetCpuThreadCount()
|
||||
{
|
||||
return std::thread::hardware_concurrency();
|
||||
static size_t threadCount;
|
||||
if (threadCount == 0)
|
||||
{
|
||||
threadCount = std::thread::hardware_concurrency();
|
||||
}
|
||||
return threadCount;
|
||||
}
|
||||
|
||||
int32_t SystemInfo::GetCpuTemperature()
|
||||
|
||||
Reference in New Issue
Block a user