Add remaining files
[juce-lv2.git] / juce / source / src / native / linux / juce_linux_SystemStats.cpp
blob469399912327104197f0d2a808ec2b499ee20290
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 // (This file gets included by juce_linux_NativeCode.cpp, rather than being
27 // compiled on its own).
28 #if JUCE_INCLUDED_FILE
31 //==============================================================================
32 void Logger::outputDebugString (const String& text)
34 std::cerr << text << std::endl;
37 //==============================================================================
38 SystemStats::OperatingSystemType SystemStats::getOperatingSystemType()
40 return Linux;
43 String SystemStats::getOperatingSystemName()
45 return "Linux";
48 bool SystemStats::isOperatingSystem64Bit()
50 #if JUCE_64BIT
51 return true;
52 #else
53 //xxx not sure how to find this out?..
54 return false;
55 #endif
58 //==============================================================================
59 namespace LinuxStatsHelpers
61 String getCpuInfo (const char* const key)
63 StringArray lines;
64 lines.addLines (File ("/proc/cpuinfo").loadFileAsString());
66 for (int i = lines.size(); --i >= 0;) // (NB - it's important that this runs in reverse order)
67 if (lines[i].startsWithIgnoreCase (key))
68 return lines[i].fromFirstOccurrenceOf (":", false, false).trim();
70 return String::empty;
74 String SystemStats::getCpuVendor()
76 return LinuxStatsHelpers::getCpuInfo ("vendor_id");
79 int SystemStats::getCpuSpeedInMegaherz()
81 return roundToInt (LinuxStatsHelpers::getCpuInfo ("cpu MHz").getFloatValue());
84 int SystemStats::getMemorySizeInMegabytes()
86 struct sysinfo sysi;
88 if (sysinfo (&sysi) == 0)
89 return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
91 return 0;
94 int SystemStats::getPageSize()
96 return sysconf (_SC_PAGESIZE);
99 //==============================================================================
100 String SystemStats::getLogonName()
102 const char* user = getenv ("USER");
104 if (user == nullptr)
106 struct passwd* const pw = getpwuid (getuid());
107 if (pw != nullptr)
108 user = pw->pw_name;
111 return CharPointer_UTF8 (user);
114 String SystemStats::getFullUserName()
116 return getLogonName();
119 String SystemStats::getComputerName()
121 char name [256] = { 0 };
122 if (gethostname (name, sizeof (name) - 1) == 0)
123 return name;
125 return String::empty;
128 //==============================================================================
129 SystemStats::CPUFlags::CPUFlags()
131 const String flags (LinuxStatsHelpers::getCpuInfo ("flags"));
132 hasMMX = flags.contains ("mmx");
133 hasSSE = flags.contains ("sse");
134 hasSSE2 = flags.contains ("sse2");
135 has3DNow = flags.contains ("3dnow");
137 numCpus = LinuxStatsHelpers::getCpuInfo ("processor").getIntValue() + 1;
140 void PlatformUtilities::fpuReset()
144 //==============================================================================
145 uint32 juce_millisecondsSinceStartup() noexcept
147 timespec t;
148 clock_gettime (CLOCK_MONOTONIC, &t);
150 return t.tv_sec * 1000 + t.tv_nsec / 1000000;
153 int64 Time::getHighResolutionTicks() noexcept
155 timespec t;
156 clock_gettime (CLOCK_MONOTONIC, &t);
158 return (t.tv_sec * (int64) 1000000) + (t.tv_nsec / 1000);
161 int64 Time::getHighResolutionTicksPerSecond() noexcept
163 return 1000000; // (microseconds)
166 double Time::getMillisecondCounterHiRes() noexcept
168 return getHighResolutionTicks() * 0.001;
171 bool Time::setSystemTimeToThisTime() const
173 timeval t;
174 t.tv_sec = millisSinceEpoch / 1000;
175 t.tv_usec = (millisSinceEpoch - t.tv_sec * 1000) * 1000;
177 return settimeofday (&t, 0) == 0;
181 #endif