SystemInformation.hxx.in 6.11 KB
Newer Older
Kitware Robot's avatar
Kitware Robot committed
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
Kitware Robot's avatar
Kitware Robot committed
3 4 5
#ifndef @KWSYS_NAMESPACE@_SystemInformation_h
#define @KWSYS_NAMESPACE@_SystemInformation_h

Kitware Robot's avatar
Kitware Robot committed
6
#include <@KWSYS_NAMESPACE@/Configure.hxx>
Kitware Robot's avatar
Kitware Robot committed
7

Kitware Robot's avatar
Kitware Robot committed
8
#include <stddef.h> /* size_t */
Kitware Robot's avatar
Kitware Robot committed
9
#include <string>
Kitware Robot's avatar
Kitware Robot committed
10

Kitware Robot's avatar
Kitware Robot committed
11
namespace @KWSYS_NAMESPACE@ {
Kitware Robot's avatar
Kitware Robot committed
12

Kitware Robot's avatar
Kitware Robot committed
13
// forward declare the implementation class
Kitware Robot's avatar
Kitware Robot committed
14 15
class SystemInformationImplementation;

Kitware Robot's avatar
Kitware Robot committed
16 17 18 19 20 21 22
class @KWSYS_NAMESPACE@_EXPORT SystemInformation
{
#if @KWSYS_USE_LONG_LONG@
  typedef long long LongLong;
#elif @KWSYS_USE___INT64@
  typedef __int64 LongLong;
#else
Kitware Robot's avatar
Kitware Robot committed
23
#  error "No Long Long"
Kitware Robot's avatar
Kitware Robot committed
24 25 26 27
#endif
  friend class SystemInformationImplementation;
  SystemInformationImplementation* Implementation;

Kitware Robot's avatar
Kitware Robot committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
public:
  // possible parameter values for DoesCPUSupportFeature()
  static const long int CPU_FEATURE_MMX = 1 << 0;
  static const long int CPU_FEATURE_MMX_PLUS = 1 << 1;
  static const long int CPU_FEATURE_SSE = 1 << 2;
  static const long int CPU_FEATURE_SSE2 = 1 << 3;
  static const long int CPU_FEATURE_AMD_3DNOW = 1 << 4;
  static const long int CPU_FEATURE_AMD_3DNOW_PLUS = 1 << 5;
  static const long int CPU_FEATURE_IA64 = 1 << 6;
  static const long int CPU_FEATURE_MP_CAPABLE = 1 << 7;
  static const long int CPU_FEATURE_HYPERTHREAD = 1 << 8;
  static const long int CPU_FEATURE_SERIALNUMBER = 1 << 9;
  static const long int CPU_FEATURE_APIC = 1 << 10;
  static const long int CPU_FEATURE_SSE_FP = 1 << 11;
  static const long int CPU_FEATURE_SSE_MMX = 1 << 12;
  static const long int CPU_FEATURE_CMOV = 1 << 13;
  static const long int CPU_FEATURE_MTRR = 1 << 14;
  static const long int CPU_FEATURE_L1CACHE = 1 << 15;
  static const long int CPU_FEATURE_L2CACHE = 1 << 16;
  static const long int CPU_FEATURE_L3CACHE = 1 << 17;
  static const long int CPU_FEATURE_ACPI = 1 << 18;
  static const long int CPU_FEATURE_THERMALMONITOR = 1 << 19;
  static const long int CPU_FEATURE_TEMPSENSEDIODE = 1 << 20;
  static const long int CPU_FEATURE_FREQUENCYID = 1 << 21;
  static const long int CPU_FEATURE_VOLTAGEID_FREQUENCY = 1 << 22;
  static const long int CPU_FEATURE_FPU = 1 << 23;

Kitware Robot's avatar
Kitware Robot committed
55 56 57
public:
  SystemInformation();
  ~SystemInformation();
Kitware Robot's avatar
Kitware Robot committed
58

Kitware Robot's avatar
Kitware Robot committed
59 60 61
  SystemInformation(const SystemInformation&) = delete;
  SystemInformation& operator=(const SystemInformation&) = delete;

Kitware Robot's avatar
Kitware Robot committed
62 63
  const char* GetVendorString();
  const char* GetVendorID();
Kitware Robot's avatar
Kitware Robot committed
64 65 66 67 68
  std::string GetTypeID();
  std::string GetFamilyID();
  std::string GetModelID();
  std::string GetModelName();
  std::string GetSteppingCode();
Kitware Robot's avatar
Kitware Robot committed
69 70
  const char* GetExtendedProcessorName();
  const char* GetProcessorSerialNumber();
Kitware Robot's avatar
Kitware Robot committed
71 72 73 74 75 76
  int GetProcessorCacheSize();
  unsigned int GetLogicalProcessorsPerPhysical();
  float GetProcessorClockFrequency();
  int GetProcessorAPICID();
  int GetProcessorCacheXSize(long int);
  bool DoesCPUSupportFeature(long int);
Kitware Robot's avatar
Kitware Robot committed
77 78 79

