1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2017 - ROLI Ltd.
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_4     = MacOSX | 4,
56         MacOSX_10_5     = MacOSX | 5,
57         MacOSX_10_6     = MacOSX | 6,
58         MacOSX_10_7     = MacOSX | 7,
59         MacOSX_10_8     = MacOSX | 8,
60         MacOSX_10_9     = MacOSX | 9,
61         MacOSX_10_10    = MacOSX | 10,
62         MacOSX_10_11    = MacOSX | 11,
63         MacOSX_10_12    = MacOSX | 12,
64         MacOSX_10_13    = MacOSX | 13,
65         MacOSX_10_14    = MacOSX | 14,
66 
67         Win2000         = Windows | 1,
68         WinXP           = Windows | 2,
69         WinVista        = Windows | 3,
70         Windows7        = Windows | 4,
71         Windows8_0      = Windows | 5,
72         Windows8_1      = Windows | 6,
73         Windows10       = Windows | 7
74     };
75 
76     /** Returns the type of operating system we're running on.
77 
78         @returns one of the values from the OperatingSystemType enum.
79         @see getOperatingSystemName
80     */
81     static OperatingSystemType getOperatingSystemType();
82 
83     /** Returns the name of the type of operating system we're running on.
84 
85         @returns a string describing the OS type.
86         @see getOperatingSystemType
87     */
88     static String getOperatingSystemName();
89 
90     /** Returns true if the OS is 64-bit, or false for a 32-bit OS. */
91     static bool isOperatingSystem64Bit();
92 
93     /** Returns an environment variable.
94         If the named value isn't set, this will return the defaultValue string instead.
95     */
96     static String getEnvironmentVariable (const String& name, const String& defaultValue);
97 
98     //==============================================================================
99     /** Returns the current user's name, if available.
100         @see getFullUserName()
101     */
102     static String getLogonName();
103 
104     /** Returns the current user's full name, if available.
105         On some OSes, this may just return the same value as getLogonName().
106         @see getLogonName()
107     */
108     static String getFullUserName();
109 
110     /** Returns the host-name of the computer. */
111     static String getComputerName();
112 
113     /** Returns the language of the user's locale.
114         The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2)
115     */
116     static String getUserLanguage();
117 
118     /** Returns the region of the user's locale.
119         The return value is a 2 letter country code (ISO 3166-1 alpha-2).
120     */
121     static String getUserRegion();
122 
123     /** Returns the user's display language.
124         The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2).
125         Note that depending on the OS and region, this may also be followed by a dash
126         and a sub-region code, e.g "en-GB"
127     */
128     static String getDisplayLanguage();
129 
130     /** This will attempt to return some kind of string describing the device.
131         If no description is available, it'll just return an empty string. You may
132         want to use this for things like determining the type of phone/iPad, etc.
133     */
134     static String getDeviceDescription();
135 
136     /** This will attempt to return the manufacturer of the device.
137         If no description is available, it'll just return an empty string.
138     */
139     static String getDeviceManufacturer();
140 
141     /** This method calculates some IDs to uniquely identify the device.
142 
143         The first choice for an ID is a filesystem ID for the user's home folder or
144         windows directory. If that fails then this function returns the MAC addresses.
145     */
146     static StringArray getDeviceIdentifiers();
147 
148     //==============================================================================
149     // CPU and memory information..
150 
151     /** Returns the number of logical CPU cores. */
152     static int getNumCpus() noexcept;
153 
154     /** Returns the number of physical CPU cores. */
155     static int getNumPhysicalCpus() noexcept;
156 
157     /** Returns the approximate CPU speed.
158         @returns    the speed in megahertz, e.g. 1500, 2500, 32000 (depending on
159                     what year you're reading this...)
160     */
161     static int getCpuSpeedInMegahertz();
162 
163     /** Returns a string to indicate the CPU vendor.
164         Might not be known on some systems.
165     */
166     static String getCpuVendor();
167 
168     /** Attempts to return a string describing the CPU model.
169         May not be available on some systems.
170     */
171     static String getCpuModel();
172 
173     static bool hasMMX() noexcept;             /**< Returns true if Intel MMX instructions are available. */
174     static bool has3DNow() noexcept;           /**< Returns true if AMD 3DNOW instructions are available. */
175     static bool hasFMA3() noexcept;            /**< Returns true if AMD FMA3 instructions are available. */
176     static bool hasFMA4() noexcept;            /**< Returns true if AMD FMA4 instructions are available. */
177     static bool hasSSE() noexcept;             /**< Returns true if Intel SSE instructions are available. */
178     static bool hasSSE2() noexcept;            /**< Returns true if Intel SSE2 instructions are available. */
179     static bool hasSSE3() noexcept;            /**< Returns true if Intel SSE3 instructions are available. */
180     static bool hasSSSE3() noexcept;           /**< Returns true if Intel SSSE3 instructions are available. */
181     static bool hasSSE41() noexcept;           /**< Returns true if Intel SSE4.1 instructions are available. */
182     static bool hasSSE42() noexcept;           /**< Returns true if Intel SSE4.2 instructions are available. */
183     static bool hasAVX() noexcept;             /**< Returns true if Intel AVX instructions are available. */
184     static bool hasAVX2() noexcept;            /**< Returns true if Intel AVX2 instructions are available. */
185     static bool hasAVX512F() noexcept;         /**< Returns true if Intel AVX-512 Foundation instructions are available. */
186     static bool hasAVX512BW() noexcept;        /**< Returns true if Intel AVX-512 Byte and Word instructions are available. */
187     static bool hasAVX512CD() noexcept;        /**< Returns true if Intel AVX-512 Conflict Detection instructions are available. */
188     static bool hasAVX512DQ() noexcept;        /**< Returns true if Intel AVX-512 Doubleword and Quadword instructions are available. */
189     static bool hasAVX512ER() noexcept;        /**< Returns true if Intel AVX-512 Exponential and Reciprocal instructions are available. */
190     static bool hasAVX512IFMA() noexcept;      /**< Returns true if Intel AVX-512 Integer Fused Multiply-Add instructions are available. */
191     static bool hasAVX512PF() noexcept;        /**< Returns true if Intel AVX-512 Prefetch instructions are available. */
192     static bool hasAVX512VBMI() noexcept;      /**< Returns true if Intel AVX-512 Vector Bit Manipulation instructions are available. */
193     static bool hasAVX512VL() noexcept;        /**< Returns true if Intel AVX-512 Vector Length instructions are available. */
194     static bool hasAVX512VPOPCNTDQ() noexcept; /**< Returns true if Intel AVX-512 Vector Population Count Double and Quad-word instructions are available. */
195     static bool hasNeon() noexcept;            /**< Returns true if ARM NEON instructions are available. */
196 
197     //==============================================================================
198     /** Finds out how much RAM is in the machine.
199         @returns    the approximate number of megabytes of memory, or zero if
200                     something goes wrong when finding out.
201     */
202     static int getMemorySizeInMegabytes();
203 
204     /** Returns the system page-size.
205         This is only used by programmers with beards.
206     */
207     static int getPageSize();
208 
209     //==============================================================================
210     /** Returns a backtrace of the current call-stack.
211         The usefulness of the result will depend on the level of debug symbols
212         that are available in the executable.
213     */
214     static String getStackBacktrace();
215 
216     /** A function type for use in setApplicationCrashHandler().
217         When called, its void* argument will contain platform-specific data about the crash.
218     */
219     using CrashHandlerFunction = void(*)(void*);
220 
221     /** Sets up a global callback function that will be called if the application
222         executes some kind of illegal instruction.
223 
224         You may want to call getStackBacktrace() in your handler function, to find out
225         where the problem happened and log it, etc.
226     */
227     static void setApplicationCrashHandler (CrashHandlerFunction);
228 
229     /** Returns true if this code is running inside an app extension sandbox.
230         This function will always return false on windows, linux and android.
231     */
232     static bool isRunningInAppExtensionSandbox() noexcept;
233 
234 
235     //==============================================================================
236     // This method was spelt wrong! Please change your code to use getCpuSpeedInMegahertz() instead
237     JUCE_DEPRECATED_WITH_BODY (static int getCpuSpeedInMegaherz(), { return getCpuSpeedInMegahertz(); })
238 
239 private:
240     SystemStats() = delete; // uses only static methods
241     JUCE_DECLARE_NON_COPYABLE (SystemStats)
242 };
243 
244 } // namespace juce
245