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
65ed470c
Commit
65ed470c
authored
Mar 31, 2015
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #64 from mattyclarkson/nt
MinGW support
parents
80514584
36d7dc67
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
6 deletions
+110
-6
.gitignore
.gitignore
+4
-0
appveyor.yml
appveyor.yml
+55
-0
mingw.py
mingw.py
+0
-0
CMakeLists.txt
src/CMakeLists.txt
+5
-0
benchmark.cc
src/benchmark.cc
+3
-0
colorprint.cc
src/colorprint.cc
+4
-0
sleep.cc
src/sleep.cc
+6
-2
sysinfo.cc
src/sysinfo.cc
+33
-4
No files found.
.gitignore
View file @
65ed470c
*.a
*.so
*.so.?*
*.dll
*.exe
*.dylib
*.cmake
!/cmake/*.cmake
*~
*.pyc
__pycache__
# cmake files.
/Testing
...
...
appveyor.yml
0 → 100644
View file @
65ed470c
version
:
'
{build}'
configuration
:
-
Static Debug
-
Static Release
# - Shared Debug
# - Shared Release
platform
:
-
x86
-
x64
environment
:
matrix
:
-
compiler
:
gcc-4.9.2-posix
# - compiler: gcc-4.8.4-posix
# - compiler: msvc-12-seh
install
:
# derive some extra information
-
for /f "tokens=1-2" %%a in ("%configuration%") do (@set "linkage=%%a")
-
for /f "tokens=1-2" %%a in ("%configuration%") do (@set "variant=%%b")
-
if "%linkage%"=="Shared" (set shared=YES) else (set shared=NO)
-
for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_name=%%a")
-
for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_version=%%b")
-
for /f "tokens=1-3 delims=-" %%a in ("%compiler%") do (@set "compiler_threading=%%c")
-
if "%platform%"=="x64" (set arch=x86_64)
-
if "%platform%"=="x86" (set arch=i686)
# download the specific version of MinGW
-
if "%compiler_name%"=="gcc" (for /f %%a in ('python mingw.py --quiet --version "%compiler_version%" --arch "%arch%" --threading "%compiler_threading%" --location "C:\mingw-builds"') do @set "compiler_path=%%a")
before_build
:
# Set up mingw commands
-
if "%compiler_name%"=="gcc" (set "generator=MinGW Makefiles")
-
if "%compiler_name%"=="gcc" (set "build=mingw32-make -j4")
-
if "%compiler_name%"=="gcc" (set "test=mingw32-make CTEST_OUTPUT_ON_FAILURE=1 test")
# msvc specific commands
# TODO :)
# add the compiler path if needed
-
if not "%compiler_path%"=="" (set "PATH=%PATH%;%compiler_path%")
# git bash conflicts with MinGW makefiles
-
if "%generator%"=="MinGW Makefiles" (set "PATH=%PATH:C:\Program Files (x86)\Git\bin=%")
build_script
:
-
cmake -G "%generator%" "-DCMAKE_BUILD_TYPE=%variant%" "-DBENCHMARK_ENABLE_SHARED=%shared%"
-
cmd /c "%build%"
test_script
:
-
cmd /c "%test%"
matrix
:
fast_finish
:
true
cache
:
-
C:\mingw-builds
mingw.py
0 → 100644
View file @
65ed470c
This diff is collapsed.
Click to expand it.
src/CMakeLists.txt
View file @
65ed470c
...
...
@@ -32,6 +32,11 @@ set_target_properties(benchmark PROPERTIES
SOVERSION
${
GENERIC_LIB_SOVERSION
}
)
# We need extra libraries on Windows
if
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Windows"
)
target_link_libraries
(
benchmark Shlwapi
)
endif
()
# Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)
install
(
TARGETS benchmark
...
...
src/benchmark.cc
View file @
65ed470c
...
...
@@ -13,9 +13,12 @@
// limitations under the License.
#include "benchmark/benchmark.h"
#include "internal_macros.h"
#include <sys/time.h>
#ifndef OS_WINDOWS
#include <sys/resource.h>
#endif
#include <unistd.h>
#include <cstdlib>
...
...
src/colorprint.cc
View file @
65ed470c
...
...
@@ -19,6 +19,10 @@
#include "commandlineflags.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#include <Windows.h>
#endif
DECLARE_bool
(
color_print
);
namespace
benchmark
{
...
...
src/sleep.cc
View file @
65ed470c
...
...
@@ -19,10 +19,14 @@
#include "internal_macros.h"
#ifdef OS_WINDOWS
#include <Windows.h>
#endif
namespace
benchmark
{
#ifdef OS_WINDOWS
// Window's
_s
leep takes milliseconds argument.
void
SleepForMilliseconds
(
int
milliseconds
)
{
_s
leep
(
milliseconds
);
}
// Window's
S
leep takes milliseconds argument.
void
SleepForMilliseconds
(
int
milliseconds
)
{
S
leep
(
milliseconds
);
}
void
SleepForSeconds
(
double
seconds
)
{
SleepForMilliseconds
(
static_cast
<
int
>
(
kNumMillisPerSecond
*
seconds
));
}
...
...
src/sysinfo.cc
View file @
65ed470c
...
...
@@ -13,13 +13,19 @@
// limitations under the License.
#include "sysinfo.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#include <Shlwapi.h>
#include <Windows.h>
#else
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
#include <sys/sysctl.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <cerrno>
#include <cstdio>
...
...
@@ -227,7 +233,6 @@ void InitializeSystemInfo() {
// TODO: also figure out cpuinfo_num_cpus
#elif defined OS_WINDOWS
#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
;
...
...
@@ -238,7 +243,7 @@ void InitializeSystemInfo() {
SHGetValueA
(
HKEY_LOCAL_MACHINE
,
"HARDWARE
\\
DESCRIPTION
\\
System
\\
CentralProcessor
\\
0"
,
"~MHz"
,
nullptr
,
&
data
,
&
data_size
)))
cpuinfo_cycles_per_second
=
(
int64
)
data
*
(
int64
)(
1000
*
1000
);
// was mhz
cpuinfo_cycles_per_second
=
(
int64
_t
)
data
*
(
int64_t
)(
1000
*
1000
);
// was mhz
else
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
// TODO: also figure out cpuinfo_num_cpus
...
...
@@ -274,9 +279,9 @@ void InitializeSystemInfo() {
}
}
// end namespace
#ifndef OS_WINDOWS
// getrusage() based implementation of MyCPUUsage
static
double
MyCPUUsageRUsage
()
{
#ifndef OS_WINDOWS
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
...
...
@@ -286,8 +291,25 @@ static double MyCPUUsageRUsage() {
}
else
{
return
0.0
;
}
#else
HANDLE
proc
=
GetCurrentProcess
();
FILETIME
creation_time
;
FILETIME
exit_time
;
FILETIME
kernel_time
;
FILETIME
user_time
;
ULARGE_INTEGER
kernel
;
ULARGE_INTEGER
user
;
GetProcessTimes
(
proc
,
&
creation_time
,
&
exit_time
,
&
kernel_time
,
&
user_time
);
kernel
.
HighPart
=
kernel_time
.
dwHighDateTime
;
kernel
.
LowPart
=
kernel_time
.
dwLowDateTime
;
user
.
HighPart
=
user_time
.
dwHighDateTime
;
user
.
LowPart
=
user_time
.
dwLowDateTime
;
return
(
static_cast
<
double
>
(
kernel
.
QuadPart
)
+
static_cast
<
double
>
(
user
.
QuadPart
))
/
1.0E-7
;
#endif // OS_WINDOWS
}
#ifndef OS_WINDOWS
static
bool
MyCPUUsageCPUTimeNsLocked
(
double
*
cputime
)
{
static
int
cputime_fd
=
-
1
;
if
(
cputime_fd
==
-
1
)
{
...
...
@@ -313,8 +335,10 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
*
cputime
=
static_cast
<
double
>
(
result
)
/
1e9
;
return
true
;
}
#endif // OS_WINDOWS
double
MyCPUUsage
()
{
#ifndef OS_WINDOWS
{
std
::
lock_guard
<
std
::
mutex
>
l
(
cputimens_mutex
);
static
bool
use_cputime_ns
=
true
;
...
...
@@ -328,10 +352,12 @@ double MyCPUUsage() {
use_cputime_ns
=
false
;
}
}
#endif // OS_WINDOWS
return
MyCPUUsageRUsage
();
}
double
ChildrenCPUUsage
()
{
#ifndef OS_WINDOWS
struct
rusage
ru
;
if
(
getrusage
(
RUSAGE_CHILDREN
,
&
ru
)
==
0
)
{
return
(
static_cast
<
double
>
(
ru
.
ru_utime
.
tv_sec
)
+
...
...
@@ -341,8 +367,11 @@ double ChildrenCPUUsage() {
}
else
{
return
0.0
;
}
}
#else
// TODO: Not sure what this even means on Windows
return
0.0
;
#endif // OS_WINDOWS
}
double
CyclesPerSecond
(
void
)
{
std
::
call_once
(
cpuinfo_init
,
InitializeSystemInfo
);
...
...
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