  // returns an informative general description of the cpu
  // on this system.
Kitware Robot's avatar
Kitware Robot committed
80
  std::string GetCPUDescription();
Kitware Robot's avatar
Kitware Robot committed
81

Kitware Robot's avatar
Kitware Robot committed
82
  const char* GetHostname();
Kitware Robot's avatar
Kitware Robot committed
83
  std::string GetFullyQualifiedDomainName();
Kitware Robot's avatar
Kitware Robot committed
84

Kitware Robot's avatar
Kitware Robot committed
85 86 87 88
  const char* GetOSName();
  const char* GetOSRelease();
  const char* GetOSVersion();
  const char* GetOSPlatform();
Kitware Robot's avatar
Kitware Robot committed
89

Kitware Robot's avatar
Kitware Robot committed
90 91 92 93 94 95
  int GetOSIsWindows();
  int GetOSIsLinux();
  int GetOSIsApple();

  // returns an informative general description of the os
  // on this system.
Kitware Robot's avatar
Kitware Robot committed
96
  std::string GetOSDescription();
Kitware Robot's avatar
Kitware Robot committed
97

Kitware Robot's avatar
Kitware Robot committed
98
  // returns if the operating system is 64bit or not.
Kitware Robot's avatar
Kitware Robot committed
99 100
  bool Is64Bits();

Kitware Robot's avatar
Kitware Robot committed
101
  unsigned int GetNumberOfLogicalCPU();
Kitware Robot's avatar
Kitware Robot committed
102 103 104 105
  unsigned int GetNumberOfPhysicalCPU();

  bool DoesCPUSupportCPUID();

Kitware Robot's avatar
Kitware Robot committed
106 107 108
  // Retrieve id of the current running process
  LongLong GetProcessId();

Kitware Robot's avatar
Kitware Robot committed
109
  // Retrieve memory information in MiB.
Kitware Robot's avatar
Kitware Robot committed
110 111 112
  size_t GetTotalVirtualMemory();
  size_t GetAvailableVirtualMemory();
  size_t GetTotalPhysicalMemory();
Kitware Robot's avatar
Kitware Robot committed
113 114
  size_t GetAvailablePhysicalMemory();

Kitware Robot's avatar
Kitware Robot committed
115
  // returns an informative general description if the installed and
Kitware Robot's avatar
Kitware Robot committed
116
  // available ram on this system. See the GetHostMemoryTotal, and
Kitware Robot's avatar
Kitware Robot committed
117
  // Get{Host,Proc}MemoryAvailable methods for more information.
Kitware Robot's avatar
Kitware Robot committed
118 119
  std::string GetMemoryDescription(const char* hostLimitEnvVarName = NULL,
                                   const char* procLimitEnvVarName = NULL);
Kitware Robot's avatar
Kitware Robot committed
120 121 122 123 124 125 126 127 128 129

  // Retrieve amount of physical memory installed on the system in KiB
  // units.
  LongLong GetHostMemoryTotal();

  // Get total system RAM in units of KiB available colectivley to all
  // processes in a process group. An example of a process group
  // are the processes comprising an mpi program which is running in
  // parallel. The amount of memory reported may differ from the host
  // total if a host wide resource limit is applied. Such reource limits
Kitware Robot's avatar
Kitware Robot committed
130
  // are reported to us via an application specified environment variable.
Kitware Robot's avatar
Kitware Robot committed
131
  LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = NULL);
Kitware Robot's avatar
Kitware Robot committed
132 133 134 135

  // Get total system RAM in units of KiB available to this process.
  // This may differ from the host available if a per-process resource
  // limit is applied. per-process memory limits are applied on unix
Kitware Robot's avatar
Kitware Robot committed
136 137
  // system via rlimit API. Resource limits that are not imposed via
  // rlimit API may be reported to us via an application specified
Kitware Robot's avatar
Kitware Robot committed
138
  // environment variable.
Kitware Robot's avatar
Kitware Robot committed
139 140
  LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName = NULL,
                                  const char* procLimitEnvVarName = NULL);
Kitware Robot's avatar
Kitware Robot committed
141 142 143 144 145 146 147

  // Get the system RAM used by all processes on the host, in units of KiB.
  LongLong GetHostMemoryUsed();

  // Get system RAM used by this process id in units of KiB.
  LongLong GetProcMemoryUsed();

Kitware Robot's avatar
Kitware Robot committed
148 149 150 151
  // Return the load average of the machine or -0.0 if it cannot
  // be determined.
  double GetLoadAverage();

Kitware Robot's avatar
Kitware Robot committed
152 153 154
  // enable/disable stack trace signal handler. In order to
  // produce an informative stack trace the application should
  // be dynamically linked and compiled with debug symbols.
Kitware Robot's avatar
Kitware Robot committed
155
  static void SetStackTraceOnError(int enable);
Kitware Robot's avatar
Kitware Robot committed
156

Kitware Robot's avatar
Kitware Robot committed
157 158 159
  // format and return the current program stack in a string. In
  // order to produce an informative stack trace the application
  // should be dynamically linked and compiled with debug symbols.
Kitware Robot's avatar
Kitware Robot committed
160
  static std::string GetProgramStack(int firstFrame, int wholePath);
Kitware Robot's avatar
Kitware Robot committed
161

Kitware Robot's avatar
Kitware Robot committed
162 163 164 165 166
  /** Run the different checks */
  void RunCPUCheck();
  void RunOSCheck();
  void RunMemoryCheck();
};
Kitware Robot's avatar
Kitware Robot committed
167

Kitware Robot's avatar
Kitware Robot committed
168 169 170
} // namespace @KWSYS_NAMESPACE@

#endif