24extern "C" int cobalt_thread_mode();
31static String getCpuInfo (
const char* key)
33 return readPosixConfigFileValue (
"/proc/cpuinfo", key);
36static String getLocaleValue (nl_item key)
38 auto oldLocale = ::setlocale (LC_ALL,
"");
40 ::setlocale (LC_ALL, oldLocale);
80 size_t machineDescriptionLength = 0;
81 auto result = sysctl (mib,
numElementsInArray (mib),
nullptr, &machineDescriptionLength,
nullptr, 0);
83 if (result != 0 || machineDescriptionLength == 0)
86 MemoryBlock machineDescription { machineDescriptionLength };
87 result = sysctl (mib,
numElementsInArray (mib), machineDescription.getData(), &machineDescriptionLength,
nullptr, 0);
88 return String::fromUTF8 (result == 0 ? (
char*) machineDescription.getData() :
"");
90 return getCpuInfo (
"Hardware");
104 auto v = getCpuInfo (
"vendor_id");
107 v = getCpuInfo (
"model name");
120 size_t modelLength = 0;
121 auto result = sysctl (mib,
numElementsInArray (mib),
nullptr, &modelLength,
nullptr, 0);
123 if (result != 0 || modelLength == 0)
127 result = sysctl (mib,
numElementsInArray (mib), model.getData(), &modelLength,
nullptr, 0);
130 return getCpuInfo (
"model name");
138 auto clockRateSize =
sizeof (clockRate);
139 auto result = sysctlbyname (
"hw.clockrate", &clockRate, &clockRateSize,
nullptr, 0);
140 return result == 0 ? clockRate : 0;
142 return roundToInt (getCpuInfo (
"cpu MHz").getFloatValue());
154 auto memorySize =
sizeof (memory);
155 auto result = sysctl (mib,
numElementsInArray (mib), &memory, &memorySize,
nullptr, 0);
156 return result == 0 ? (
int) (memory / (
int64) 1e6) : 0;
160 if (sysinfo (&sysi) == 0)
161 return (
int) (sysi.totalram * sysi.mem_unit / (1024 * 1024));
169 return (
int)
sysconf (_SC_PAGESIZE);
175 if (
auto user =
getenv (
"USER"))
202 if (
auto langEnv =
getenv (
"LANG"))
207 return getLocaleValue (_NL_ADDRESS_LANG_AB);
216 return getLocaleValue (_NL_ADDRESS_COUNTRY_AB2);
225 if (region.isNotEmpty())
226 result <<
"-" << region;
232void CPUInformation::initialise() noexcept
235 #if JUCE_INTEL && ! JUCE_NO_INLINE_ASM
236 SystemStatsHelpers::getCPUInfo (hasMMX,
260 numLogicalCPUs = numPhysicalCPUs = []
267 auto numCPUsSize =
sizeof (numCPUs);
268 auto result = sysctl (mib,
numElementsInArray (mib), &numCPUs, &numCPUsSize,
nullptr, 0);
269 return result == 0 ? numCPUs : 1;
272 auto flags = getCpuInfo (
"flags");
274 hasMMX = flags.contains (
"mmx");
275 hasFMA3 = flags.contains (
"fma");
276 hasFMA4 = flags.contains (
"fma4");
277 hasSSE = flags.contains (
"sse");
278 hasSSE2 = flags.contains (
"sse2");
279 hasSSE3 = flags.contains (
"sse3");
280 has3DNow = flags.contains (
"3dnow");
281 hasSSSE3 = flags.contains (
"ssse3");
282 hasSSE41 = flags.contains (
"sse4_1");
283 hasSSE42 = flags.contains (
"sse4_2");
284 hasAVX = flags.contains (
"avx");
285 hasAVX2 = flags.contains (
"avx2");
286 hasAVX512F = flags.contains (
"avx512f");
287 hasAVX512BW = flags.contains (
"avx512bw");
288 hasAVX512CD = flags.contains (
"avx512cd");
289 hasAVX512DQ = flags.contains (
"avx512dq");
290 hasAVX512ER = flags.contains (
"avx512er");
291 hasAVX512IFMA = flags.contains (
"avx512ifma");
292 hasAVX512PF = flags.contains (
"avx512pf");
293 hasAVX512VBMI = flags.contains (
"avx512vbmi");
294 hasAVX512VL = flags.contains (
"avx512vl");
295 hasAVX512VPOPCNTDQ = flags.contains (
"avx512_vpopcntdq");
297 numLogicalCPUs = getCpuInfo (
"processor").
getIntValue() + 1;
300 numPhysicalCPUs = getCpuInfo (
"cpu cores").
getIntValue() * (getCpuInfo (
"physical id").
getIntValue() + 1);
302 if (numPhysicalCPUs <= 0)
303 numPhysicalCPUs = numLogicalCPUs;
309 static const auto deviceId = []()
311 const auto call = [] (
auto command) ->
String
315 if (proc.
start (command, ChildProcess::wantStdOut))
321 auto data = call (
"cat /sys/class/dmi/id/board_serial");
326 data = call (
"cat /sys/class/dmi/id/bios_date")
327 + call (
"cat /sys/class/dmi/id/bios_release")
328 + call (
"cat /sys/class/dmi/id/bios_vendor")
329 + call (
"cat /sys/class/dmi/id/bios_version");
332 auto cpuData = call (
"lscpu");
334 if (cpuData.isNotEmpty())
336 auto getCpuInfo = [&cpuData] (
auto key) ->
String
338 auto index = cpuData.
indexOf (key);
342 auto start = cpuData.indexOf (index,
":");
343 auto end = cpuData.indexOf (start,
"\n");
345 return cpuData.substring (start + 1,
end).trim();
351 data += getCpuInfo (
"CPU family:");
352 data += getCpuInfo (
"Model:");
353 data += getCpuInfo (
"Model name:");
354 data += getCpuInfo (
"Vendor ID:");
361 jassert (deviceId.isNotEmpty());
366uint32 juce_millisecondsSinceStartup() noexcept
376 if (cobalt_thread_mode() == 0x200 )
379 __wrap_clock_gettime (CLOCK_MONOTONIC, &t);
384 return (t.tv_sec * (
int64) 1000000) + (t.tv_nsec / 1000);
400 t.tv_sec =
decltype (timeval::tv_sec) (millisSinceEpoch / 1000);
401 t.tv_usec =
decltype (timeval::tv_usec) ((millisSinceEpoch - t.tv_sec * 1000) * 1000);
403 return settimeofday (&t,
nullptr) == 0;
416 struct kinfo_proc info;
417 auto infoSize =
sizeof (info);
419 return result == 0 ? ((info.ki_flag & P_TRACED) != 0) :
false;
421 return readPosixConfigFileValue (
"/proc/self/status",
"TracerPid").getIntValue() > 0;
Launches and monitors a child process.
String readAllProcessOutput()
Blocks until the process has finished, and then returns its complete output as a string.
bool start(const String &command, int streamFlags=wantStdOut|wantStdErr)
Attempts to launch a child process command.
static void JUCE_CALLTYPE outputDebugString(const String &text)
Writes a message to the standard error stream.
A class to hold a resizable block of raw data.
int indexOf(StringRef textToLookFor) const noexcept
Searches for a substring within this string.
String upToLastOccurrenceOf(StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
Returns the start of this string, up to the last occurrence of a substring.
static String fromUTF8(const char *utf8buffer, int bufferSizeBytes=-1)
Creates a String from a UTF-8 encoded buffer.
int getIntValue() const noexcept
Reads the value of the string as a decimal number (up to 32 bits in size).
static String getUniqueDeviceID()
This method returns a machine unique ID unaffected by storage or peripheral changes.
static int getPageSize()
Returns the system page-size.
static String getOperatingSystemName()
Returns the name of the type of operating system we're running on.
static String getUserRegion()
Returns the region of the user's locale.
static String getDeviceDescription()
This will attempt to return some kind of string describing the device.
static String getLogonName()
Returns the current user's name, if available.
static String getUserLanguage()
Returns the language of the user's locale.
static String getDeviceManufacturer()
This will attempt to return the manufacturer of the device.
static bool isOperatingSystem64Bit()
Returns true if the OS is 64-bit, or false for a 32-bit OS.
OperatingSystemType
The set of possible results of the getOperatingSystemType() method.
static String getComputerName()
Returns the host-name of the computer.
static OperatingSystemType getOperatingSystemType()
Returns the type of operating system we're running on.
static String getCpuModel()
Attempts to return a string describing the CPU model.
static int getCpuSpeedInMegahertz()
Returns the approximate CPU speed.
static String getCpuVendor()
Returns a string to indicate the CPU vendor.
static String getFullUserName()
Returns the current user's full name, if available.
static int getMemorySizeInMegabytes()
Finds out how much RAM is in the machine.
static String getDisplayLanguage()
Returns the user's display language.
static double getMillisecondCounterHiRes() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
static int64 getHighResolutionTicksPerSecond() noexcept
Returns the resolution of the high-resolution counter in ticks per second.
bool setSystemTimeToThisTime() const
Tries to set the computer's clock.
static int64 getHighResolutionTicks() noexcept
Returns the current high-resolution counter's tick-count.
bool juce_isRunningUnderDebugger() noexcept
< This macro is added to all JUCE public class declarations.
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Returns a default-constructed sentinel value.
signed int int32
A platform-independent 32-bit signed integer type.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
long long int64
A platform-independent 64-bit integer type.