SystemInformation.hxx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #ifndef cmsys_SystemInformation_h
  4. #define cmsys_SystemInformation_h
  5. #include <cmsys/Configure.hxx>
  6. #include <stddef.h> /* size_t */
  7. #include <string>
  8. namespace cmsys {
  9. // forward declare the implementation class
  10. class SystemInformationImplementation;
  11. class cmsys_EXPORT SystemInformation
  12. {
  13. #if 1
  14. typedef long long LongLong;
  15. #elif 0
  16. typedef __int64 LongLong;
  17. #else
  18. #error "No Long Long"
  19. #endif
  20. friend class SystemInformationImplementation;
  21. SystemInformationImplementation* Implementation;
  22. public:
  23. // possible parameter values for DoesCPUSupportFeature()
  24. static const long int CPU_FEATURE_MMX = 1 << 0;
  25. static const long int CPU_FEATURE_MMX_PLUS = 1 << 1;
  26. static const long int CPU_FEATURE_SSE = 1 << 2;
  27. static const long int CPU_FEATURE_SSE2 = 1 << 3;
  28. static const long int CPU_FEATURE_AMD_3DNOW = 1 << 4;
  29. static const long int CPU_FEATURE_AMD_3DNOW_PLUS = 1 << 5;
  30. static const long int CPU_FEATURE_IA64 = 1 << 6;
  31. static const long int CPU_FEATURE_MP_CAPABLE = 1 << 7;
  32. static const long int CPU_FEATURE_HYPERTHREAD = 1 << 8;
  33. static const long int CPU_FEATURE_SERIALNUMBER = 1 << 9;
  34. static const long int CPU_FEATURE_APIC = 1 << 10;
  35. static const long int CPU_FEATURE_SSE_FP = 1 << 11;
  36. static const long int CPU_FEATURE_SSE_MMX = 1 << 12;
  37. static const long int CPU_FEATURE_CMOV = 1 << 13;
  38. static const long int CPU_FEATURE_MTRR = 1 << 14;
  39. static const long int CPU_FEATURE_L1CACHE = 1 << 15;
  40. static const long int CPU_FEATURE_L2CACHE = 1 << 16;
  41. static const long int CPU_FEATURE_L3CACHE = 1 << 17;
  42. static const long int CPU_FEATURE_ACPI = 1 << 18;
  43. static const long int CPU_FEATURE_THERMALMONITOR = 1 << 19;
  44. static const long int CPU_FEATURE_TEMPSENSEDIODE = 1 << 20;
  45. static const long int CPU_FEATURE_FREQUENCYID = 1 << 21;
  46. static const long int CPU_FEATURE_VOLTAGEID_FREQUENCY = 1 << 22;
  47. static const long int CPU_FEATURE_FPU = 1 << 23;
  48. public:
  49. SystemInformation();
  50. ~SystemInformation();
  51. const char* GetVendorString();
  52. const char* GetVendorID();
  53. std::string GetTypeID();
  54. std::string GetFamilyID();
  55. std::string GetModelID();
  56. std::string GetModelName();
  57. std::string GetSteppingCode();
  58. const char* GetExtendedProcessorName();
  59. const char* GetProcessorSerialNumber();
  60. int GetProcessorCacheSize();
  61. unsigned int GetLogicalProcessorsPerPhysical();
  62. float GetProcessorClockFrequency();
  63. int GetProcessorAPICID();
  64. int GetProcessorCacheXSize(long int);
  65. bool DoesCPUSupportFeature(long int);
  66. // returns an informative general description of the cpu
  67. // on this system.
  68. std::string GetCPUDescription();
  69. const char* GetHostname();
  70. std::string GetFullyQualifiedDomainName();
  71. const char* GetOSName();
  72. const char* GetOSRelease();
  73. const char* GetOSVersion();
  74. const char* GetOSPlatform();
  75. int GetOSIsWindows();
  76. int GetOSIsLinux();
  77. int GetOSIsApple();
  78. // returns an informative general description of the os
  79. // on this system.
  80. std::string GetOSDescription();
  81. // returns if the operating system is 64bit or not.
  82. bool Is64Bits();
  83. unsigned int GetNumberOfLogicalCPU();
  84. unsigned int GetNumberOfPhysicalCPU();
  85. bool DoesCPUSupportCPUID();
  86. // Retrieve id of the current running process
  87. LongLong GetProcessId();
  88. // Retrieve memory information in MiB.
  89. size_t GetTotalVirtualMemory();
  90. size_t GetAvailableVirtualMemory();
  91. size_t GetTotalPhysicalMemory();
  92. size_t GetAvailablePhysicalMemory();
  93. // returns an informative general description if the installed and
  94. // available ram on this system. See the GetHostMemoryTotal, and
  95. // Get{Host,Proc}MemoryAvailable methods for more information.
  96. std::string GetMemoryDescription(const char* hostLimitEnvVarName = NULL,
  97. const char* procLimitEnvVarName = NULL);
  98. // Retrieve amount of physical memory installed on the system in KiB
  99. // units.
  100. LongLong GetHostMemoryTotal();
  101. // Get total system RAM in units of KiB available colectivley to all
  102. // processes in a process group. An example of a process group
  103. // are the processes comprising an mpi program which is running in
  104. // parallel. The amount of memory reported may differ from the host
  105. // total if a host wide resource limit is applied. Such reource limits
  106. // are reported to us via an application specified environment variable.
  107. LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = NULL);
  108. // Get total system RAM in units of KiB available to this process.
  109. // This may differ from the host available if a per-process resource
  110. // limit is applied. per-process memory limits are applied on unix
  111. // system via rlimit API. Resource limits that are not imposed via
  112. // rlimit API may be reported to us via an application specified
  113. // environment variable.
  114. LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName = NULL,
  115. const char* procLimitEnvVarName = NULL);
  116. // Get the system RAM used by all processes on the host, in units of KiB.
  117. LongLong GetHostMemoryUsed();
  118. // Get system RAM used by this process id in units of KiB.
  119. LongLong GetProcMemoryUsed();
  120. // Return the load average of the machine or -0.0 if it cannot
  121. // be determined.
  122. double GetLoadAverage();
  123. // enable/disable stack trace signal handler. In order to
  124. // produce an informative stack trace the application should
  125. // be dynamically linked and compiled with debug symbols.
  126. static void SetStackTraceOnError(int enable);
  127. // format and return the current program stack in a string. In
  128. // order to produce an informative stack trace the application
  129. // should be dynamically linked and compiled with debug symbols.
  130. static std::string GetProgramStack(int firstFrame, int wholePath);
  131. /** Run the different checks */
  132. void RunCPUCheck();
  133. void RunOSCheck();
  134. void RunMemoryCheck();
  135. };
  136. } // namespace cmsys
  137. #endif