juce_SystemStats.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_SYSTEMSTATS_H_INCLUDED
  22. #define JUCE_SYSTEMSTATS_H_INCLUDED
  23. //==============================================================================
  24. /**
  25. Contains methods for finding out about the current hardware and OS configuration.
  26. */
  27. class JUCE_API SystemStats
  28. {
  29. public:
  30. //==============================================================================
  31. /** Returns the current version of JUCE,
  32. See also the JUCE_VERSION, JUCE_MAJOR_VERSION and JUCE_MINOR_VERSION macros.
  33. */
  34. static String getJUCEVersion();
  35. //==============================================================================
  36. /** The set of possible results of the getOperatingSystemType() method. */
  37. enum OperatingSystemType
  38. {
  39. UnknownOS = 0,
  40. MacOSX = 0x0100, /**< To test whether any version of OSX is running,
  41. you can use the expression ((getOperatingSystemType() & MacOSX) != 0). */
  42. Windows = 0x0200, /**< To test whether any version of Windows is running,
  43. you can use the expression ((getOperatingSystemType() & Windows) != 0). */
  44. Linux = 0x0400,
  45. Android = 0x0800,
  46. iOS = 0x1000,
  47. MacOSX_10_4 = MacOSX | 4,
  48. MacOSX_10_5 = MacOSX | 5,
  49. MacOSX_10_6 = MacOSX | 6,
  50. MacOSX_10_7 = MacOSX | 7,
  51. MacOSX_10_8 = MacOSX | 8,
  52. MacOSX_10_9 = MacOSX | 9,
  53. MacOSX_10_10 = MacOSX | 10,
  54. MacOSX_10_11 = MacOSX | 11,
  55. Win2000 = Windows | 1,
  56. WinXP = Windows | 2,
  57. WinVista = Windows | 3,
  58. Windows7 = Windows | 4,
  59. Windows8_0 = Windows | 5,
  60. Windows8_1 = Windows | 6,
  61. Windows10 = Windows | 7
  62. };
  63. /** Returns the type of operating system we're running on.
  64. @returns one of the values from the OperatingSystemType enum.
  65. @see getOperatingSystemName
  66. */
  67. static OperatingSystemType getOperatingSystemType();
  68. /** Returns the name of the type of operating system we're running on.
  69. @returns a string describing the OS type.
  70. @see getOperatingSystemType
  71. */
  72. static String getOperatingSystemName();
  73. /** Returns true if the OS is 64-bit, or false for a 32-bit OS. */
  74. static bool isOperatingSystem64Bit();
  75. /** Returns an environment variable.
  76. If the named value isn't set, this will return the defaultValue string instead.
  77. */
  78. static String getEnvironmentVariable (const String& name, const String& defaultValue);
  79. //==============================================================================
  80. /** Returns the current user's name, if available.
  81. @see getFullUserName()
  82. */
  83. static String getLogonName();
  84. /** Returns the current user's full name, if available.
  85. On some OSes, this may just return the same value as getLogonName().
  86. @see getLogonName()
  87. */
  88. static String getFullUserName();
  89. /** Returns the host-name of the computer. */
  90. static String getComputerName();
  91. /** Returns the language of the user's locale.
  92. The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2)
  93. */
  94. static String getUserLanguage();
  95. /** Returns the region of the user's locale.
  96. The return value is a 2 letter country code (ISO 3166-1 alpha-2).
  97. */
  98. static String getUserRegion();
  99. /** Returns the user's display language.
  100. The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2).
  101. Note that depending on the OS and region, this may also be followed by a dash
  102. and a sub-region code, e.g "en-GB"
  103. */
  104. static String getDisplayLanguage();
  105. /** This will attempt to return some kind of string describing the device.
  106. If no description is available, it'll just return an empty string. You may
  107. want to use this for things like determining the type of phone/iPad, etc.
  108. */
  109. static String getDeviceDescription();
  110. //==============================================================================
  111. // CPU and memory information..
  112. /** Returns the number of CPU cores. */
  113. static int getNumCpus() noexcept;
  114. /** Returns the approximate CPU speed.
  115. @returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on
  116. what year you're reading this...)
  117. */
  118. static int getCpuSpeedInMegaherz();
  119. /** Returns a string to indicate the CPU vendor.
  120. Might not be known on some systems.
  121. */
  122. static String getCpuVendor();
  123. static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */
  124. static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */
  125. static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */
  126. static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */
  127. static bool hasSSE3() noexcept; /**< Returns true if Intel SSE3 instructions are available. */
  128. static bool hasSSSE3() noexcept; /**< Returns true if Intel SSSE3 instructions are available. */
  129. static bool hasSSE41() noexcept; /**< Returns true if Intel SSE4.1 instructions are available. */
  130. static bool hasSSE42() noexcept; /**< Returns true if Intel SSE4.2 instructions are available. */
  131. static bool hasAVX() noexcept; /**< Returns true if Intel AVX instructions are available. */
  132. static bool hasAVX2() noexcept; /**< Returns true if Intel AVX2 instructions are available. */
  133. //==============================================================================
  134. /** Finds out how much RAM is in the machine.
  135. @returns the approximate number of megabytes of memory, or zero if
  136. something goes wrong when finding out.
  137. */
  138. static int getMemorySizeInMegabytes();
  139. /** Returns the system page-size.
  140. This is only used by programmers with beards.
  141. */
  142. static int getPageSize();
  143. //==============================================================================
  144. /** Returns a backtrace of the current call-stack.
  145. The usefulness of the result will depend on the level of debug symbols
  146. that are available in the executable.
  147. */
  148. static String getStackBacktrace();
  149. /** A void() function type, used by setApplicationCrashHandler(). */
  150. typedef void (*CrashHandlerFunction)();
  151. /** Sets up a global callback function that will be called if the application
  152. executes some kind of illegal instruction.
  153. You may want to call getStackBacktrace() in your handler function, to find out
  154. where the problem happened and log it, etc.
  155. */
  156. static void setApplicationCrashHandler (CrashHandlerFunction);
  157. /** Returns true if this code is running inside an app extension sandbox.
  158. This function will always return false on windows, linux and android.
  159. */
  160. static bool isRunningInAppExtensionSandbox() noexcept;
  161. private:
  162. //==============================================================================
  163. SystemStats();
  164. JUCE_DECLARE_NON_COPYABLE (SystemStats)
  165. };
  166. #endif // JUCE_SYSTEMSTATS_H_INCLUDED