benchmark-1.5.0.patch 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. diff -N -a -u -r benchmark-1.5.0.orig/src/benchmark.cc benchmark-1.5.0/src/benchmark.cc
  2. --- benchmark-1.5.0.orig/src/benchmark.cc 2019-05-13 14:42:18.000000000 -0500
  3. +++ benchmark-1.5.0/src/benchmark.cc 2020-10-14 22:05:36.383669200 -0500
  4. @@ -18,7 +18,7 @@
  5. #include "internal_macros.h"
  6. #ifndef BENCHMARK_OS_WINDOWS
  7. -#ifndef BENCHMARK_OS_FUCHSIA
  8. +#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_SYS_RESOURCE_H_UNSUPPORTED)
  9. #include <sys/resource.h>
  10. #endif
  11. #include <sys/time.h>
  12. diff -N -a -u -r benchmark-1.5.0.orig/src/benchmark_register.cc benchmark-1.5.0/src/benchmark_register.cc
  13. --- benchmark-1.5.0.orig/src/benchmark_register.cc 2019-05-13 14:42:18.000000000 -0500
  14. +++ benchmark-1.5.0/src/benchmark_register.cc 2020-10-14 22:06:56.901076900 -0500
  15. @@ -15,7 +15,7 @@
  16. #include "benchmark_register.h"
  17. #ifndef BENCHMARK_OS_WINDOWS
  18. -#ifndef BENCHMARK_OS_FUCHSIA
  19. +#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_SYS_RESOURCE_H_UNSUPPORTED)
  20. #include <sys/resource.h>
  21. #endif
  22. #include <sys/time.h>
  23. diff -N -a -u -r benchmark-1.5.0.orig/src/benchmark_runner.cc benchmark-1.5.0/src/benchmark_runner.cc
  24. --- benchmark-1.5.0.orig/src/benchmark_runner.cc 2019-05-13 14:42:18.000000000 -0500
  25. +++ benchmark-1.5.0/src/benchmark_runner.cc 2020-10-14 22:07:01.282622200 -0500
  26. @@ -18,7 +18,7 @@
  27. #include "internal_macros.h"
  28. #ifndef BENCHMARK_OS_WINDOWS
  29. -#ifndef BENCHMARK_OS_FUCHSIA
  30. +#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_SYS_RESOURCE_H_UNSUPPORTED)
  31. #include <sys/resource.h>
  32. #endif
  33. #include <sys/time.h>
  34. diff -N -a -u -r benchmark-1.5.0.orig/src/colorprint.cc benchmark-1.5.0/src/colorprint.cc
  35. --- benchmark-1.5.0.orig/src/colorprint.cc 2019-05-13 14:42:18.000000000 -0500
  36. +++ benchmark-1.5.0/src/colorprint.cc 2020-10-14 22:07:43.727853800 -0500
  37. @@ -33,14 +33,14 @@
  38. namespace benchmark {
  39. namespace {
  40. -#ifdef BENCHMARK_OS_WINDOWS
  41. +#if defined(BENCHMARK_OS_WINDOWS) && !defined(BENCHMARK_USE_ANSI_COLOR_MODE)
  42. typedef WORD PlatformColorCode;
  43. #else
  44. typedef const char* PlatformColorCode;
  45. #endif
  46. PlatformColorCode GetPlatformColorCode(LogColor color) {
  47. -#ifdef BENCHMARK_OS_WINDOWS
  48. +#if defined(BENCHMARK_OS_WINDOWS) && !defined(BENCHMARK_USE_ANSI_COLOR_MODE)
  49. switch (color) {
  50. case COLOR_RED:
  51. return FOREGROUND_RED;
  52. @@ -127,7 +127,7 @@
  53. void ColorPrintf(std::ostream& out, LogColor color, const char* fmt,
  54. va_list args) {
  55. -#ifdef BENCHMARK_OS_WINDOWS
  56. +#if defined(BENCHMARK_OS_WINDOWS) && !defined(BENCHMARK_USE_ANSI_COLOR_MODE)
  57. ((void)out); // suppress unused warning
  58. const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
  59. diff -N -a -u -r benchmark-1.5.0.orig/src/commandlineflags.cc benchmark-1.5.0/src/commandlineflags.cc
  60. --- benchmark-1.5.0.orig/src/commandlineflags.cc 2019-05-13 14:42:18.000000000 -0500
  61. +++ benchmark-1.5.0/src/commandlineflags.cc 2020-10-14 22:09:39.353104100 -0500
  62. @@ -13,7 +13,7 @@
  63. // limitations under the License.
  64. #include "commandlineflags.h"
  65. -
  66. +#include "internal_macros.h"
  67. #include <cctype>
  68. #include <cstdlib>
  69. #include <cstring>
  70. diff -N -a -u -r benchmark-1.5.0.orig/src/internal_macros.h benchmark-1.5.0/src/internal_macros.h
  71. --- benchmark-1.5.0.orig/src/internal_macros.h 2019-05-13 14:42:18.000000000 -0500
  72. +++ benchmark-1.5.0/src/internal_macros.h 2020-10-14 22:09:41.520871700 -0500
  73. @@ -89,6 +89,17 @@
  74. #define BENCHMARK_MAYBE_UNUSED
  75. #endif
  76. +#ifdef BENCHMARK_ISATTY_UNSUPPORTED
  77. +inline int isatty(int) {
  78. + return 0;
  79. +}
  80. +#endif
  81. +
  82. +#ifdef BENCHMARK_GETENV_UNSUPPORTED
  83. +inline const char* getenv(const char*) {
  84. + return nullptr;
  85. +}
  86. +#endif
  87. // clang-format on
  88. #endif // BENCHMARK_INTERNAL_MACROS_H_
  89. diff -N -a -u -r benchmark-1.5.0.orig/src/sysinfo.cc benchmark-1.5.0/src/sysinfo.cc
  90. --- benchmark-1.5.0.orig/src/sysinfo.cc 2019-05-13 14:42:18.000000000 -0500
  91. +++ benchmark-1.5.0/src/sysinfo.cc 2020-10-14 22:56:44.702431200 -0500
  92. @@ -22,14 +22,14 @@
  93. #include <codecvt>
  94. #else
  95. #include <fcntl.h>
  96. -#ifndef BENCHMARK_OS_FUCHSIA
  97. +#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_SYS_RESOURCE_H_UNSUPPORTED)
  98. #include <sys/resource.h>
  99. #endif
  100. #include <sys/time.h>
  101. #include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
  102. #include <unistd.h>
  103. -#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || \
  104. - defined BENCHMARK_OS_NETBSD || defined BENCHMARK_OS_OPENBSD
  105. +#if (defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || \
  106. + defined BENCHMARK_OS_NETBSD || defined BENCHMARK_OS_OPENBSD) && !defined(BENCHMARK_SYS_SYSCTL_H_UNSUPPORTED)
  107. #define BENCHMARK_HAS_SYSCTL
  108. #include <sys/sysctl.h>
  109. #endif
  110. @@ -316,6 +316,7 @@
  111. #elif defined(BENCHMARK_OS_WINDOWS)
  112. std::vector<CPUInfo::CacheInfo> GetCacheSizesWindows() {
  113. std::vector<CPUInfo::CacheInfo> res;
  114. +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY != WINAPI_FAMILY_TV_TITLE
  115. DWORD buffer_size = 0;
  116. using PInfo = SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  117. using CInfo = CACHE_DESCRIPTOR;
  118. @@ -360,6 +361,7 @@
  119. }
  120. res.push_back(C);
  121. }
  122. +#endif
  123. return res;
  124. }
  125. #elif BENCHMARK_OS_QNX
  126. @@ -411,7 +413,9 @@
  127. }
  128. std::string GetSystemName() {
  129. -#if defined(BENCHMARK_OS_WINDOWS)
  130. +#if defined(BENCHMARK_SYSTEM_NAME)
  131. + return { BENCHMARK_SYSTEM_NAME };
  132. +#elif defined(BENCHMARK_OS_WINDOWS)
  133. std::string str;
  134. const unsigned COUNT = MAX_COMPUTERNAME_LENGTH+1;
  135. TCHAR hostname[COUNT] = {'\0'};
  136. @@ -434,10 +438,14 @@
  137. #elif defined(BENCHMARK_OS_QNX)
  138. #define HOST_NAME_MAX 154
  139. #endif
  140. +#if !defined(BENCHMARK_SYS_SYSCTL_H_UNSUPPORTED)
  141. char hostname[HOST_NAME_MAX];
  142. int retVal = gethostname(hostname, HOST_NAME_MAX);
  143. if (retVal != 0) return std::string("");
  144. return std::string(hostname);
  145. +#else
  146. + return {};
  147. +#endif
  148. #endif // Catch-all POSIX block.
  149. }
  150. @@ -610,11 +618,15 @@
  151. // In NT, read MHz from the registry. If we fail to do so or we're in win9x
  152. // then make a crude estimate.
  153. DWORD data, data_size = sizeof(data);
  154. +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY != WINAPI_FAMILY_TV_TITLE
  155. if (IsWindowsXPOrGreater() &&
  156. SUCCEEDED(
  157. SHGetValueA(HKEY_LOCAL_MACHINE,
  158. "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
  159. "~MHz", nullptr, &data, &data_size)))
  160. +#else
  161. + data = 1600; // Windows applications with WINAPI family of TV Title has a cpu frequency clock rate of 1.6Ghz according to documentation
  162. +#endif
  163. return static_cast<double>((int64_t)data *
  164. (int64_t)(1000 * 1000)); // was mhz
  165. #elif defined (BENCHMARK_OS_SOLARIS)
  166. @@ -660,7 +672,7 @@
  167. std::vector<double> GetLoadAvg() {
  168. #if (defined BENCHMARK_OS_FREEBSD || defined(BENCHMARK_OS_LINUX) || \
  169. defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD || \
  170. - defined BENCHMARK_OS_OPENBSD) && !defined(__ANDROID__)
  171. + defined BENCHMARK_OS_OPENBSD) && !defined(__ANDROID__) && !defined(BENCHMARK_SYS_SYSCTL_H_UNSUPPORTED)
  172. constexpr int kMaxSamples = 3;
  173. std::vector<double> res(kMaxSamples, 0.0);
  174. const int nelem = getloadavg(res.data(), kMaxSamples);
  175. diff -N -a -u -r benchmark-1.5.0.orig/src/timers.cc benchmark-1.5.0/src/timers.cc
  176. --- benchmark-1.5.0.orig/src/timers.cc 2019-05-13 14:42:18.000000000 -0500
  177. +++ benchmark-1.5.0/src/timers.cc 2020-10-14 22:19:18.569818000 -0500
  178. @@ -22,13 +22,13 @@
  179. #include <windows.h>
  180. #else
  181. #include <fcntl.h>
  182. -#ifndef BENCHMARK_OS_FUCHSIA
  183. +#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_SYS_RESOURCE_H_UNSUPPORTED)
  184. #include <sys/resource.h>
  185. #endif
  186. #include <sys/time.h>
  187. #include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
  188. #include <unistd.h>
  189. -#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX
  190. +#if (defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX) && !defined(BENCHMARK_SYS_SYSCTL_H_UNSUPPORTED)
  191. #include <sys/sysctl.h>
  192. #endif
  193. #if defined(BENCHMARK_OS_MACOSX)
  194. @@ -77,7 +77,7 @@
  195. static_cast<double>(user.QuadPart)) *
  196. 1e-7;
  197. }
  198. -#elif !defined(BENCHMARK_OS_FUCHSIA)
  199. +#elif !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_TIME_S_SUPPORTED)
  200. double MakeTime(struct rusage const& ru) {
  201. return (static_cast<double>(ru.ru_utime.tv_sec) +
  202. static_cast<double>(ru.ru_utime.tv_usec) * 1e-6 +
  203. @@ -130,6 +130,11 @@
  204. if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0)
  205. return MakeTime(spec);
  206. DiagnoseAndExit("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) failed");
  207. +#elif defined(CLOCK_THREAD_CPUTIME_ID)
  208. + struct timespec spec;
  209. + if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &spec) == 0)
  210. + return MakeTime(spec);
  211. + DiagnoseAndExit("clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...) failed");
  212. #else
  213. struct rusage ru;
  214. if (getrusage(RUSAGE_SELF, &ru) == 0) return MakeTime(ru);
  215. @@ -193,7 +198,11 @@
  216. std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
  217. #else
  218. std::tm timeinfo;
  219. +#if defined(BENCHMARK_TIME_S_SUPPORTED)
  220. + ::localtime_s(&now, &timeinfo);
  221. +#else
  222. ::localtime_r(&now, &timeinfo);
  223. +#endif
  224. written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
  225. #endif
  226. } else {
  227. @@ -201,7 +210,11 @@
  228. written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
  229. #else
  230. std::tm timeinfo;
  231. +#if defined(BENCHMARK_TIME_S_SUPPORTED)
  232. + ::gmtime_s(&now, &timeinfo);
  233. +#else
  234. ::gmtime_r(&now, &timeinfo);
  235. +#endif
  236. written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
  237. #endif
  238. }