SystemInformation.hxx.in 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 @KWSYS_NAMESPACE@_SystemInformation_h
  4. #define @KWSYS_NAMESPACE@_SystemInformation_h
  5. #include <@KWSYS_NAMESPACE@/Configure.hxx>
  6. #include <stddef.h> /* size_t */
  7. #include <string>
  8. namespace @KWSYS_NAMESPACE@ {
  9. // forward declare the implementation class
  10. class SystemInformationImplementation;
  11. class @KWSYS_NAMESPACE@_EXPORT SystemInformation
  12. {
  13. #if @KWSYS_USE_LONG_LONG@
  14. typedef long long LongLong;
  15. #elif @KWSYS_USE___INT64@
  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. SystemInformation(const SystemInformation&) = delete;
  52. SystemInformation& operator=(const SystemInformation&) = delete;
  53. const char* GetVendorString();
  54. const char* GetVendorID();
  55. std::string GetTypeID();
  56. std::string GetFamilyID();
  57. std::string GetModelID();
  58. std::string GetModelName();
  59. std::string GetSteppingCode();
  60. const char* GetExtendedProcessorName();
  61. const char* GetProcessorSerialNumber();
  62. int GetProcessorCacheSize();
  63. unsigned int GetLogicalProcessorsPerPhysical();
  64. float GetProcessorClockFrequency();
  65. int GetProcessorAPICID();
  66. int GetProcessorCacheXSize(long int);
  67. bool DoesCPUSupportFeature(long int);
  68. // returns an informative general description of the cpu
  69. // on this system.
  70. std::string GetCPUDescription();
  71. const char* GetHostname();
  72. std::string GetFullyQualifiedDomainName();
  73. const char* GetOSName();
  74. const char* GetOSRelease();
  75. const char* GetOSVersion();
  76. const char* GetOSPlatform();
  77. int GetOSIsWindows();
  78. int GetOSIsLinux();
  79. int GetOSIsApple();
  80. // returns an informative general description of the os
  81. // on this system.
  82. std::string GetOSDescription();
  83. // returns if the operating system is 64bit or not.
  84. bool Is64Bits();
  85. unsigned int GetNumberOfLogicalCPU();
  86. unsigned int GetNumberOfPhysicalCPU();
  87. bool DoesCPUSupportCPUID();
  88. // Retrieve id of the current running process
  89. LongLong GetProcessId();
  90. // Retrieve memory information in MiB.
  91. size_t GetTotalVirtualMemory();
  92. size_t GetAvailableVirtualMemory();
  93. size_t GetTotalPhysicalMemory();
  94. size_t GetAvailablePhysicalMemory();
  95. // returns an informative general description if the installed and
  96. // available ram on this system. See the GetHostMemoryTotal, and
  97. // Get{Host,Proc}MemoryAvailable methods for more information.
  98. std::string GetMemoryDescription(const char* hostLimitEnvVarName = NULL,
  99. const char* procLimitEnvVarName = NULL);
  100. // Retrieve amount of physical memory installed on the system in KiB
  101. // units.
  102. LongLong GetHostMemoryTotal();
  103. // Get total system RAM in units of KiB available colectivley to all
  104. // processes in a process group. An example of a process group
  105. // are the processes comprising an mpi program which is running in
  106. // parallel. The amount of memory reported may differ from the host
  107. // total if a host wide resource limit is applied. Such reource limits
  108. // are reported to us via an application specified environment variable.
  109. LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = NULL);
  110. // Get total system RAM in units of KiB available to this process.
  111. // This may differ from the host available if a per-process resource
  112. // limit is applied. per-process memory limits are applied on unix
  113. // system via rlimit API. Resource limits that are not imposed via
  114. // rlimit API may be reported to us via an application specified
  115. // environment variable.
  116. LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName = NULL,
  117. const char* procLimitEnvVarName = NULL);
  118. // Get the system RAM used by all processes on the host, in units of KiB.
  119. LongLong GetHostMemoryUsed();
  120. // Get system RAM used by this process id in units of KiB.
  121. LongLong GetProcMemoryUsed();
  122. // Return the load average of the machine or -0.0 if it cannot
  123. // be determined.
  124. double GetLoadAverage();
  125. // enable/disable stack trace signal handler. In order to
  126. // produce an informative stack trace the application should
  127. // be dynamically linked and compiled with debug symbols.
  128. static void SetStackTraceOnError(int enable);
  129. // format and return the current program stack in a string. In
  130. // order to produce an informative stack trace the application
  131. // should be dynamically linked and compiled with debug symbols.
  132. static std::string GetProgramStack(int firstFrame, int wholePath);
  133. /** Run the different checks */
  134. void RunCPUCheck();
  135. void RunOSCheck();
  136. void RunMemoryCheck();
  137. };
  138. } // namespace @KWSYS_NAMESPACE@
  139. #endif