gpu_info_cpu.c 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "gpu_info.h"
  2. // Fallbacks for CPU mode
  3. #ifdef _WIN32
  4. #include <sysinfoapi.h>
  5. void cpu_check_ram(mem_info_t *resp) {
  6. resp->err = NULL;
  7. MEMORYSTATUSEX info;
  8. info.dwLength = sizeof(info);
  9. if (GlobalMemoryStatusEx(&info) != 0) {
  10. resp->total = info.ullTotalPhys;
  11. resp->free = info.ullAvailPhys;
  12. } else {
  13. resp->err = LOAD_ERR();
  14. }
  15. return;
  16. }
  17. #elif __linux__
  18. #include <errno.h>
  19. #include <string.h>
  20. #include <sys/sysinfo.h>
  21. void cpu_check_ram(mem_info_t *resp) {
  22. struct sysinfo info;
  23. resp->err = NULL;
  24. if (sysinfo(&info) != 0) {
  25. resp->err = strdup(strerror(errno));
  26. } else {
  27. resp->total = info.totalram * info.mem_unit;
  28. resp->free = info.freeram * info.mem_unit;
  29. }
  30. return;
  31. }
  32. #elif __APPLE__
  33. // TODO consider an Apple implementation that does something useful
  34. // mem_info_t cpu_check_ram() {
  35. // mem_info_t resp = {0, 0, NULL};
  36. // return resp;
  37. // }
  38. #else
  39. #error "Unsupported platform"
  40. #endif