Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
ba141ac0
Commit
ba141ac0
authored
Oct 05, 2015
by
Anton Danielsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed the internal os macros to avoid a name clash in Shlwapi.h where OS_WINDOWS is defined to 0.
parent
02440964
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
29 deletions
+29
-29
benchmark.cc
src/benchmark.cc
+1
-1
colorprint.cc
src/colorprint.cc
+4
-4
cycleclock.h
src/cycleclock.h
+1
-1
internal_macros.h
src/internal_macros.h
+5
-5
sleep.cc
src/sleep.cc
+2
-2
sysinfo.cc
src/sysinfo.cc
+12
-12
walltime.cc
src/walltime.cc
+4
-4
No files found.
src/benchmark.cc
View file @
ba141ac0
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "benchmark/benchmark.h"
#include "benchmark/benchmark.h"
#include "internal_macros.h"
#include "internal_macros.h"
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
#include <sys/time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/resource.h>
#include <unistd.h>
#include <unistd.h>
...
...
src/colorprint.cc
View file @
ba141ac0
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#include "commandlineflags.h"
#include "commandlineflags.h"
#include "internal_macros.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
#include <Windows.h>
#include <Windows.h>
#endif
#endif
...
@@ -27,14 +27,14 @@ DECLARE_bool(color_print);
...
@@ -27,14 +27,14 @@ DECLARE_bool(color_print);
namespace
benchmark
{
namespace
benchmark
{
namespace
{
namespace
{
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
typedef
WORD
PlatformColorCode
;
typedef
WORD
PlatformColorCode
;
#else
#else
typedef
const
char
*
PlatformColorCode
;
typedef
const
char
*
PlatformColorCode
;
#endif
#endif
PlatformColorCode
GetPlatformColorCode
(
LogColor
color
)
{
PlatformColorCode
GetPlatformColorCode
(
LogColor
color
)
{
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
switch
(
color
)
{
switch
(
color
)
{
case
COLOR_RED
:
case
COLOR_RED
:
return
FOREGROUND_RED
;
return
FOREGROUND_RED
;
...
@@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
...
@@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
return
;
return
;
}
}
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
const
HANDLE
stdout_handle
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
const
HANDLE
stdout_handle
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
// Gets the current text color.
// Gets the current text color.
...
...
src/cycleclock.h
View file @
ba141ac0
...
@@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
...
@@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
#pragma intrinsic(__rdtsc)
#pragma intrinsic(__rdtsc)
#endif
#endif
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
#include <sys/time.h>
#include <sys/time.h>
#endif
#endif
...
...
src/internal_macros.h
View file @
ba141ac0
...
@@ -16,17 +16,17 @@
...
@@ -16,17 +16,17 @@
#endif
#endif
#if defined(__CYGWIN__)
#if defined(__CYGWIN__)
# define OS_CYGWIN 1
# define
BENCHMARK_
OS_CYGWIN 1
#elif defined(_WIN32)
#elif defined(_WIN32)
# define OS_WINDOWS 1
# define
BENCHMARK_
OS_WINDOWS 1
#elif defined(__APPLE__)
#elif defined(__APPLE__)
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
// that it is an apple system.
// that it is an apple system.
# define OS_MACOSX 1
# define
BENCHMARK_
OS_MACOSX 1
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__)
# define OS_FREEBSD 1
# define
BENCHMARK_
OS_FREEBSD 1
#elif defined(__linux__)
#elif defined(__linux__)
# define OS_LINUX 1
# define
BENCHMARK_
OS_LINUX 1
#endif
#endif
#if defined(__clang__)
#if defined(__clang__)
...
...
src/sleep.cc
View file @
ba141ac0
...
@@ -19,12 +19,12 @@
...
@@ -19,12 +19,12 @@
#include "internal_macros.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
#include <Windows.h>
#include <Windows.h>
#endif
#endif
namespace
benchmark
{
namespace
benchmark
{
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
// Window's Sleep takes milliseconds argument.
// Window's Sleep takes milliseconds argument.
void
SleepForMilliseconds
(
int
milliseconds
)
{
Sleep
(
milliseconds
);
}
void
SleepForMilliseconds
(
int
milliseconds
)
{
Sleep
(
milliseconds
);
}
void
SleepForSeconds
(
double
seconds
)
{
void
SleepForSeconds
(
double
seconds
)
{
...
...
src/sysinfo.cc
View file @
ba141ac0
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "sysinfo.h"
#include "sysinfo.h"
#include "internal_macros.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef
BENCHMARK_
OS_WINDOWS
#include <Shlwapi.h>
#include <Shlwapi.h>
#include <Windows.h>
#include <Windows.h>
#else
#else
...
@@ -51,7 +51,7 @@ double cpuinfo_cycles_per_second = 1.0;
...
@@ -51,7 +51,7 @@ double cpuinfo_cycles_per_second = 1.0;
int
cpuinfo_num_cpus
=
1
;
// Conservative guess
int
cpuinfo_num_cpus
=
1
;
// Conservative guess
std
::
mutex
cputimens_mutex
;
std
::
mutex
cputimens_mutex
;
#if !defined OS_MACOSX
#if !defined
BENCHMARK_
OS_MACOSX
const
int64_t
estimate_time_ms
=
1000
;
const
int64_t
estimate_time_ms
=
1000
;
// Helper function estimates cycles/sec by observing cycles elapsed during
// Helper function estimates cycles/sec by observing cycles elapsed during
...
@@ -63,7 +63,7 @@ int64_t EstimateCyclesPerSecond() {
...
@@ -63,7 +63,7 @@ int64_t EstimateCyclesPerSecond() {
}
}
#endif
#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
// 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.
// and the memory location pointed to by value is set to the value read.
bool
ReadIntFromFile
(
const
char
*
file
,
long
*
value
)
{
bool
ReadIntFromFile
(
const
char
*
file
,
long
*
value
)
{
...
@@ -86,7 +86,7 @@ bool ReadIntFromFile(const char* file, long* value) {
...
@@ -86,7 +86,7 @@ bool ReadIntFromFile(const char* file, long* value) {
#endif
#endif
void
InitializeSystemInfo
()
{
void
InitializeSystemInfo
()
{
#if defined
OS_LINUX || defined
OS_CYGWIN
#if defined
BENCHMARK_OS_LINUX || defined BENCHMARK_
OS_CYGWIN
char
line
[
1024
];
char
line
[
1024
];
char
*
err
;
char
*
err
;
long
freq
;
long
freq
;
...
@@ -204,7 +204,7 @@ void InitializeSystemInfo() {
...
@@ -204,7 +204,7 @@ void InitializeSystemInfo() {
cpuinfo_num_cpus
=
num_cpus
;
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
// 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
// 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
// and later. Before that, it's a 32-bit quantity (and gives the
...
@@ -232,7 +232,7 @@ void InitializeSystemInfo() {
...
@@ -232,7 +232,7 @@ void InitializeSystemInfo() {
}
}
// TODO: also figure out cpuinfo_num_cpus
// 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
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
// then make a crude estimate.
// then make a crude estimate.
OSVERSIONINFO
os
;
OSVERSIONINFO
os
;
...
@@ -248,7 +248,7 @@ void InitializeSystemInfo() {
...
@@ -248,7 +248,7 @@ void InitializeSystemInfo() {
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
// TODO: also figure out cpuinfo_num_cpus
// 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
// returning "mach time units" per second. the current number of elapsed
// mach time units can be found by calling uint64 mach_absolute_time();
// 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
// while not as precise as actual CPU cycles, it is accurate in the face
...
@@ -281,7 +281,7 @@ void InitializeSystemInfo() {
...
@@ -281,7 +281,7 @@ void InitializeSystemInfo() {
// getrusage() based implementation of MyCPUUsage
// getrusage() based implementation of MyCPUUsage
static
double
MyCPUUsageRUsage
()
{
static
double
MyCPUUsageRUsage
()
{
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
struct
rusage
ru
;
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
)
==
0
)
{
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
...
@@ -309,7 +309,7 @@ static double MyCPUUsageRUsage() {
...
@@ -309,7 +309,7 @@ static double MyCPUUsageRUsage() {
#endif // OS_WINDOWS
#endif // OS_WINDOWS
}
}
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
static
bool
MyCPUUsageCPUTimeNsLocked
(
double
*
cputime
)
{
static
bool
MyCPUUsageCPUTimeNsLocked
(
double
*
cputime
)
{
static
int
cputime_fd
=
-
1
;
static
int
cputime_fd
=
-
1
;
if
(
cputime_fd
==
-
1
)
{
if
(
cputime_fd
==
-
1
)
{
...
@@ -338,7 +338,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
...
@@ -338,7 +338,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
#endif // OS_WINDOWS
#endif // OS_WINDOWS
double
MyCPUUsage
()
{
double
MyCPUUsage
()
{
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
{
{
std
::
lock_guard
<
std
::
mutex
>
l
(
cputimens_mutex
);
std
::
lock_guard
<
std
::
mutex
>
l
(
cputimens_mutex
);
static
bool
use_cputime_ns
=
true
;
static
bool
use_cputime_ns
=
true
;
...
@@ -357,7 +357,7 @@ double MyCPUUsage() {
...
@@ -357,7 +357,7 @@ double MyCPUUsage() {
}
}
double
ChildrenCPUUsage
()
{
double
ChildrenCPUUsage
()
{
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
struct
rusage
ru
;
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_CHILDREN
,
&
ru
)
==
0
)
{
if
(
getrusage
(
RUSAGE_CHILDREN
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
...
@@ -394,7 +394,7 @@ int NumCPUs(void) {
...
@@ -394,7 +394,7 @@ int NumCPUs(void) {
: nullptr)
: nullptr)
bool
CpuScalingEnabled
()
{
bool
CpuScalingEnabled
()
{
#ifndef OS_WINDOWS
#ifndef
BENCHMARK_
OS_WINDOWS
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
// 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
// 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.
// running on Linux, so we silently ignore all the read errors.
...
...
src/walltime.cc
View file @
ba141ac0
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include "internal_macros.h"
#include "internal_macros.h"
#include "walltime.h"
#include "walltime.h"
#if defined(OS_WINDOWS)
#if defined(
BENCHMARK_
OS_WINDOWS)
#include <time.h>
#include <time.h>
#include <winsock.h> // for timeval
#include <winsock.h> // for timeval
#else
#else
...
@@ -93,7 +93,7 @@ private:
...
@@ -93,7 +93,7 @@ private:
WallTime
Slow
()
const
{
WallTime
Slow
()
const
{
struct
timeval
tv
;
struct
timeval
tv
;
#if defined(OS_WINDOWS)
#if defined(
BENCHMARK_
OS_WINDOWS)
FILETIME
file_time
;
FILETIME
file_time
;
SYSTEMTIME
system_time
;
SYSTEMTIME
system_time
;
ULARGE_INTEGER
ularge
;
ULARGE_INTEGER
ularge
;
...
@@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
...
@@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
std
::
size_t
written
;
std
::
size_t
written
;
if
(
local
)
{
if
(
local
)
{
#if defined(OS_WINDOWS)
#if defined(
BENCHMARK_
OS_WINDOWS)
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
localtime
(
&
now
));
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
localtime
(
&
now
));
#else
#else
std
::
tm
timeinfo
;
std
::
tm
timeinfo
;
...
@@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
...
@@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%F %T"
,
&
timeinfo
);
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%F %T"
,
&
timeinfo
);
#endif
#endif
}
else
{
}
else
{
#if defined(OS_WINDOWS)
#if defined(
BENCHMARK_
OS_WINDOWS)
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
gmtime
(
&
now
));
written
=
std
::
strftime
(
storage
,
sizeof
(
storage
),
"%x %X"
,
::
gmtime
(
&
now
));
#else
#else
std
::
tm
timeinfo
;
std
::
tm
timeinfo
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment