Commit 65ed470c by Dominic Hamon

Merge pull request #64 from mattyclarkson/nt

MinGW support
parents 80514584 36d7dc67
*.a
*.so
*.so.?*
*.dll
*.exe
*.dylib
*.cmake
!/cmake/*.cmake
*~
*.pyc
__pycache__
# cmake files.
/Testing
......
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
This diff is collapsed. Click to expand it.
......@@ -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
......
......@@ -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>
......
......@@ -19,6 +19,10 @@
#include "commandlineflags.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#include <Windows.h>
#endif
DECLARE_bool(color_print);
namespace benchmark {
......
......@@ -19,10 +19,14 @@
#include "internal_macros.h"
#ifdef OS_WINDOWS
#include <Windows.h>
#endif
namespace benchmark {
#ifdef OS_WINDOWS
// Window's _sleep takes milliseconds argument.
void SleepForMilliseconds(int milliseconds) { _sleep(milliseconds); }
// Window's Sleep takes milliseconds argument.
void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
void SleepForSeconds(double seconds) {
SleepForMilliseconds(static_cast<int>(kNumMillisPerSecond * seconds));
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment