OpenShot Audio Library | OpenShotAudio: juce_SystemStats.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.1

Loading...
Searching...
No Matches
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
23namespace juce
24{
25
26 String SystemStats::getJUCEVersion()
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 {
54 DBG (SystemStats::getJUCEVersion());
55 }
56 };
57
58 static JuceVersionPrinter juceVersionPrinter;
59#endif
60
61 StringArray SystemStats::getDeviceIdentifiers()
62{
63 StringArray ids;
64
65 #if JUCE_WINDOWS
66 File f (File::getSpecialLocation (File::windowsSystemDirectory));
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//==============================================================================
85struct CPUInformation
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, hasFMA3 = false, hasFMA4 = false, hasSSSE3 = false,
95 hasSSE41 = false, 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
103static 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::hasFMA3() noexcept { return getCPUInformation().hasFMA3; }
114 bool SystemStats::hasFMA4() noexcept { return getCPUInformation().hasFMA4; }
115 bool SystemStats::hasSSE() noexcept { return getCPUInformation().hasSSE; }
116 bool SystemStats::hasSSE2() noexcept { return getCPUInformation().hasSSE2; }
117 bool SystemStats::hasSSE3() noexcept { return getCPUInformation().hasSSE3; }
118 bool SystemStats::hasSSSE3() noexcept { return getCPUInformation().hasSSSE3; }
119 bool SystemStats::hasSSE41() noexcept { return getCPUInformation().hasSSE41; }
120 bool SystemStats::hasSSE42() noexcept { return getCPUInformation().hasSSE42; }
121 bool SystemStats::hasAVX() noexcept { return getCPUInformation().hasAVX; }
122 bool SystemStats::hasAVX2() noexcept { return getCPUInformation().hasAVX2; }
123 bool SystemStats::hasAVX512F() noexcept { return getCPUInformation().hasAVX512F; }
124 bool SystemStats::hasAVX512BW() noexcept { return getCPUInformation().hasAVX512BW; }
125 bool SystemStats::hasAVX512CD() noexcept { return getCPUInformation().hasAVX512CD; }
126 bool SystemStats::hasAVX512DQ() noexcept { return getCPUInformation().hasAVX512DQ; }
127 bool SystemStats::hasAVX512ER() noexcept { return getCPUInformation().hasAVX512ER; }
128 bool SystemStats::hasAVX512IFMA() noexcept { return getCPUInformation().hasAVX512IFMA; }
129 bool SystemStats::hasAVX512PF() noexcept { return getCPUInformation().hasAVX512PF; }
130 bool SystemStats::hasAVX512VBMI() noexcept { return getCPUInformation().hasAVX512VBMI; }
131 bool SystemStats::hasAVX512VL() noexcept { return getCPUInformation().hasAVX512VL; }
132 bool SystemStats::hasAVX512VPOPCNTDQ() noexcept { return getCPUInformation().hasAVX512VPOPCNTDQ; }
133 bool SystemStats::hasNeon() noexcept { return getCPUInformation().hasNeon; }
134
135
136//==============================================================================
137 String SystemStats::getStackBacktrace()
138{
139 String result;
140
141 #if JUCE_ANDROID || JUCE_MINGW
142 jassertfalse; // sorry, not implemented yet!
143
144 #elif JUCE_WINDOWS
145 HANDLE process = GetCurrentProcess();
146 SymInitialize (process, nullptr, TRUE);
147
148 void* stack[128];
149 int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
150
151 HeapBlock<SYMBOL_INFO> symbol;
152 symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
153 symbol->MaxNameLen = 255;
154 symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
155
156 for (int i = 0; i < frames; ++i)
157 {
158 DWORD64 displacement = 0;
159
160 if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
161 {
162 result << i << ": ";
163
164 IMAGEHLP_MODULE64 moduleInfo;
165 zerostruct (moduleInfo);
166 moduleInfo.SizeOfStruct = sizeof (moduleInfo);
167
168 if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
169 result << moduleInfo.ModuleName << ": ";
170
171 result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
172 }
173 }
174
175 #else
176 void* stack[128];
177 int frames = backtrace (stack, numElementsInArray (stack));
178 char** frameStrings = backtrace_symbols (stack, frames);
179
180 for (int i = 0; i < frames; ++i)
181 result << frameStrings[i] << newLine;
182
183 ::free (frameStrings);
184 #endif
185
186 return result;
187}
188
189//==============================================================================
190static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr;
191
192#if JUCE_WINDOWS
193static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS ep)
194{
195 globalCrashHandler (ep);
196 return EXCEPTION_EXECUTE_HANDLER;
197}
198#else
199static void handleCrash (int signum)
200{
201 globalCrashHandler ((void*) (pointer_sized_int) signum);
202 ::kill (getpid(), SIGKILL);
203}
204
205int juce_siginterrupt (int sig, int flag);
206#endif
207
208 void SystemStats::setApplicationCrashHandler (CrashHandlerFunction handler)
209{
210 jassert (handler != nullptr); // This must be a valid function.
211 globalCrashHandler = handler;
212
213 #if JUCE_WINDOWS
214 SetUnhandledExceptionFilter (handleCrash);
215 #else
216 const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS };
217
218 for (int i = 0; i < numElementsInArray (signals); ++i)
219 {
220 ::signal (signals[i], handleCrash);
221 juce_siginterrupt (signals[i], 1);
222 }
223 #endif
224}
225
226 bool SystemStats::isRunningInAppExtensionSandbox() noexcept
227{
228 #if JUCE_MAC || JUCE_IOS
229 static bool firstQuery = true;
230 static bool isRunningInAppSandbox = false;
231
232 if (firstQuery)
233 {
234 firstQuery = false;
235
236 File bundle = File::getSpecialLocation (File::invokedExecutableFile).getParentDirectory();
237
238 #if JUCE_MAC
239 bundle = bundle.getParentDirectory().getParentDirectory();
240 #endif
241
242 if (bundle.isDirectory())
243 isRunningInAppSandbox = (bundle.getFileExtension() == ".appex");
244 }
245
246 return isRunningInAppSandbox;
247 #else
248 return false;
249 #endif
250}
251
252} // namespace juce
juce::File
Definition: juce_File.h:41
juce::File::isDirectory
bool isDirectory() const
juce::File::getFileExtension
String getFileExtension() const
Definition: juce_File.cpp:669
juce::File::getSpecialLocation
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
juce::File::invokedExecutableFile
@ invokedExecutableFile
Definition: juce_File.h:912
juce::File::getParentDirectory
File getParentDirectory() const
Definition: juce_File.cpp:360
juce::File::getFileIdentifier
uint64 getFileIdentifier() const
juce::HeapBlock
Definition: juce_HeapBlock.h:87
juce::HeapBlock::calloc
void calloc(SizeType newNumElements, const size_t elementSize=sizeof(ElementType))
Definition: juce_HeapBlock.h:263
juce::MACAddress::getAllAddresses
static Array< MACAddress > getAllAddresses()
Definition: juce_MACAddress.cpp:88
juce::StringArray
Definition: juce_StringArray.h:35
juce::StringArray::add
void add(String stringToAdd)
Definition: juce_StringArray.cpp:135
juce::StringArray::isEmpty
bool isEmpty() const noexcept
Definition: juce_StringArray.h:138
juce::String
Definition: juce_String.h:39
juce::String::toHexString
static String toHexString(IntegerType number)
Definition: juce_String.h:1053
juce::SystemStats::hasAVX512CD
static bool hasAVX512CD() noexcept
Definition: juce_SystemStats.cpp:125
juce::SystemStats::getStackBacktrace
static String getStackBacktrace()
Definition: juce_SystemStats.cpp:137
juce::SystemStats::hasMMX
static bool hasMMX() noexcept
Definition: juce_SystemStats.cpp:111
juce::SystemStats::setApplicationCrashHandler
static void setApplicationCrashHandler(CrashHandlerFunction)
Definition: juce_SystemStats.cpp:208
juce::SystemStats::CrashHandlerFunction
void(*)(void *) CrashHandlerFunction
Definition: juce_SystemStats.h:219
juce::SystemStats::getNumPhysicalCpus
static int getNumPhysicalCpus() noexcept
Definition: juce_SystemStats.cpp:110
juce::SystemStats::hasAVX512ER
static bool hasAVX512ER() noexcept
Definition: juce_SystemStats.cpp:127
juce::SystemStats::has3DNow
static bool has3DNow() noexcept
Definition: juce_SystemStats.cpp:112
juce::SystemStats::hasAVX2
static bool hasAVX2() noexcept
Definition: juce_SystemStats.cpp:122
juce::SystemStats::hasAVX512VPOPCNTDQ
static bool hasAVX512VPOPCNTDQ() noexcept
Definition: juce_SystemStats.cpp:132
juce::SystemStats::hasSSE
static bool hasSSE() noexcept
Definition: juce_SystemStats.cpp:115
juce::SystemStats::hasAVX512DQ
static bool hasAVX512DQ() noexcept
Definition: juce_SystemStats.cpp:126
juce::SystemStats::isRunningInAppExtensionSandbox
static bool isRunningInAppExtensionSandbox() noexcept
Definition: juce_SystemStats.cpp:226
juce::SystemStats::hasNeon
static bool hasNeon() noexcept
Definition: juce_SystemStats.cpp:133
juce::SystemStats::hasAVX512F
static bool hasAVX512F() noexcept
Definition: juce_SystemStats.cpp:123
juce::SystemStats::hasSSE3
static bool hasSSE3() noexcept
Definition: juce_SystemStats.cpp:117
juce::SystemStats::hasSSE2
static bool hasSSE2() noexcept
Definition: juce_SystemStats.cpp:116
juce::SystemStats::hasAVX
static bool hasAVX() noexcept
Definition: juce_SystemStats.cpp:121
juce::SystemStats::hasAVX512VBMI
static bool hasAVX512VBMI() noexcept
Definition: juce_SystemStats.cpp:130
juce::SystemStats::hasSSSE3
static bool hasSSSE3() noexcept
Definition: juce_SystemStats.cpp:118
juce::SystemStats::hasAVX512VL
static bool hasAVX512VL() noexcept
Definition: juce_SystemStats.cpp:131
juce::SystemStats::hasAVX512PF
static bool hasAVX512PF() noexcept
Definition: juce_SystemStats.cpp:129
juce::SystemStats::hasSSE41
static bool hasSSE41() noexcept
Definition: juce_SystemStats.cpp:119
juce::SystemStats::getDeviceIdentifiers
static StringArray getDeviceIdentifiers()
Definition: juce_SystemStats.cpp:61
juce::SystemStats::hasFMA4
static bool hasFMA4() noexcept
Definition: juce_SystemStats.cpp:114
juce::SystemStats::getJUCEVersion
static String getJUCEVersion()
Definition: juce_SystemStats.cpp:26
juce::SystemStats::hasSSE42
static bool hasSSE42() noexcept
Definition: juce_SystemStats.cpp:120
juce::SystemStats::hasFMA3
static bool hasFMA3() noexcept
Definition: juce_SystemStats.cpp:113
juce::SystemStats::hasAVX512IFMA
static bool hasAVX512IFMA() noexcept
Definition: juce_SystemStats.cpp:128
juce::SystemStats::hasAVX512BW
static bool hasAVX512BW() noexcept
Definition: juce_SystemStats.cpp:124
juce::SystemStats::getNumCpus
static int getNumCpus() noexcept
Definition: juce_SystemStats.cpp:109