Page MenuHome
Paste P1501

Linux memory load
ActivePublic

Authored by Hans Goudey (HooglyBoogly) on Jul 1 2020, 4:33 PM.
#ifdef WIN32
if (info[0]) {
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
}
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
ofs += BLI_snprintf(info + ofs, len, TIP_("RAM: %i%%"), statex.dwMemoryLoad);
#else
struct sysinfo memInfo;
if (sysinfo(&memInfo) == 0) {
if (info[0]) {
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
}
long long total_virtual_ram = memInfo.totalram;
total_virtual_ram += memInfo.totalswap;
total_virtual_ram *= memInfo.mem_unit;
long long virtual_ram_used = memInfo.totalram - memInfo.freeram;
virtual_ram_used += memInfo.totalswap - memInfo.freeswap;
virtual_ram_used *= memInfo.mem_unit;
int ram_load = ((float)virtual_ram_used / (float)total_virtual_ram) * 100.0f;
ofs += BLI_snprintf(info + ofs, len, TIP_("RAM: %d%%"), ram_load);
}
#endif