mirror of
https://github.com/google/benchmark.git
synced 2025-01-30 13:50:15 +08:00
Renamed the internal os macros to avoid a name clash in Shlwapi.h where OS_WINDOWS is defined to 0.
This commit is contained in:
parent
02440964e8
commit
ba141ac0d9
@ -15,7 +15,7 @@
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "commandlineflags.h"
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
@ -27,14 +27,14 @@ DECLARE_bool(color_print);
|
||||
|
||||
namespace benchmark {
|
||||
namespace {
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
typedef WORD PlatformColorCode;
|
||||
#else
|
||||
typedef const char* PlatformColorCode;
|
||||
#endif
|
||||
|
||||
PlatformColorCode GetPlatformColorCode(LogColor color) {
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
switch (color) {
|
||||
case COLOR_RED:
|
||||
return FOREGROUND_RED;
|
||||
@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
// Gets the current text color.
|
||||
|
@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
|
||||
#pragma intrinsic(__rdtsc)
|
||||
#endif
|
||||
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
@ -16,17 +16,17 @@
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
# define OS_CYGWIN 1
|
||||
# define BENCHMARK_OS_CYGWIN 1
|
||||
#elif defined(_WIN32)
|
||||
# define OS_WINDOWS 1
|
||||
# define BENCHMARK_OS_WINDOWS 1
|
||||
#elif defined(__APPLE__)
|
||||
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
|
||||
// that it is an apple system.
|
||||
# define OS_MACOSX 1
|
||||
# define BENCHMARK_OS_MACOSX 1
|
||||
#elif defined(__FreeBSD__)
|
||||
# define OS_FREEBSD 1
|
||||
# define BENCHMARK_OS_FREEBSD 1
|
||||
#elif defined(__linux__)
|
||||
# define OS_LINUX 1
|
||||
# define BENCHMARK_OS_LINUX 1
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
|
@ -19,12 +19,12 @@
|
||||
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
namespace benchmark {
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
// Window's Sleep takes milliseconds argument.
|
||||
void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
|
||||
void SleepForSeconds(double seconds) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "sysinfo.h"
|
||||
#include "internal_macros.h"
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
#ifdef BENCHMARK_OS_WINDOWS
|
||||
#include <Shlwapi.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
@ -51,7 +51,7 @@ double cpuinfo_cycles_per_second = 1.0;
|
||||
int cpuinfo_num_cpus = 1; // Conservative guess
|
||||
std::mutex cputimens_mutex;
|
||||
|
||||
#if !defined OS_MACOSX
|
||||
#if !defined BENCHMARK_OS_MACOSX
|
||||
const int64_t estimate_time_ms = 1000;
|
||||
|
||||
// Helper function estimates cycles/sec by observing cycles elapsed during
|
||||
@ -63,7 +63,7 @@ int64_t EstimateCyclesPerSecond() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined OS_LINUX || defined OS_CYGWIN
|
||||
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
|
||||
// Helper function for reading an int from a file. Returns true if successful
|
||||
// and the memory location pointed to by value is set to the value read.
|
||||
bool ReadIntFromFile(const char* file, long* value) {
|
||||
@ -86,7 +86,7 @@ bool ReadIntFromFile(const char* file, long* value) {
|
||||
#endif
|
||||
|
||||
void InitializeSystemInfo() {
|
||||
#if defined OS_LINUX || defined OS_CYGWIN
|
||||
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
|
||||
char line[1024];
|
||||
char* err;
|
||||
long freq;
|
||||
@ -204,7 +204,7 @@ void InitializeSystemInfo() {
|
||||
cpuinfo_num_cpus = num_cpus;
|
||||
}
|
||||
|
||||
#elif defined OS_FREEBSD
|
||||
#elif defined BENCHMARK_OS_FREEBSD
|
||||
// For this sysctl to work, the machine must be configured without
|
||||
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
|
||||
// and later. Before that, it's a 32-bit quantity (and gives the
|
||||
@ -232,7 +232,7 @@ void InitializeSystemInfo() {
|
||||
}
|
||||
// TODO: also figure out cpuinfo_num_cpus
|
||||
|
||||
#elif defined OS_WINDOWS
|
||||
#elif defined BENCHMARK_OS_WINDOWS
|
||||
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
|
||||
// then make a crude estimate.
|
||||
OSVERSIONINFO os;
|
||||
@ -248,7 +248,7 @@ void InitializeSystemInfo() {
|
||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||
// TODO: also figure out cpuinfo_num_cpus
|
||||
|
||||
#elif defined OS_MACOSX
|
||||
#elif defined BENCHMARK_OS_MACOSX
|
||||
// returning "mach time units" per second. the current number of elapsed
|
||||
// mach time units can be found by calling uint64 mach_absolute_time();
|
||||
// while not as precise as actual CPU cycles, it is accurate in the face
|
||||
@ -281,7 +281,7 @@ void InitializeSystemInfo() {
|
||||
|
||||
// getrusage() based implementation of MyCPUUsage
|
||||
static double MyCPUUsageRUsage() {
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
struct rusage ru;
|
||||
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
||||
return (static_cast<double>(ru.ru_utime.tv_sec) +
|
||||
@ -309,7 +309,7 @@ static double MyCPUUsageRUsage() {
|
||||
#endif // OS_WINDOWS
|
||||
}
|
||||
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
|
||||
static int cputime_fd = -1;
|
||||
if (cputime_fd == -1) {
|
||||
@ -338,7 +338,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
|
||||
#endif // OS_WINDOWS
|
||||
|
||||
double MyCPUUsage() {
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
{
|
||||
std::lock_guard<std::mutex> l(cputimens_mutex);
|
||||
static bool use_cputime_ns = true;
|
||||
@ -357,7 +357,7 @@ double MyCPUUsage() {
|
||||
}
|
||||
|
||||
double ChildrenCPUUsage() {
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
struct rusage ru;
|
||||
if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
|
||||
return (static_cast<double>(ru.ru_utime.tv_sec) +
|
||||
@ -394,7 +394,7 @@ int NumCPUs(void) {
|
||||
: nullptr)
|
||||
|
||||
bool CpuScalingEnabled() {
|
||||
#ifndef OS_WINDOWS
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
|
||||
// local file system. If reading the exported files fails, then we may not be
|
||||
// running on Linux, so we silently ignore all the read errors.
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "internal_macros.h"
|
||||
#include "walltime.h"
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#if defined(BENCHMARK_OS_WINDOWS)
|
||||
#include <time.h>
|
||||
#include <winsock.h> // for timeval
|
||||
#else
|
||||
@ -93,7 +93,7 @@ private:
|
||||
|
||||
WallTime Slow() const {
|
||||
struct timeval tv;
|
||||
#if defined(OS_WINDOWS)
|
||||
#if defined(BENCHMARK_OS_WINDOWS)
|
||||
FILETIME file_time;
|
||||
SYSTEMTIME system_time;
|
||||
ULARGE_INTEGER ularge;
|
||||
@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
|
||||
std::size_t written;
|
||||
|
||||
if (local) {
|
||||
#if defined(OS_WINDOWS)
|
||||
#if defined(BENCHMARK_OS_WINDOWS)
|
||||
written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
|
||||
#else
|
||||
std::tm timeinfo;
|
||||
@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
|
||||
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||
#endif
|
||||
} else {
|
||||
#if defined(OS_WINDOWS)
|
||||
#if defined(BENCHMARK_OS_WINDOWS)
|
||||
written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
|
||||
#else
|
||||
std::tm timeinfo;
|
||||
|
Loading…
Reference in New Issue
Block a user