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
4ce184d8
Commit
4ce184d8
authored
Jan 09, 2014
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code reformat
parent
80093519
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
193 additions
and
196 deletions
+193
-196
benchmark.h
include/benchmark/benchmark.h
+14
-15
macros.h
include/benchmark/macros.h
+7
-4
benchmark.cc
src/benchmark.cc
+0
-0
colorprint.cc
src/colorprint.cc
+31
-17
commandlineflags.cc
src/commandlineflags.cc
+9
-13
commandlineflags.h
src/commandlineflags.h
+0
-0
cycleclock.h
src/cycleclock.h
+14
-14
mutex_lock.h
src/mutex_lock.h
+1
-3
sleep.cc
src/sleep.cc
+1
-3
stat.h
src/stat.h
+74
-83
sysinfo.cc
src/sysinfo.cc
+37
-38
walltime.cc
src/walltime.cc
+5
-6
No files found.
include/benchmark/benchmark.h
View file @
4ce184d8
...
...
@@ -414,8 +414,8 @@ class Benchmark {
static
void
RunInstance
(
const
Instance
&
b
,
BenchmarkReporter
*
br
);
friend
class
::
benchmark
::
State
;
friend
struct
::
benchmark
::
internal
::
Benchmark
::
Instance
;
friend
void
::
benchmark
::
internal
::
RunMatchingBenchmarks
(
const
std
::
string
&
,
BenchmarkReporter
*
);
friend
void
::
benchmark
::
internal
::
RunMatchingBenchmarks
(
const
std
::
string
&
,
BenchmarkReporter
*
);
DISALLOW_COPY_AND_ASSIGN
(
Benchmark
);
};
...
...
@@ -425,7 +425,7 @@ class Benchmark {
struct
BenchmarkContextData
{
int
num_cpus
;
double
mhz_per_cpu
;
//std::string cpu_info;
//
std::string cpu_info;
bool
cpu_scaling_enabled
;
// The number of chars in the longest benchmark name.
...
...
@@ -433,8 +433,8 @@ struct BenchmarkContextData {
};
struct
BenchmarkRunData
{
BenchmarkRunData
()
:
thread_index
(
-
1
),
BenchmarkRunData
()
:
thread_index
(
-
1
),
iterations
(
1
),
real_accumulated_time
(
0
),
cpu_accumulated_time
(
0
),
...
...
@@ -481,15 +481,13 @@ class BenchmarkReporter {
virtual
~
BenchmarkReporter
();
};
// ------------------------------------------------------
// Internal implementation details follow; please ignore
// Given a collection of reports, computes their mean and stddev.
// REQUIRES: all runs in "reports" must be from the same benchmark.
void
ComputeStats
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
,
BenchmarkRunData
*
mean_data
,
BenchmarkRunData
*
stddev_data
);
BenchmarkRunData
*
mean_data
,
BenchmarkRunData
*
stddev_data
);
// Simple reporter that outputs benchmark data to the console. This is the
// default reporter used by RunSpecifiedBenchmarks().
...
...
@@ -497,6 +495,7 @@ class ConsoleReporter : public BenchmarkReporter {
public
:
virtual
bool
ReportContext
(
const
BenchmarkContextData
&
context
);
virtual
void
ReportRuns
(
const
std
::
vector
<
BenchmarkRunData
>&
reports
);
private
:
std
::
string
PrintMemoryUsage
(
double
bytes
);
virtual
void
PrintRunData
(
const
BenchmarkRunData
&
report
);
...
...
@@ -513,11 +512,11 @@ void Initialize(int* argc, const char** argv);
// Helpers for generating unique variable names
#define BENCHMARK_CONCAT(a, b, c) BENCHMARK_CONCAT2(a, b, c)
#define BENCHMARK_CONCAT2(a, b, c) a
## b ##
c
#define BENCHMARK_CONCAT2(a, b, c) a
##b##
c
#define BENCHMARK(n) \
static ::benchmark::internal::Benchmark*
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT(
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n, n))
// Old-style macros
...
...
@@ -536,13 +535,13 @@ void Initialize(int* argc, const char** argv);
//
// will register BM_Foo<1> as a benchmark.
#define BENCHMARK_TEMPLATE(n, a) \
static ::benchmark::internal::Benchmark*
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT(
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n "<" #a ">", n<a>))
#define BENCHMARK_TEMPLATE2(n, a, b) \
static ::benchmark::internal::Benchmark*
\
BENCHMARK_CONCAT(__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
static ::benchmark::internal::Benchmark*
BENCHMARK_CONCAT(
\
__benchmark_, n, __LINE__) ATTRIBUTE_UNUSED =
\
(new ::benchmark::internal::Benchmark(#n "<" #a "," #b ">", n<a, b>))
#endif // BENCHMARK_BENCHMARK_H_
...
...
include/benchmark/macros.h
View file @
4ce184d8
...
...
@@ -34,7 +34,10 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
#define CHECK(b) do { if (!(b)) assert(false); } while(0)
#define CHECK(b) \
do { \
if (!(b)) assert(false); \
} while (0)
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_NE(a, b) CHECK((a) != (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
...
...
@@ -45,14 +48,14 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
//
// Prevent the compiler from complaining about or optimizing away variables
// that appear unused.
#define ATTRIBUTE_UNUSED __attribute__
((unused))
#define ATTRIBUTE_UNUSED __attribute__((unused))
//
// For functions we want to force inline or not inline.
// Introduced in gcc 3.1.
#define ATTRIBUTE_ALWAYS_INLINE
__attribute__
((always_inline))
#define ATTRIBUTE_ALWAYS_INLINE
__attribute__
((always_inline))
#define HAVE_ATTRIBUTE_ALWAYS_INLINE 1
#define ATTRIBUTE_NOINLINE __attribute__
((noinline))
#define ATTRIBUTE_NOINLINE __attribute__((noinline))
#define HAVE_ATTRIBUTE_NOINLINE 1
#endif // BENCHMARK_MACROS_H_
src/benchmark.cc
View file @
4ce184d8
This diff is collapsed.
Click to expand it.
src/colorprint.cc
View file @
4ce184d8
...
...
@@ -17,25 +17,40 @@ typedef const char* PlatformColorCode;
PlatformColorCode
GetPlatformColorCode
(
LogColor
color
)
{
#ifdef OS_WINDOWS
switch
(
color
)
{
case
COLOR_RED
:
return
FOREGROUND_RED
;
case
COLOR_GREEN
:
return
FOREGROUND_GREEN
;
case
COLOR_YELLOW
:
return
FOREGROUND_RED
|
FOREGROUND_GREEN
;
case
COLOR_BLUE
:
return
FOREGROUND_BLUE
;
case
COLOR_MAGENTA
:
return
FOREGROUND_BLUE
|
FOREGROUND_RED
;
case
COLOR_CYAN
:
return
FOREGROUND_BLUE
|
FOREGROUND_GREEN
;
case
COLOR_RED
:
return
FOREGROUND_RED
;
case
COLOR_GREEN
:
return
FOREGROUND_GREEN
;
case
COLOR_YELLOW
:
return
FOREGROUND_RED
|
FOREGROUND_GREEN
;
case
COLOR_BLUE
:
return
FOREGROUND_BLUE
;
case
COLOR_MAGENTA
:
return
FOREGROUND_BLUE
|
FOREGROUND_RED
;
case
COLOR_CYAN
:
return
FOREGROUND_BLUE
|
FOREGROUND_GREEN
;
case
COLOR_WHITE
:
// fall through to default
default:
return
0
;
default:
return
0
;
}
#else
switch
(
color
)
{
case
COLOR_RED
:
return
"1"
;
case
COLOR_GREEN
:
return
"2"
;
case
COLOR_YELLOW
:
return
"3"
;
case
COLOR_BLUE
:
return
"4"
;
case
COLOR_MAGENTA
:
return
"5"
;
case
COLOR_CYAN
:
return
"6"
;
case
COLOR_WHITE
:
return
"7"
;
default:
return
NULL
;
case
COLOR_RED
:
return
"1"
;
case
COLOR_GREEN
:
return
"2"
;
case
COLOR_YELLOW
:
return
"3"
;
case
COLOR_BLUE
:
return
"4"
;
case
COLOR_MAGENTA
:
return
"5"
;
case
COLOR_CYAN
:
return
"6"
;
case
COLOR_WHITE
:
return
"7"
;
default:
return
NULL
;
};
#endif
}
...
...
@@ -72,8 +87,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
SetConsoleTextAttribute
(
stdout_handle
,
old_color_attrs
);
#else
const
char
*
color_code
=
GetPlatformColorCode
(
color
);
if
(
color_code
)
fprintf
(
stdout
,
"
\033
[0;3%sm"
,
color_code
);
if
(
color_code
)
fprintf
(
stdout
,
"
\033
[0;3%sm"
,
color_code
);
vprintf
(
fmt
,
args
);
printf
(
"
\033
[m"
);
// Resets the terminal to default.
#endif
...
...
src/commandlineflags.cc
View file @
4ce184d8
...
...
@@ -60,7 +60,6 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) {
return
true
;
}
inline
const
char
*
GetEnv
(
const
char
*
name
)
{
#if GTEST_OS_WINDOWS_MOBILE
// We are on Windows CE, which has no environment variables.
...
...
@@ -95,8 +94,7 @@ static std::string FlagToEnvVar(const char* flag) {
bool
BoolFromEnv
(
const
char
*
flag
,
bool
default_value
)
{
const
std
::
string
env_var
=
FlagToEnvVar
(
flag
);
const
char
*
const
string_value
=
GetEnv
(
env_var
.
c_str
());
return
string_value
==
NULL
?
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
return
string_value
==
NULL
?
default_value
:
strcmp
(
string_value
,
"0"
)
!=
0
;
}
// Reads and returns a 32-bit integer stored in the environment
...
...
@@ -111,8 +109,8 @@ int32_t Int32FromEnv(const char* flag, int32_t default_value) {
}
int32_t
result
=
default_value
;
if
(
!
ParseInt32
(
std
::
string
(
"Environment variable "
)
+
env_var
,
string_value
,
&
result
))
{
if
(
!
ParseInt32
(
std
::
string
(
"Environment variable "
)
+
env_var
,
string_value
,
&
result
))
{
std
::
cout
<<
"The default value "
<<
default_value
<<
" is used.
\n
"
;
return
default_value
;
}
...
...
@@ -133,8 +131,7 @@ const char* StringFromEnv(const char* flag, const char* default_value) {
// part can be omitted.
//
// Returns the value of the flag, or NULL if the parsing failed.
const
char
*
ParseFlagValue
(
const
char
*
str
,
const
char
*
flag
,
const
char
*
ParseFlagValue
(
const
char
*
str
,
const
char
*
flag
,
bool
def_optional
)
{
// str and flag must not be NULL.
if
(
str
==
NULL
||
flag
==
NULL
)
return
NULL
;
...
...
@@ -148,8 +145,7 @@ const char* ParseFlagValue(const char* str,
const
char
*
flag_end
=
str
+
flag_len
;
// When def_optional is true, it's OK to not have a "=value" part.
if
(
def_optional
&&
(
flag_end
[
0
]
==
'\0'
))
return
flag_end
;
if
(
def_optional
&&
(
flag_end
[
0
]
==
'\0'
))
return
flag_end
;
// If def_optional is true and there are more characters after the
// flag name, or if def_optional is false, there must be a '=' after
...
...
@@ -180,8 +176,8 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
if
(
value_str
==
NULL
)
return
false
;
// Sets *value to the value of the flag.
return
ParseInt32
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value
_str
,
value
);
return
ParseInt32
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value_str
,
value
);
}
bool
ParseDoubleFlag
(
const
char
*
str
,
const
char
*
flag
,
double
*
value
)
{
...
...
@@ -192,8 +188,8 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
if
(
value_str
==
NULL
)
return
false
;
// Sets *value to the value of the flag.
return
ParseDouble
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value
_str
,
value
);
return
ParseDouble
(
std
::
string
(
"The value of flag --"
)
+
flag
,
value_str
,
value
);
}
bool
ParseStringFlag
(
const
char
*
str
,
const
char
*
flag
,
std
::
string
*
value
)
{
...
...
src/commandlineflags.h
View file @
4ce184d8
src/cycleclock.h
View file @
4ce184d8
...
...
@@ -24,7 +24,7 @@
#include <stdint.h>
#if defined(OS_MACOSX)
#
include <mach/mach_time.h>
#include <mach/mach_time.h>
#endif
// For MSVC, we want to use '_asm rdtsc' when possible (since it works
// with even ancient MSVC compilers), and when not possible the
...
...
@@ -48,8 +48,8 @@ namespace benchmark {
// with modifications by m3b. See also
// https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
namespace
cycleclock
{
// This should return the number of cycles since power-on. Thread-safe.
inline
ATTRIBUTE_ALWAYS_INLINE
int64_t
Now
()
{
// This should return the number of cycles since power-on. Thread-safe.
inline
ATTRIBUTE_ALWAYS_INLINE
int64_t
Now
()
{
#if defined(OS_MACOSX)
// this goes at the top because we need ALL Macs, regardless of
// architecture, to return the number of "mach time units" that
...
...
@@ -63,29 +63,29 @@ namespace cycleclock {
return
mach_absolute_time
();
#elif defined(__i386__)
int64_t
ret
;
__asm__
volatile
(
"rdtsc"
:
"=A"
(
ret
)
);
__asm__
volatile
(
"rdtsc"
:
"=A"
(
ret
)
);
return
ret
;
#elif defined(__x86_64__) || defined(__amd64__)
uint64_t
low
,
high
;
__asm__
volatile
(
"rdtsc"
:
"=a"
(
low
),
"=d"
(
high
));
__asm__
volatile
(
"rdtsc"
:
"=a"
(
low
),
"=d"
(
high
));
return
(
high
<<
32
)
|
low
;
#elif defined(__powerpc__) || defined(__ppc__)
// This returns a time-base, which is not always precisely a cycle-count.
int64_t
tbl
,
tbu0
,
tbu1
;
asm
(
"mftbu %0"
:
"=r"
(
tbu0
));
asm
(
"mftb %0"
:
"=r"
(
tbl
));
asm
(
"mftbu %0"
:
"=r"
(
tbu1
));
asm
(
"mftbu %0"
:
"=r"
(
tbu0
));
asm
(
"mftb %0"
:
"=r"
(
tbl
));
asm
(
"mftbu %0"
:
"=r"
(
tbu1
));
tbl
&=
-
static_cast
<
int64
>
(
tbu0
==
tbu1
);
// high 32 bits in tbu1; low 32 bits in tbl (tbu0 is garbage)
return
(
tbu1
<<
32
)
|
tbl
;
#elif defined(__sparc__)
int64_t
tick
;
asm
(
".byte 0x83, 0x41, 0x00, 0x00"
);
asm
(
"mov %%g1, %0"
:
"=r"
(
tick
));
asm
(
"mov %%g1, %0"
:
"=r"
(
tick
));
return
tick
;
#elif defined(__ia64__)
int64_t
itc
;
asm
(
"mov %0 = ar.itc"
:
"=r"
(
itc
));
asm
(
"mov %0 = ar.itc"
:
"=r"
(
itc
));
return
itc
;
#elif defined(COMPILER_MSVC) && defined(_M_IX86)
// Older MSVC compilers (like 7.x) don't seem to support the
...
...
@@ -101,11 +101,11 @@ namespace cycleclock {
uint32_t
pmuseren
;
uint32_t
pmcntenset
;
// Read the user mode perf monitor counter access permissions.
asm
(
"mrc p15, 0, %0, c9, c14, 0"
:
"=r"
(
pmuseren
));
asm
(
"mrc p15, 0, %0, c9, c14, 0"
:
"=r"
(
pmuseren
));
if
(
pmuseren
&
1
)
{
// Allows reading perfmon counters for user mode code.
asm
(
"mrc p15, 0, %0, c9, c12, 1"
:
"=r"
(
pmcntenset
));
asm
(
"mrc p15, 0, %0, c9, c12, 1"
:
"=r"
(
pmcntenset
));
if
(
pmcntenset
&
0x80000000ul
)
{
// Is it counting?
asm
(
"mrc p15, 0, %0, c9, c13, 0"
:
"=r"
(
pmccntr
));
asm
(
"mrc p15, 0, %0, c9, c13, 0"
:
"=r"
(
pmccntr
));
// The counter is set up to count every 64th cycle
return
static_cast
<
int64
>
(
pmccntr
)
*
64
;
// Should optimize to << 6
}
...
...
@@ -126,7 +126,7 @@ namespace cycleclock {
// a fast implementation and use generic version if nothing better is available.
#error You need to define CycleTimer for your OS and CPU
#endif
}
}
}
// end namespace cycleclock
}
// end namespace benchmark
...
...
src/mutex_lock.h
View file @
4ce184d8
...
...
@@ -10,9 +10,7 @@ class mutex_lock {
pthread_mutex_lock
(
mu_
);
}
~
mutex_lock
()
{
pthread_mutex_unlock
(
mu_
);
}
~
mutex_lock
()
{
pthread_mutex_unlock
(
mu_
);
}
private
:
pthread_mutex_t
*
mu_
;
...
...
src/sleep.cc
View file @
4ce184d8
...
...
@@ -6,9 +6,7 @@
namespace
benchmark
{
#ifdef OS_WINDOWS
// Window's _sleep takes milliseconds argument.
void
SleepForMilliseconds
(
int
milliseconds
)
{
_sleep
(
milliseconds
);
}
void
SleepForMilliseconds
(
int
milliseconds
)
{
_sleep
(
milliseconds
);
}
void
SleepForSeconds
(
double
seconds
)
{
SleepForMilliseconds
(
static_cast
<
int
>
(
kNumMillisPerSecond
*
seconds
));
}
...
...
src/stat.h
View file @
4ce184d8
This diff is collapsed.
Click to expand it.
src/sysinfo.cc
View file @
4ce184d8
...
...
@@ -39,7 +39,7 @@ int64_t EstimateCyclesPerSecond(const int estimate_time_ms) {
// 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
,
int
*
value
)
{
bool
ReadIntFromFile
(
const
char
*
file
,
int
*
value
)
{
bool
ret
=
false
;
int
fd
=
open
(
file
,
O_RDONLY
);
if
(
fd
!=
-
1
)
{
...
...
@@ -116,42 +116,41 @@ void InitializeSystemInfo() {
if
(
sizeof
(
line
)
==
oldlinelen
+
1
)
// oldlinelen took up entire line
line
[
0
]
=
'\0'
;
else
// still other lines left to save
memmove
(
line
,
line
+
oldlinelen
+
1
,
sizeof
(
line
)
-
(
oldlinelen
+
1
));
memmove
(
line
,
line
+
oldlinelen
+
1
,
sizeof
(
line
)
-
(
oldlinelen
+
1
));
// Terminate the new line, reading more if we can't find the newline
char
*
newline
=
strchr
(
line
,
'\n'
);
if
(
newline
==
NULL
)
{
const
int
linelen
=
strlen
(
line
);
const
int
bytes_to_read
=
sizeof
(
line
)
-
1
-
linelen
;
const
int
bytes_to_read
=
sizeof
(
line
)
-
1
-
linelen
;
CHECK
(
bytes_to_read
>
0
);
// because the memmove recovered >=1 bytes
chars_read
=
read
(
fd
,
line
+
linelen
,
bytes_to_read
);
line
[
linelen
+
chars_read
]
=
'\0'
;
newline
=
strchr
(
line
,
'\n'
);
}
if
(
newline
!=
NULL
)
*
newline
=
'\0'
;
if
(
newline
!=
NULL
)
*
newline
=
'\0'
;
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// accept postive values. Some environments (virtual machines) report zero,
// which would cause infinite looping in WallTime_Init.
if
(
!
saw_mhz
&&
strncasecmp
(
line
,
"cpu MHz"
,
sizeof
(
"cpu MHz"
)
-
1
)
==
0
)
{
if
(
!
saw_mhz
&&
strncasecmp
(
line
,
"cpu MHz"
,
sizeof
(
"cpu MHz"
)
-
1
)
==
0
)
{
const
char
*
freqstr
=
strchr
(
line
,
':'
);
if
(
freqstr
)
{
cpuinfo_cycles_per_second
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
cpuinfo_cycles_per_second
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
cpuinfo_cycles_per_second
>
0
)
saw_mhz
=
true
;
}
}
else
if
(
strncasecmp
(
line
,
"bogomips"
,
sizeof
(
"bogomips"
)
-
1
)
==
0
)
{
}
else
if
(
strncasecmp
(
line
,
"bogomips"
,
sizeof
(
"bogomips"
)
-
1
)
==
0
)
{
const
char
*
freqstr
=
strchr
(
line
,
':'
);
if
(
freqstr
)
{
bogo_clock
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
bogo_clock
=
strtod
(
freqstr
+
1
,
&
err
)
*
1000000.0
;
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
bogo_clock
>
0
)
saw_bogo
=
true
;
}
}
else
if
(
strncasecmp
(
line
,
"processor"
,
sizeof
(
"processor"
)
-
1
)
==
0
)
{
}
else
if
(
strncasecmp
(
line
,
"processor"
,
sizeof
(
"processor"
)
-
1
)
==
0
)
{
num_cpus
++
;
// count up every time we see an "processor :" entry
const
char
*
freqstr
=
strchr
(
line
,
':'
);
if
(
freqstr
)
{
const
int
cpu_id
=
strtol
(
freqstr
+
1
,
&
err
,
10
);
const
int
cpu_id
=
strtol
(
freqstr
+
1
,
&
err
,
10
);
if
(
freqstr
[
1
]
!=
'\0'
&&
*
err
==
'\0'
&&
max_cpu_id
<
cpu_id
)
max_cpu_id
=
cpu_id
;
}
...
...
@@ -181,17 +180,17 @@ void InitializeSystemInfo() {
}
#elif defined 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
// wrong answer on machines faster than 2^32 Hz). See
// http://lists.freebsd.org/pipermail/freebsd-i386/2004-November/001846.html
// But also compare FreeBSD 7.0:
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG70#L223
// 231 error = sysctl_handle_quad(oidp, &freq, 0, req);
// To FreeBSD 6.3 (it's the same in 6-STABLE):
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
// 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
// wrong answer on machines faster than 2^32 Hz). See
// http://lists.freebsd.org/pipermail/freebsd-i386/2004-November/001846.html
// But also compare FreeBSD 7.0:
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG70#L223
// 231 error = sysctl_handle_quad(oidp, &freq, 0, req);
// To FreeBSD 6.3 (it's the same in 6-STABLE):
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
#if __FreeBSD__ >= 7
uint64_t
hz
=
0
;
#else
...
...
@@ -199,25 +198,25 @@ void InitializeSystemInfo() {
#endif
size_t
sz
=
sizeof
(
hz
);
const
char
*
sysctl_path
=
"machdep.tsc_freq"
;
if
(
sysctlbyname
(
sysctl_path
,
&
hz
,
&
sz
,
NULL
,
0
)
!=
0
)
{
if
(
sysctlbyname
(
sysctl_path
,
&
hz
,
&
sz
,
NULL
,
0
)
!=
0
)
{
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
sysctl_path
,
strerror
(
errno
));
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
1000
);
}
else
{
cpuinfo_cycles_per_second
=
hz
;
}
// TODO: also figure out cpuinfo_num_cpus
// TODO: also figure out cpuinfo_num_cpus
#elif defined OS_WINDOWS
#
pragma comment(lib, "shlwapi.lib") // for SHGetValue()
#pragma comment(lib, "shlwapi.lib") // for SHGetValue()
// 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
;
os
.
dwOSVersionInfoSize
=
sizeof
(
os
);
DWORD
data
,
data_size
=
sizeof
(
data
);
if
(
GetVersionEx
(
&
os
)
&&
os
.
dwPlatformId
==
VER_PLATFORM_WIN32_NT
&&
SUCCEEDED
(
SHGetValueA
(
HKEY_LOCAL_MACHINE
,
if
(
GetVersionEx
(
&
os
)
&&
os
.
dwPlatformId
==
VER_PLATFORM_WIN32_NT
&&
SUCCEEDED
(
SHGetValueA
(
HKEY_LOCAL_MACHINE
,
"HARDWARE
\\
DESCRIPTION
\\
System
\\
CentralProcessor
\\
0"
,
"~MHz"
,
NULL
,
&
data
,
&
data_size
)))
cpuinfo_cycles_per_second
=
(
int64
)
data
*
(
int64
)(
1000
*
1000
);
// was mhz
...
...
@@ -243,10 +242,10 @@ void InitializeSystemInfo() {
int
num_cpus
=
0
;
size_t
size
=
sizeof
(
num_cpus
);
int
numcpus_name
[]
=
{
CTL_HW
,
HW_NCPU
};
if
(
::
sysctl
(
numcpus_name
,
arraysize
(
numcpus_name
),
&
num_cpus
,
&
size
,
0
,
0
)
==
0
&&
(
size
==
sizeof
(
num_cpus
)))
int
numcpus_name
[]
=
{
CTL_HW
,
HW_NCPU
};
if
(
::
sysctl
(
numcpus_name
,
arraysize
(
numcpus_name
),
&
num_cpus
,
&
size
,
0
,
0
)
==
0
&&
(
size
==
sizeof
(
num_cpus
)))
cpuinfo_num_cpus
=
num_cpus
;
#else
...
...
@@ -262,15 +261,15 @@ static double MyCPUUsageRUsage() {
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_usec
)
*
1e-6
+
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_usec
)
*
1e-6
+
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_sec
)
+
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_usec
)
*
1e-6
);
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_usec
)
*
1e-6
);
}
else
{
return
0.0
;
}
}
static
bool
MyCPUUsageCPUTimeNsLocked
(
double
*
cputime
)
{
static
bool
MyCPUUsageCPUTimeNsLocked
(
double
*
cputime
)
{
static
int
cputime_fd
=
-
1
;
if
(
cputime_fd
==
-
1
)
{
cputime_fd
=
open
(
"/proc/self/cputime_ns"
,
O_RDONLY
);
...
...
@@ -281,7 +280,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double *cputime) {
}
char
buff
[
64
];
memset
(
buff
,
0
,
sizeof
(
buff
));
if
(
pread
(
cputime_fd
,
buff
,
sizeof
(
buff
)
-
1
,
0
)
<=
0
)
{
if
(
pread
(
cputime_fd
,
buff
,
sizeof
(
buff
)
-
1
,
0
)
<=
0
)
{
close
(
cputime_fd
);
cputime_fd
=
-
1
;
return
false
;
...
...
@@ -317,9 +316,9 @@ double ChildrenCPUUsage() {
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_CHILDREN
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_usec
)
*
1e-6
+
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_usec
)
*
1e-6
+
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_sec
)
+
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_usec
)
*
1e-6
);
static_cast
<
double
>
(
ru
.
ru_stime
.
tv_usec
)
*
1e-6
);
}
else
{
return
0.0
;
}
...
...
src/walltime.cc
View file @
4ce184d8
...
...
@@ -75,8 +75,8 @@ void Initialize() {
cycles_per_second
=
static_cast
<
int64_t
>
(
CyclesPerSecond
());
CHECK
(
cycles_per_second
!=
0
);
seconds_per_cycle
=
1.0
/
cycles_per_second
;
max_interval_cycles
=
static_cast
<
int64_t
>
(
cycles_per_second
*
kMaxErrorInterval
);
max_interval_cycles
=
static_cast
<
int64_t
>
(
cycles_per_second
*
kMaxErrorInterval
);
do
{
base_cycletime
=
cycleclock
::
Now
();
base_walltime
=
Slow
();
...
...
@@ -90,8 +90,7 @@ void Initialize() {
}
WallTime
Now
()
{
if
(
!
std
::
atomic_load
(
&
initialized
))
return
Slow
();
if
(
!
std
::
atomic_load
(
&
initialized
))
return
Slow
();
WallTime
now
=
0.0
;
WallTime
result
=
0.0
;
...
...
@@ -119,8 +118,8 @@ WallTime Now() {
return
now
;
}
std
::
string
Print
(
WallTime
time
,
const
char
*
format
,
bool
local
,
int
*
remainder_us
)
{
std
::
string
Print
(
WallTime
time
,
const
char
*
format
,
bool
local
,
int
*
remainder_us
)
{
char
storage
[
32
];
struct
tm
split
;
double
subsecond
;
...
...
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