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.

278 lines
6.7KB

  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. bool SystemStats::isOperatingSystem64Bit() throw()
  79. {
  80. #if JUCE_64BIT
  81. return true;
  82. #else
  83. //xxx not sure how to find this out?..
  84. return false;
  85. #endif
  86. }
  87. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  88. {
  89. String info;
  90. char buf [256];
  91. FILE* f = fopen ("/proc/cpuinfo", "r");
  92. while (f != 0 && fgets (buf, sizeof(buf), f))
  93. {
  94. if (strncmp (buf, key, strlen (key)) == 0)
  95. {
  96. char* p = buf;
  97. while (*p && *p != '\n')
  98. ++p;
  99. if (*p != 0)
  100. *p = 0;
  101. p = buf;
  102. while (*p != 0 && *p != ':')
  103. ++p;
  104. if (*p != 0 && *(p + 1) != 0)
  105. info = p + 2;
  106. if (! lastOne)
  107. break;
  108. }
  109. }
  110. fclose (f);
  111. return info;
  112. }
  113. bool SystemStats::hasMMX() throw()
  114. {
  115. return getCpuInfo ("flags").contains (T("mmx"));
  116. }
  117. bool SystemStats::hasSSE() throw()
  118. {
  119. return getCpuInfo ("flags").contains (T("sse"));
  120. }
  121. bool SystemStats::hasSSE2() throw()
  122. {
  123. return getCpuInfo ("flags").contains (T("sse2"));
  124. }
  125. bool SystemStats::has3DNow() throw()
  126. {
  127. return getCpuInfo ("flags").contains (T("3dnow"));
  128. }
  129. const String SystemStats::getCpuVendor() throw()
  130. {
  131. return getCpuInfo ("vendor_id");
  132. }
  133. int SystemStats::getCpuSpeedInMegaherz() throw()
  134. {
  135. const String speed (getCpuInfo ("cpu MHz"));
  136. return (int) (speed.getFloatValue() + 0.5f);
  137. }
  138. int SystemStats::getMemorySizeInMegabytes() throw()
  139. {
  140. struct sysinfo sysi;
  141. if (sysinfo (&sysi) == 0)
  142. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  143. return 0;
  144. }
  145. uint32 juce_millisecondsSinceStartup() throw()
  146. {
  147. static unsigned int calibrate = 0;
  148. static bool calibrated = false;
  149. timeval t;
  150. unsigned int ret = 0;
  151. if (! gettimeofday (&t, 0))
  152. {
  153. if (! calibrated)
  154. {
  155. struct sysinfo sysi;
  156. if (sysinfo (&sysi) == 0)
  157. // Safe to assume system was not brought up earlier than 1970!
  158. calibrate = t.tv_sec - sysi.uptime;
  159. calibrated = true;
  160. }
  161. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  162. }
  163. return ret;
  164. }
  165. double Time::getMillisecondCounterHiRes() throw()
  166. {
  167. return getHighResolutionTicks() * 0.001;
  168. }
  169. int64 Time::getHighResolutionTicks() throw()
  170. {
  171. timeval t;
  172. if (gettimeofday (&t, 0))
  173. return 0;
  174. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  175. }
  176. int64 Time::getHighResolutionTicksPerSecond() throw()
  177. {
  178. // Microseconds
  179. return 1000000;
  180. }
  181. bool Time::setSystemTimeToThisTime() const throw()
  182. {
  183. timeval t;
  184. t.tv_sec = millisSinceEpoch % 1000000;
  185. t.tv_usec = millisSinceEpoch - t.tv_sec;
  186. return settimeofday (&t, NULL) ? false : true;
  187. }
  188. int SystemStats::getPageSize() throw()
  189. {
  190. static int systemPageSize = 0;
  191. if (systemPageSize == 0)
  192. systemPageSize = sysconf (_SC_PAGESIZE);
  193. return systemPageSize;
  194. }
  195. int SystemStats::getNumCpus() throw()
  196. {
  197. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  198. return lastCpu + 1;
  199. }
  200. //==============================================================================
  201. void SystemStats::initialiseStats() throw()
  202. {
  203. // Process starts off as root when running suid
  204. Process::lowerPrivilege();
  205. String s (SystemStats::getJUCEVersion());
  206. }
  207. void PlatformUtilities::fpuReset()
  208. {
  209. }
  210. END_JUCE_NAMESPACE