The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include "linuxincludes.h"
  24. #include "../../../src/juce_core/basics/juce_StandardHeader.h"
  25. #include <sys/sysinfo.h>
  26. #include <dlfcn.h>
  27. #ifndef CPU_ISSET
  28. #undef SUPPORT_AFFINITIES
  29. #endif
  30. BEGIN_JUCE_NAMESPACE
  31. #include "../../../src/juce_core/io/files/juce_File.h"
  32. #include "../../../src/juce_core/basics/juce_SystemStats.h"
  33. #include "../../../src/juce_core/threads/juce_Process.h"
  34. #include "../../../src/juce_appframework/events/juce_Timer.h"
  35. #include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
  36. //==============================================================================
  37. /*static juce_noinline unsigned int getCPUIDWord (int* familyModel, int* extFeatures) throw()
  38. {
  39. unsigned int cpu = 0;
  40. unsigned int ext = 0;
  41. unsigned int family = 0;
  42. unsigned int dummy = 0;
  43. #if JUCE_64BIT
  44. __asm__ ("cpuid"
  45. : "=a" (family), "=b" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  46. #else
  47. __asm__ ("push %%ebx; cpuid; mov %%ebx, %%edi; pop %%ebx"
  48. : "=a" (family), "=D" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  49. #endif
  50. if (familyModel != 0)
  51. *familyModel = family;
  52. if (extFeatures != 0)
  53. *extFeatures = ext;
  54. return cpu;
  55. }*/
  56. //==============================================================================
  57. void Logger::outputDebugString (const String& text) throw()
  58. {
  59. fprintf (stdout, text.toUTF8());
  60. fprintf (stdout, "\n");
  61. }
  62. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  63. {
  64. String text;
  65. va_list args;
  66. va_start (args, format);
  67. text.vprintf(format, args);
  68. outputDebugString(text);
  69. }
  70. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  71. {
  72. return Linux;
  73. }
  74. const String SystemStats::getOperatingSystemName() throw()
  75. {
  76. return T("Linux");
  77. }
  78. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  79. {
  80. String info;
  81. char buf [256];
  82. FILE* f = fopen ("/proc/cpuinfo", "r");
  83. while (f != 0 && fgets (buf, sizeof(buf), f))
  84. {
  85. if (strncmp (buf, key, strlen (key)) == 0)
  86. {
  87. char* p = buf;
  88. while (*p && *p != '\n')
  89. ++p;
  90. if (*p != 0)
  91. *p = 0;
  92. p = buf;
  93. while (*p != 0 && *p != ':')
  94. ++p;
  95. if (*p != 0 && *(p + 1) != 0)
  96. info = p + 2;
  97. if (! lastOne)
  98. break;
  99. }
  100. }
  101. fclose (f);
  102. return info;
  103. }
  104. bool SystemStats::hasMMX() throw()
  105. {
  106. return getCpuInfo ("flags").contains (T("mmx"));
  107. }
  108. bool SystemStats::hasSSE() throw()
  109. {
  110. return getCpuInfo ("flags").contains (T("sse"));
  111. }
  112. bool SystemStats::hasSSE2() throw()
  113. {
  114. return getCpuInfo ("flags").contains (T("sse2"));
  115. }
  116. bool SystemStats::has3DNow() throw()
  117. {
  118. return getCpuInfo ("flags").contains (T("3dnow"));
  119. }
  120. const String SystemStats::getCpuVendor() throw()
  121. {
  122. return getCpuInfo ("vendor_id");
  123. }
  124. int SystemStats::getCpuSpeedInMegaherz() throw()
  125. {
  126. const String speed (getCpuInfo ("cpu MHz"));
  127. return (int) (speed.getFloatValue() + 0.5f);
  128. }
  129. int SystemStats::getMemorySizeInMegabytes() throw()
  130. {
  131. struct sysinfo sysi;
  132. if (sysinfo (&sysi) == 0)
  133. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  134. return 0;
  135. }
  136. uint32 juce_millisecondsSinceStartup() throw()
  137. {
  138. static unsigned int calibrate = 0;
  139. static bool calibrated = false;
  140. timeval t;
  141. unsigned int ret = 0;
  142. if (! gettimeofday (&t, 0))
  143. {
  144. if (! calibrated)
  145. {
  146. struct sysinfo sysi;
  147. if (sysinfo (&sysi) == 0)
  148. // Safe to assume system was not brought up earlier than 1970!
  149. calibrate = t.tv_sec - sysi.uptime;
  150. calibrated = true;
  151. }
  152. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  153. }
  154. return ret;
  155. }
  156. double Time::getMillisecondCounterHiRes() throw()
  157. {
  158. return getHighResolutionTicks() * 0.001;
  159. }
  160. int64 Time::getHighResolutionTicks() throw()
  161. {
  162. timeval t;
  163. if (gettimeofday (&t, 0))
  164. return 0;
  165. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  166. }
  167. int64 Time::getHighResolutionTicksPerSecond() throw()
  168. {
  169. // Microseconds
  170. return 1000000;
  171. }
  172. bool Time::setSystemTimeToThisTime() const throw()
  173. {
  174. timeval t;
  175. t.tv_sec = millisSinceEpoch % 1000000;
  176. t.tv_usec = millisSinceEpoch - t.tv_sec;
  177. return settimeofday (&t, NULL) ? false : true;
  178. }
  179. int SystemStats::getPageSize() throw()
  180. {
  181. static int systemPageSize = 0;
  182. if (systemPageSize == 0)
  183. systemPageSize = sysconf (_SC_PAGESIZE);
  184. return systemPageSize;
  185. }
  186. int SystemStats::getNumCpus() throw()
  187. {
  188. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  189. return lastCpu + 1;
  190. }
  191. //==============================================================================
  192. void SystemStats::initialiseStats() throw()
  193. {
  194. // Process starts off as root when running suid
  195. Process::lowerPrivilege();
  196. String s (SystemStats::getJUCEVersion());
  197. }
  198. void PlatformUtilities::fpuReset()
  199. {
  200. }
  201. END_JUCE_NAMESPACE