| 279 | } |
| 280 | |
| 281 | QString SystemPerformanceCounters::getRAM() |
| 282 | { |
| 283 | try |
| 284 | { |
| 285 | QJsonObject jResult; |
| 286 | |
| 287 | if (!isInitialized) |
| 288 | { |
| 289 | init(); |
| 290 | return ""; |
| 291 | } |
| 292 | |
| 293 | #ifdef _WIN32 |
| 294 | |
| 295 | MEMORYSTATUSEX memInfo{}; |
| 296 | memInfo.dwLength = sizeof(MEMORYSTATUSEX); |
| 297 | if (GlobalMemoryStatusEx(&memInfo) == 0) |
| 298 | return ""; |
| 299 | qint64 totalPhysMem = qint64(memInfo.ullTotalPhys) / (1024ll * 1024); |
| 300 | qint64 physMemAv = qint64(memInfo.ullAvailPhys) / (1024ll * 1024); |
| 301 | qint64 takenMem = totalPhysMem - physMemAv; |
| 302 | qint64 aspect = (takenMem * 100) / totalPhysMem; |
| 303 | |
| 304 | #else |
| 305 | |
| 306 | struct sysinfo memInfo; |
| 307 | sysinfo(&memInfo); |
| 308 | |
| 309 | long long totalPhysMem = memInfo.totalram; |
| 310 | totalPhysMem *= memInfo.mem_unit; |
| 311 | |
| 312 | long long physMemAv = memInfo.freeram + memInfo.bufferram; |
| 313 | physMemAv *= memInfo.mem_unit; |
| 314 | |
| 315 | unsigned long available = 0, total = 0, free = 0; |
| 316 | FILE* pFile = fopen("/proc/meminfo", "r"); |
| 317 | if (pFile != NULL) |
| 318 | { |
| 319 | if (fscanf(pFile, "MemTotal: %lu kB\n", &total) == 1 && |
| 320 | fscanf(pFile, "MemFree: %lu kB\n", &free) == 1 && |
| 321 | fscanf(pFile, "MemAvailable: %lu kB\n", &available) == 1) |
| 322 | { |
| 323 | physMemAv = available * 1024; |
| 324 | totalPhysMem = total * 1024; |
| 325 | } |
| 326 | fclose(pFile); |
| 327 | } |
| 328 | |
| 329 | totalPhysMem /= (1024 * 1024); |
| 330 | physMemAv /= (1024 * 1024); |
| 331 | |
| 332 | long long takenMem = totalPhysMem - physMemAv; |
| 333 | qint64 aspect = (takenMem * 100) / totalPhysMem; |
| 334 | #endif |
| 335 | jResult["totalPhysMem"] = (qint64) totalPhysMem; |
| 336 | jResult["takenMem"] = (qint64)takenMem; |
| 337 | jResult["aspect"] = (qint64) aspect; |
| 338 |
no test coverage detected