OpenShot Library | libopenshot-audio  0.2.0
juce_SystemStats.cpp
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 
27 {
28  // Some basic tests, to keep an eye on things and make sure these types work ok
29  // on all platforms. Let me know if any of these assertions fail on your system!
30  static_assert (sizeof (pointer_sized_int) == sizeof (void*), "Basic sanity test failed: please report!");
31  static_assert (sizeof (int8) == 1, "Basic sanity test failed: please report!");
32  static_assert (sizeof (uint8) == 1, "Basic sanity test failed: please report!");
33  static_assert (sizeof (int16) == 2, "Basic sanity test failed: please report!");
34  static_assert (sizeof (uint16) == 2, "Basic sanity test failed: please report!");
35  static_assert (sizeof (int32) == 4, "Basic sanity test failed: please report!");
36  static_assert (sizeof (uint32) == 4, "Basic sanity test failed: please report!");
37  static_assert (sizeof (int64) == 8, "Basic sanity test failed: please report!");
38  static_assert (sizeof (uint64) == 8, "Basic sanity test failed: please report!");
39 
40  return "JUCE v" JUCE_STRINGIFY(JUCE_MAJOR_VERSION)
41  "." JUCE_STRINGIFY(JUCE_MINOR_VERSION)
42  "." JUCE_STRINGIFY(JUCE_BUILDNUMBER);
43 }
44 
45 #if JUCE_ANDROID && ! defined (JUCE_DISABLE_JUCE_VERSION_PRINTING)
46  #define JUCE_DISABLE_JUCE_VERSION_PRINTING 1
47 #endif
48 
49 #if JUCE_DEBUG && ! JUCE_DISABLE_JUCE_VERSION_PRINTING
50  struct JuceVersionPrinter
51  {
52  JuceVersionPrinter()
53  {
55  }
56  };
57 
58  static JuceVersionPrinter juceVersionPrinter;
59 #endif
60 
62 {
63  StringArray ids;
64 
65  #if JUCE_WINDOWS
67  #else
68  File f ("~");
69  #endif
70  if (auto num = f.getFileIdentifier())
71  {
72  ids.add (String::toHexString ((int64) num));
73  }
74  else
75  {
76  for (auto& address : MACAddress::getAllAddresses())
77  ids.add (address.toString());
78  }
79 
80  jassert (! ids.isEmpty()); // Failed to create any IDs!
81  return ids;
82 }
83 
84 //==============================================================================
86 {
87  CPUInformation() noexcept { initialise(); }
88 
89  void initialise() noexcept;
90 
91  int numLogicalCPUs = 0, numPhysicalCPUs = 0;
92 
93  bool hasMMX = false, hasSSE = false, hasSSE2 = false, hasSSE3 = false,
94  has3DNow = false, hasSSSE3 = false, hasSSE41 = false,
95  hasSSE42 = false, hasAVX = false, hasAVX2 = false,
96  hasAVX512F = false, hasAVX512BW = false, hasAVX512CD = false,
97  hasAVX512DQ = false, hasAVX512ER = false, hasAVX512IFMA = false,
98  hasAVX512PF = false, hasAVX512VBMI = false, hasAVX512VL = false,
99  hasAVX512VPOPCNTDQ = false,
100  hasNeon = false;
101 };
102 
103 static const CPUInformation& getCPUInformation() noexcept
104 {
105  static CPUInformation info;
106  return info;
107 }
108 
109 int SystemStats::getNumCpus() noexcept { return getCPUInformation().numLogicalCPUs; }
110 int SystemStats::getNumPhysicalCpus() noexcept { return getCPUInformation().numPhysicalCPUs; }
111 bool SystemStats::hasMMX() noexcept { return getCPUInformation().hasMMX; }
112 bool SystemStats::has3DNow() noexcept { return getCPUInformation().has3DNow; }
113 bool SystemStats::hasSSE() noexcept { return getCPUInformation().hasSSE; }
114 bool SystemStats::hasSSE2() noexcept { return getCPUInformation().hasSSE2; }
115 bool SystemStats::hasSSE3() noexcept { return getCPUInformation().hasSSE3; }
116 bool SystemStats::hasSSSE3() noexcept { return getCPUInformation().hasSSSE3; }
117 bool SystemStats::hasSSE41() noexcept { return getCPUInformation().hasSSE41; }
118 bool SystemStats::hasSSE42() noexcept { return getCPUInformation().hasSSE42; }
119 bool SystemStats::hasAVX() noexcept { return getCPUInformation().hasAVX; }
120 bool SystemStats::hasAVX2() noexcept { return getCPUInformation().hasAVX2; }
121 bool SystemStats::hasAVX512F() noexcept { return getCPUInformation().hasAVX512F; }
122 bool SystemStats::hasAVX512BW() noexcept { return getCPUInformation().hasAVX512BW; }
123 bool SystemStats::hasAVX512CD() noexcept { return getCPUInformation().hasAVX512CD; }
124 bool SystemStats::hasAVX512DQ() noexcept { return getCPUInformation().hasAVX512DQ; }
125 bool SystemStats::hasAVX512ER() noexcept { return getCPUInformation().hasAVX512ER; }
126 bool SystemStats::hasAVX512IFMA() noexcept { return getCPUInformation().hasAVX512IFMA; }
127 bool SystemStats::hasAVX512PF() noexcept { return getCPUInformation().hasAVX512PF; }
128 bool SystemStats::hasAVX512VBMI() noexcept { return getCPUInformation().hasAVX512VBMI; }
129 bool SystemStats::hasAVX512VL() noexcept { return getCPUInformation().hasAVX512VL; }
130 bool SystemStats::hasAVX512VPOPCNTDQ() noexcept { return getCPUInformation().hasAVX512VPOPCNTDQ; }
131 bool SystemStats::hasNeon() noexcept { return getCPUInformation().hasNeon; }
132 
133 
134 //==============================================================================
136 {
137  String result;
138 
139  #if JUCE_ANDROID || JUCE_MINGW
140  jassertfalse; // sorry, not implemented yet!
141 
142  #elif JUCE_WINDOWS
143  HANDLE process = GetCurrentProcess();
144  SymInitialize (process, nullptr, TRUE);
145 
146  void* stack[128];
147  int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
148 
149  HeapBlock<SYMBOL_INFO> symbol;
150  symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
151  symbol->MaxNameLen = 255;
152  symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
153 
154  for (int i = 0; i < frames; ++i)
155  {
156  DWORD64 displacement = 0;
157 
158  if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
159  {
160  result << i << ": ";
161 
162  IMAGEHLP_MODULE64 moduleInfo;
163  zerostruct (moduleInfo);
164  moduleInfo.SizeOfStruct = sizeof (moduleInfo);
165 
166  if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
167  result << moduleInfo.ModuleName << ": ";
168 
169  result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
170  }
171  }
172 
173  #else
174  void* stack[128];
175  int frames = backtrace (stack, numElementsInArray (stack));
176  char** frameStrings = backtrace_symbols (stack, frames);
177 
178  for (int i = 0; i < frames; ++i)
179  result << frameStrings[i] << newLine;
180 
181  ::free (frameStrings);
182  #endif
183 
184  return result;
185 }
186 
187 //==============================================================================
188 static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr;
189 
190 #if JUCE_WINDOWS
191 static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS ep)
192 {
193  globalCrashHandler (ep);
194  return EXCEPTION_EXECUTE_HANDLER;
195 }
196 #else
197 static void handleCrash (int signum)
198 {
199  globalCrashHandler ((void*) (pointer_sized_int) signum);
200  kill (getpid(), SIGKILL);
201 }
202 
203 int juce_siginterrupt (int sig, int flag);
204 #endif
205 
207 {
208  jassert (handler != nullptr); // This must be a valid function.
209  globalCrashHandler = handler;
210 
211  #if JUCE_WINDOWS
212  SetUnhandledExceptionFilter (handleCrash);
213  #else
214  const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS };
215 
216  for (int i = 0; i < numElementsInArray (signals); ++i)
217  {
218  ::signal (signals[i], handleCrash);
219  juce_siginterrupt (signals[i], 1);
220  }
221  #endif
222 }
223 
225 {
226  #if JUCE_MAC || JUCE_IOS
227  static bool firstQuery = true;
228  static bool isRunningInAppSandbox = false;
229 
230  if (firstQuery)
231  {
232  firstQuery = false;
233 
235 
236  #if JUCE_MAC
237  bundle = bundle.getParentDirectory().getParentDirectory();
238  #endif
239 
240  if (bundle.isDirectory())
241  isRunningInAppSandbox = (bundle.getFileExtension() == ".appex");
242  }
243 
244  return isRunningInAppSandbox;
245  #else
246  return false;
247  #endif
248 }
249 
250 } // namespace juce
juce::SystemStats::isRunningInAppExtensionSandbox
static bool isRunningInAppExtensionSandbox() noexcept
Returns true if this code is running inside an app extension sandbox.
Definition: juce_SystemStats.cpp:224
juce::StringArray
A special array for holding a list of strings.
Definition: juce_StringArray.h:38
juce::SystemStats::hasSSE
static bool hasSSE() noexcept
Returns true if Intel SSE instructions are available.
Definition: juce_SystemStats.cpp:113
juce::SystemStats::hasAVX512VPOPCNTDQ
static bool hasAVX512VPOPCNTDQ() noexcept
Returns true if Intel AVX-512 Vector Population Count Double and Quad-word instructions are available...
Definition: juce_SystemStats.cpp:130
juce::HeapBlock::calloc
void calloc(SizeType newNumElements, const size_t elementSize=sizeof(ElementType))
Allocates a specified amount of memory and clears it.
Definition: juce_HeapBlock.h:267
juce::SystemStats::hasAVX512PF
static bool hasAVX512PF() noexcept
Returns true if Intel AVX-512 Prefetch instructions are available.
Definition: juce_SystemStats.cpp:127
juce::MACAddress::getAllAddresses
static Array< MACAddress > getAllAddresses()
Returns a list of the MAC addresses of all the available network cards.
Definition: juce_MACAddress.cpp:88
juce::SystemStats::hasNeon
static bool hasNeon() noexcept
Returns true if ARM NEON instructions are available.
Definition: juce_SystemStats.cpp:131
juce::File::isDirectory
bool isDirectory() const
Checks whether the file is a directory that exists.
juce::HeapBlock
Very simple container class to hold a pointer to some data on the heap.
Definition: juce_HeapBlock.h:90
juce::File::getParentDirectory
File getParentDirectory() const
Returns the directory that contains this file or directory.
Definition: juce_File.cpp:340
juce::SystemStats::hasAVX
static bool hasAVX() noexcept
Returns true if Intel AVX instructions are available.
Definition: juce_SystemStats.cpp:119
juce::SystemStats::getDeviceIdentifiers
static StringArray getDeviceIdentifiers()
This method calculates some IDs to uniquely identify the device.
Definition: juce_SystemStats.cpp:61
juce::SystemStats::hasAVX512F
static bool hasAVX512F() noexcept
Returns true if Intel AVX-512 Foundation instructions are available.
Definition: juce_SystemStats.cpp:121
juce::File::getSpecialLocation
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Finds the location of a special type of file or directory, such as a home folder or documents folder.
juce::String::toHexString
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
Definition: juce_String.h:1055
juce::SystemStats::getNumCpus
static int getNumCpus() noexcept
Returns the number of logical CPU cores.
Definition: juce_SystemStats.cpp:109
juce::CPUInformation
Definition: juce_SystemStats.cpp:85
juce::SystemStats::CrashHandlerFunction
void(*)(void *) CrashHandlerFunction
A function type for use in setApplicationCrashHandler().
Definition: juce_SystemStats.h:219
juce::File
Represents a local file or directory.
Definition: juce_File.h:44
juce::SystemStats::hasAVX2
static bool hasAVX2() noexcept
Returns true if Intel AVX2 instructions are available.
Definition: juce_SystemStats.cpp:120
juce::SystemStats::hasAVX512BW
static bool hasAVX512BW() noexcept
Returns true if Intel AVX-512 Byte and Word instructions are available.
Definition: juce_SystemStats.cpp:122
juce::StringArray::isEmpty
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
Definition: juce_StringArray.h:142
juce::SystemStats::hasAVX512DQ
static bool hasAVX512DQ() noexcept
Returns true if Intel AVX-512 Doubleword and Quadword instructions are available.
Definition: juce_SystemStats.cpp:124
juce::SystemStats::hasAVX512VBMI
static bool hasAVX512VBMI() noexcept
Returns true if Intel AVX-512 Vector Bit Manipulation instructions are available.
Definition: juce_SystemStats.cpp:128
juce::File::invokedExecutableFile
@ invokedExecutableFile
Returns the file that was invoked to launch this executable.
Definition: juce_File.h:916
juce::SystemStats::getStackBacktrace
static String getStackBacktrace()
Returns a backtrace of the current call-stack.
Definition: juce_SystemStats.cpp:135
juce::SystemStats::hasSSSE3
static bool hasSSSE3() noexcept
Returns true if Intel SSSE3 instructions are available.
Definition: juce_SystemStats.cpp:116
juce::SystemStats::hasSSE42
static bool hasSSE42() noexcept
Returns true if Intel SSE4.2 instructions are available.
Definition: juce_SystemStats.cpp:118
juce::SystemStats::hasAVX512CD
static bool hasAVX512CD() noexcept
Returns true if Intel AVX-512 Conflict Detection instructions are available.
Definition: juce_SystemStats.cpp:123
juce::File::windowsSystemDirectory
@ windowsSystemDirectory
On a Windows machine, returns the location of the Windows/System32 folder.
Definition: juce_File.h:923
JUCE_MAJOR_VERSION
#define JUCE_MAJOR_VERSION
Current JUCE version number.
Definition: juce_StandardHeader.h:34
juce::SystemStats::hasSSE3
static bool hasSSE3() noexcept
Returns true if Intel SSE3 instructions are available.
Definition: juce_SystemStats.cpp:115
juce::SystemStats::hasAVX512IFMA
static bool hasAVX512IFMA() noexcept
Returns true if Intel AVX-512 Integer Fused Multiply-Add instructions are available.
Definition: juce_SystemStats.cpp:126
juce::File::getFileIdentifier
uint64 getFileIdentifier() const
Returns a unique identifier for the file, if one is available.
juce::SystemStats::getNumPhysicalCpus
static int getNumPhysicalCpus() noexcept
Returns the number of physical CPU cores.
Definition: juce_SystemStats.cpp:110
juce::File::getFileExtension
String getFileExtension() const
Returns the file's extension.
Definition: juce_File.cpp:649
juce::SystemStats::hasAVX512ER
static bool hasAVX512ER() noexcept
Returns true if Intel AVX-512 Exponential and Reciprocal instructions are available.
Definition: juce_SystemStats.cpp:125
juce::String
The JUCE String class!
Definition: juce_String.h:42
juce::SystemStats::getJUCEVersion
static String getJUCEVersion()
Returns the current version of JUCE, See also the JUCE_VERSION, JUCE_MAJOR_VERSION and JUCE_MINOR_VER...
Definition: juce_SystemStats.cpp:26
juce::SystemStats::hasSSE41
static bool hasSSE41() noexcept
Returns true if Intel SSE4.1 instructions are available.
Definition: juce_SystemStats.cpp:117
juce::SystemStats::hasAVX512VL
static bool hasAVX512VL() noexcept
Returns true if Intel AVX-512 Vector Length instructions are available.
Definition: juce_SystemStats.cpp:129
juce::SystemStats::has3DNow
static bool has3DNow() noexcept
Returns true if AMD 3DNOW instructions are available.
Definition: juce_SystemStats.cpp:112
juce::StringArray::add
void add(String stringToAdd)
Appends a string at the end of the array.
Definition: juce_StringArray.cpp:135
juce::SystemStats::hasMMX
static bool hasMMX() noexcept
Returns true if Intel MMX instructions are available.
Definition: juce_SystemStats.cpp:111
juce::SystemStats::setApplicationCrashHandler
static void setApplicationCrashHandler(CrashHandlerFunction)
Sets up a global callback function that will be called if the application executes some kind of illeg...
Definition: juce_SystemStats.cpp:206
juce::SystemStats::hasSSE2
static bool hasSSE2() noexcept
Returns true if Intel SSE2 instructions are available.
Definition: juce_SystemStats.cpp:114