gpu_info_cpu.c 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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->count = 1;
  11. resp->total = info.ullTotalPhys;
  12. resp->free = info.ullAvailPhys;
  13. } else {
  14. resp->err = LOAD_ERR();
  15. }
  16. return;
  17. }
  18. #elif __linux__
  19. #include <errno.h>
  20. #include <string.h>
  21. #include <sys/sysinfo.h>
  22. void cpu_check_ram(mem_info_t *resp) {
  23. struct sysinfo info;
  24. resp->err = NULL;
  25. if (sysinfo(&info) != 0) {
  26. resp->err = strdup(strerror(errno));
  27. } else {
  28. resp->count = 1;
  29. resp->total = info.totalram * info.mem_unit;
  30. resp->free = info.freeram * info.mem_unit;
  31. }
  32. return;
  33. }
  34. #elif __APPLE__
  35. // TODO consider an Apple implementation that does something useful
  36. // mem_info_t cpu_check_ram() {
  37. // mem_info_t resp = {0, 0, NULL};
  38. // return resp;
  39. // }
  40. #else
  41. #error "Unsupported platform"
  42. #endif