LMMS
Loading...
Searching...
No Matches
juce_SystemStats.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - 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
23namespace 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)
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
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
75 jassert (! ids.isEmpty()); // Failed to create any IDs!
76 return ids;
77}
78
79//==============================================================================
97
99{
100 static CPUInformation info;
101 return info;
102}
103
104int SystemStats::getNumCpus() noexcept { return getCPUInformation().numLogicalCPUs; }
123bool SystemStats::hasAVX512IFMA() noexcept { return getCPUInformation().hasAVX512IFMA; }
125bool SystemStats::hasAVX512VBMI() noexcept { return getCPUInformation().hasAVX512VBMI; }
127bool SystemStats::hasAVX512VPOPCNTDQ() noexcept { return getCPUInformation().hasAVX512VPOPCNTDQ; }
129
130
131//==============================================================================
133{
135
136 #if JUCE_ANDROID || JUCE_MINGW || JUCE_WASM
137 jassertfalse; // sorry, not implemented yet!
138
139 #elif JUCE_WINDOWS
140 HANDLE process = GetCurrentProcess();
141 SymInitialize (process, nullptr, TRUE);
142
143 void* stack[128];
144 int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
145
147 symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
148 symbol->MaxNameLen = 255;
149 symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
150
151 for (int i = 0; i < frames; ++i)
152 {
153 DWORD64 displacement = 0;
154
155 if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
156 {
157 result << i << ": ";
158
159 IMAGEHLP_MODULE64 moduleInfo;
160 zerostruct (moduleInfo);
161 moduleInfo.SizeOfStruct = sizeof (moduleInfo);
162
163 if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
164 result << moduleInfo.ModuleName << ": ";
165
166 result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
167 }
168 }
169
170 #else
171 void* stack[128];
172 auto frames = backtrace (stack, numElementsInArray (stack));
173 char** frameStrings = backtrace_symbols (stack, frames);
174
175 for (int i = 0; i < frames; ++i)
176 result << frameStrings[i] << newLine;
177
178 ::free (frameStrings);
179 #endif
180
181 return result;
182}
183
184//==============================================================================
185#if ! JUCE_WASM
186
188
189#if JUCE_WINDOWS
190static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS ep)
191{
193 return EXCEPTION_EXECUTE_HANDLER;
194}
195#else
196static void handleCrash (int signum)
197{
198 globalCrashHandler ((void*) (pointer_sized_int) signum);
199 ::kill (getpid(), SIGKILL);
200}
201
202int juce_siginterrupt (int sig, int flag);
203#endif
204
206{
207 jassert (handler != nullptr); // This must be a valid function.
209
210 #if JUCE_WINDOWS
211 SetUnhandledExceptionFilter (handleCrash);
212 #else
213 const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS };
214
215 for (int i = 0; i < numElementsInArray (signals); ++i)
216 {
217 ::signal (signals[i], handleCrash);
218 juce_siginterrupt (signals[i], 1);
219 }
220 #endif
221}
222
223#endif
224
226{
227 #if JUCE_MAC || JUCE_IOS
228 static bool firstQuery = true;
229 static bool isRunningInAppSandbox = false;
230
231 if (firstQuery)
232 {
233 firstQuery = false;
234
236
237 #if JUCE_MAC
238 bundle = bundle.getParentDirectory().getParentDirectory();
239 #endif
240
241 if (bundle.isDirectory())
242 isRunningInAppSandbox = (bundle.getFileExtension() == ".appex");
243 }
244
245 return isRunningInAppSandbox;
246 #else
247 return false;
248 #endif
249}
250
251} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
void process(Alg_seq_ptr seq, bool tempo_flag, double tempo, bool flatten_flag)
Definition allegroconvert.cpp:42
static File getSpecialLocation(const SpecialLocationType type)
Definition File.cpp:1642
static String toHexString(int number)
Definition String.cpp:1830
Definition juce_File.h:45
bool isDirectory() const
Definition juce_posix_SharedCode.h:238
String getFileExtension() const
Definition juce_File.cpp:664
@ invokedExecutableFile
Definition juce_File.h:943
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Definition juce_linux_Files.cpp:107
File getParentDirectory() const
Definition juce_File.cpp:358
Definition juce_HeapBlock.h:87
void calloc(SizeType newNumElements, const size_t elementSize=sizeof(ElementType))
Definition juce_HeapBlock.h:263
Definition juce_StringArray.h:35
void add(String stringToAdd)
Definition juce_StringArray.cpp:136
bool isEmpty() const noexcept
Definition juce_StringArray.h:139
Definition juce_String.h:53
static String toHexString(IntegerType number)
Definition juce_String.h:1097
static bool hasAVX512CD() noexcept
Definition juce_SystemStats.cpp:120
static String getStackBacktrace()
Definition juce_SystemStats.cpp:132
static bool hasMMX() noexcept
Definition juce_SystemStats.cpp:106
static void setApplicationCrashHandler(CrashHandlerFunction)
Definition juce_SystemStats.cpp:205
void(*)(void *) CrashHandlerFunction
Definition juce_SystemStats.h:220
static int getNumPhysicalCpus() noexcept
Definition juce_SystemStats.cpp:105
static bool hasAVX512ER() noexcept
Definition juce_SystemStats.cpp:122
static bool has3DNow() noexcept
Definition juce_SystemStats.cpp:107
static bool hasAVX2() noexcept
Definition juce_SystemStats.cpp:117
static bool hasAVX512VPOPCNTDQ() noexcept
Definition juce_SystemStats.cpp:127
static bool hasSSE() noexcept
Definition juce_SystemStats.cpp:110
static bool hasAVX512DQ() noexcept
Definition juce_SystemStats.cpp:121
static bool isRunningInAppExtensionSandbox() noexcept
Definition juce_SystemStats.cpp:225
static bool hasNeon() noexcept
Definition juce_SystemStats.cpp:128
static bool hasAVX512F() noexcept
Definition juce_SystemStats.cpp:118
static bool hasSSE3() noexcept
Definition juce_SystemStats.cpp:112
static bool hasSSE2() noexcept
Definition juce_SystemStats.cpp:111
static bool hasAVX() noexcept
Definition juce_SystemStats.cpp:116
static bool hasAVX512VBMI() noexcept
Definition juce_SystemStats.cpp:125
static bool hasSSSE3() noexcept
Definition juce_SystemStats.cpp:113
static bool hasAVX512VL() noexcept
Definition juce_SystemStats.cpp:126
static bool hasAVX512PF() noexcept
Definition juce_SystemStats.cpp:124
static bool hasSSE41() noexcept
Definition juce_SystemStats.cpp:114
static StringArray getDeviceIdentifiers()
Definition juce_SystemStats.cpp:61
static bool hasFMA4() noexcept
Definition juce_SystemStats.cpp:109
static String getJUCEVersion()
Definition juce_SystemStats.cpp:26
static bool hasSSE42() noexcept
Definition juce_SystemStats.cpp:115
static bool hasFMA3() noexcept
Definition juce_SystemStats.cpp:108
static bool hasAVX512IFMA() noexcept
Definition juce_SystemStats.cpp:123
static bool hasAVX512BW() noexcept
Definition juce_SystemStats.cpp:119
static int getNumCpus() noexcept
Definition juce_SystemStats.cpp:104
File getParentDirectory() const
Definition File.cpp:365
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
struct backing_store_struct * info
Definition jmemsys.h:183
#define jassert(expression)
#define DBG(textToWrite)
#define JUCE_STRINGIFY(item)
#define jassertfalse
#define JUCE_MINOR_VERSION
Definition juce_StandardHeader.h:31
#define JUCE_BUILDNUMBER
Definition juce_StandardHeader.h:32
#define JUCE_MAJOR_VERSION
Definition juce_StandardHeader.h:30
Definition carla_juce.cpp:31
static const CPUInformation & getCPUInformation() noexcept
Definition juce_SystemStats.cpp:98
void zerostruct(Type &structure) noexcept
Definition juce_Memory.h:32
int juce_siginterrupt(int sig, int flag)
Definition juce_posix_SharedCode.h:143
NewLine newLine
Definition juce_String.cpp:28
unsigned short uint16
Definition juce_MathsFunctions.h:41
unsigned long long uint64
Definition juce_MathsFunctions.h:56
unsigned int uint32
Definition juce_MathsFunctions.h:45
signed short int16
Definition juce_MathsFunctions.h:39
long long int64
Definition juce_MathsFunctions.h:54
signed char int8
Definition juce_MathsFunctions.h:35
signed int int32
Definition juce_MathsFunctions.h:43
int pointer_sized_int
Definition juce_MathsFunctions.h:80
unsigned char uint8
Definition juce_MathsFunctions.h:37
static SystemStats::CrashHandlerFunction globalCrashHandler
Definition juce_SystemStats.cpp:187
static void handleCrash(int signum)
Definition juce_SystemStats.cpp:196
constexpr int numElementsInArray(Type(&)[N]) noexcept
Definition juce_MathsFunctions.h:344
#define false
Definition ordinals.h:83
Definition juce_SystemStats.cpp:81
bool hasAVX512VL
Definition juce_SystemStats.cpp:93
bool hasMMX
Definition juce_SystemStats.cpp:88
CPUInformation() noexcept
Definition juce_SystemStats.cpp:82
bool hasSSE3
Definition juce_SystemStats.cpp:88
void initialise() noexcept
Definition juce_linux_SystemStats.cpp:232
bool hasFMA3
Definition juce_SystemStats.cpp:89
int numLogicalCPUs
Definition juce_SystemStats.cpp:86
bool hasAVX512F
Definition juce_SystemStats.cpp:91
bool hasSSE
Definition juce_SystemStats.cpp:88
bool hasAVX512IFMA
Definition juce_SystemStats.cpp:92
bool hasAVX512PF
Definition juce_SystemStats.cpp:93
bool hasSSE41
Definition juce_SystemStats.cpp:90
bool hasAVX512ER
Definition juce_SystemStats.cpp:92
bool hasAVX512DQ
Definition juce_SystemStats.cpp:92
bool hasSSSE3
Definition juce_SystemStats.cpp:89
bool hasFMA4
Definition juce_SystemStats.cpp:89
bool hasAVX512VBMI
Definition juce_SystemStats.cpp:93
bool hasAVX512VPOPCNTDQ
Definition juce_SystemStats.cpp:94
bool hasAVX
Definition juce_SystemStats.cpp:90
bool hasSSE2
Definition juce_SystemStats.cpp:88
bool hasAVX512CD
Definition juce_SystemStats.cpp:91
bool has3DNow
Definition juce_SystemStats.cpp:89
bool hasAVX2
Definition juce_SystemStats.cpp:90
int numPhysicalCPUs
Definition juce_SystemStats.cpp:86
bool hasAVX512BW
Definition juce_SystemStats.cpp:91
bool hasSSE42
Definition juce_SystemStats.cpp:90
bool hasNeon
Definition juce_SystemStats.cpp:95
#define WINAPI
Definition swell-types.h:631
signed int LONG
Definition swell-types.h:182
void * HANDLE
Definition swell-types.h:212
void handler(int signal)
Definition fileio.c:1632
int result
Definition process.c:1455
int flag
Definition unix.c:754
typedef int(UZ_EXP MsgFn)()
#define TRUE
Definition unzpriv.h:1295
#define const
Definition zconf.h:137