1 /* 2 ============================================================================== 3 4 This file is part of the JUCE library. 5 Copyright (c) 2020 - Raw Material Software Limited 6 7 JUCE is an open source library subject to commercial or open-source 8 licensing. 9 10 The code included in this file is provided under the terms of the ISC license 11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission 12 To use, copy, modify, and/or distribute this software for any purpose with or 13 without fee is hereby granted provided that the above copyright notice and 14 this permission notice appear in all copies. 15 16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER 17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE 18 DISCLAIMED. 19 20 ============================================================================== 21 */ 22 23 namespace juce 24 { 25 26 //============================================================================== 27 /** 28 Contains methods for finding out about the current hardware and OS configuration. 29 30 @tags{Core} 31 */ 32 class JUCE_API SystemStats final 33 { 34 public: 35 //============================================================================== 36 /** Returns the current version of JUCE, 37 See also the JUCE_VERSION, JUCE_MAJOR_VERSION and JUCE_MINOR_VERSION macros. 38 */ 39 static String getJUCEVersion(); 40 41 //============================================================================== 42 /** The set of possible results of the getOperatingSystemType() method. */ 43 enum OperatingSystemType 44 { 45 UnknownOS = 0, 46 47 MacOSX = 0x0100, /**< To test whether any version of OSX is running, 48 you can use the expression ((getOperatingSystemType() & MacOSX) != 0). */ 49 Windows = 0x0200, /**< To test whether any version of Windows is running, 50 you can use the expression ((getOperatingSystemType() & Windows) != 0). */ 51 Linux = 0x0400, 52 Android = 0x0800, 53 iOS = 0x1000, 54 55 MacOSX_10_7 = MacOSX | 7, 56 MacOSX_10_8 = MacOSX | 8, 57 MacOSX_10_9 = MacOSX | 9, 58 MacOSX_10_10 = MacOSX | 10, 59 MacOSX_10_11 = MacOSX | 11, 60 MacOSX_10_12 = MacOSX | 12, 61 MacOSX_10_13 = MacOSX | 13, 62 MacOSX_10_14 = MacOSX | 14, 63 MacOSX_10_15 = MacOSX | 15, 64 MacOSX_11_0 = MacOSX | 16, 65 66 Win2000 = Windows | 1, 67 WinXP = Windows | 2, 68 WinVista = Windows | 3, 69 Windows7 = Windows | 4, 70 Windows8_0 = Windows | 5, 71 Windows8_1 = Windows | 6, 72 Windows10 = Windows | 7 73 }; 74 75 /** Returns the type of operating system we're running on. 76 77 @returns one of the values from the OperatingSystemType enum. 78 @see getOperatingSystemName 79 */ 80 static OperatingSystemType getOperatingSystemType(); 81 82 /** Returns the name of the type of operating system we're running on. 83 84 @returns a string describing the OS type. 85 @see getOperatingSystemType 86 */ 87 static String getOperatingSystemName(); 88 89 /** Returns true if the OS is 64-bit, or false for a 32-bit OS. */ 90 static bool isOperatingSystem64Bit(); 91 92 /** Returns an environment variable. 93 If the named value isn't set, this will return the defaultValue string instead. 94 */ 95 static String getEnvironmentVariable (const String& name, const String& defaultValue); 96 97 //============================================================================== 98 /** Returns the current user's name, if available. 99 @see getFullUserName() 100 */ 101 static String getLogonName(); 102 103 /** Returns the current user's full name, if available. 104 On some OSes, this may just return the same value as getLogonName(). 105 @see getLogonName() 106 */ 107 static String getFullUserName(); 108 109 /** Returns the host-name of the computer. */ 110 static String getComputerName(); 111 112 /** Returns the language of the user's locale. 113 The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2) 114 */ 115 static String getUserLanguage(); 116 117 /** Returns the region of the user's locale. 118 The return value is a 2 letter country code (ISO 3166-1 alpha-2). 119 */ 120 static String getUserRegion(); 121 122 /** Returns the user's display language. 123 The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2). 124 Note that depending on the OS and region, this may also be followed by a dash 125 and a sub-region code, e.g "en-GB" 126 */ 127 static String getDisplayLanguage(); 128 129 /** This will attempt to return some kind of string describing the device. 130 If no description is available, it'll just return an empty string. You may 131 want to use this for things like determining the type of phone/iPad, etc. 132 */ 133 static String getDeviceDescription(); 134 135 /** This will attempt to return the manufacturer of the device. 136 If no description is available, it'll just return an empty string. 137 */ 138 static String getDeviceManufacturer(); 139 140 /** This method calculates some IDs to uniquely identify the device. 141 142 The first choice for an ID is a filesystem ID for the user's home folder or 143 windows directory. If that fails then this function returns the MAC addresses. 144 */ 145 static StringArray getDeviceIdentifiers(); 146 147 //============================================================================== 148 // CPU and memory information.. 149 150 /** Returns the number of logical CPU cores. */ 151 static int getNumCpus() noexcept; 152 153 /** Returns the number of physical CPU cores. */ 154 static int getNumPhysicalCpus() noexcept; 155 156 /** Returns the approximate CPU speed. 157 @returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on 158 what year you're reading this...) 159 */ 160 static int getCpuSpeedInMegahertz(); 161 162 /** Returns a string to indicate the CPU vendor. 163 Might not be known on some systems. 164 */ 165 static String getCpuVendor(); 166 167 /** Attempts to return a string describing the CPU model. 168 May not be available on some systems. 169 */ 170 static String getCpuModel(); 171 172 static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */ 173 static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */ 174 static bool hasFMA3() noexcept; /**< Returns true if AMD FMA3 instructions are available. */ 175 static bool hasFMA4() noexcept; /**< Returns true if AMD FMA4 instructions are available. */ 176 static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */ 177 static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ 178 static bool hasSSE3() noexcept; /**< Returns true if Intel SSE3 instructions are available. */ 179 static bool hasSSSE3() noexcept; /**< Returns true if Intel SSSE3 instructions are available. */ 180 static bool hasSSE41() noexcept; /**< Returns true if Intel SSE4.1 instructions are available. */ 181 static bool hasSSE42() noexcept; /**< Returns true if Intel SSE4.2 instructions are available. */ 182 static bool hasAVX() noexcept; /**< Returns true if Intel AVX instructions are available. */ 183 static bool hasAVX2() noexcept; /**< Returns true if Intel AVX2 instructions are available. */ 184 static bool hasAVX512F() noexcept; /**< Returns true if Intel AVX-512 Foundation instructions are available. */ 185 static bool hasAVX512BW() noexcept; /**< Returns true if Intel AVX-512 Byte and Word instructions are available. */ 186 static bool hasAVX512CD() noexcept; /**< Returns true if Intel AVX-512 Conflict Detection instructions are available. */ 187 static bool hasAVX512DQ() noexcept; /**< Returns true if Intel AVX-512 Doubleword and Quadword instructions are available. */ 188 static bool hasAVX512ER() noexcept; /**< Returns true if Intel AVX-512 Exponential and Reciprocal instructions are available. */ 189 static bool hasAVX512IFMA() noexcept; /**< Returns true if Intel AVX-512 Integer Fused Multiply-Add instructions are available. */ 190 static bool hasAVX512PF() noexcept; /**< Returns true if Intel AVX-512 Prefetch instructions are available. */ 191 static bool hasAVX512VBMI() noexcept; /**< Returns true if Intel AVX-512 Vector Bit Manipulation instructions are available. */ 192 static bool hasAVX512VL() noexcept; /**< Returns true if Intel AVX-512 Vector Length instructions are available. */ 193 static bool hasAVX512VPOPCNTDQ() noexcept; /**< Returns true if Intel AVX-512 Vector Population Count Double and Quad-word instructions are available. */ 194 static bool hasNeon() noexcept; /**< Returns true if ARM NEON instructions are available. */ 195 196 //============================================================================== 197 /** Finds out how much RAM is in the machine. 198 @returns the approximate number of megabytes of memory, or zero if 199 something goes wrong when finding out. 200 */ 201 static int getMemorySizeInMegabytes(); 202 203 /** Returns the system page-size. 204 This is only used by programmers with beards. 205 */ 206 static int getPageSize(); 207 208 //============================================================================== 209 /** Returns a backtrace of the current call-stack. 210 The usefulness of the result will depend on the level of debug symbols 211 that are available in the executable. 212 */ 213 static String getStackBacktrace(); 214 215 /** A function type for use in setApplicationCrashHandler(). 216 When called, its void* argument will contain platform-specific data about the crash. 217 */ 218 using CrashHandlerFunction = void(*)(void*); 219 220 /** Sets up a global callback function that will be called if the application 221 executes some kind of illegal instruction. 222 223 You may want to call getStackBacktrace() in your handler function, to find out 224 where the problem happened and log it, etc. 225 */ 226 static void setApplicationCrashHandler (CrashHandlerFunction); 227 228 /** Returns true if this code is running inside an app extension sandbox. 229 This function will always return false on windows, linux and android. 230 */ 231 static bool isRunningInAppExtensionSandbox() noexcept; 232 233 234 //============================================================================== 235 // This method was spelt wrong! Please change your code to use getCpuSpeedInMegahertz() instead 236 JUCE_DEPRECATED_WITH_BODY (static int getCpuSpeedInMegaherz(), { return getCpuSpeedInMegahertz(); }) 237 238 private: 239 SystemStats() = delete; // uses only static methods 240 JUCE_DECLARE_NON_COPYABLE (SystemStats) 241 }; 242 243 } // namespace juce 244