gpu_info_cpu.c 923 B

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