-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Port to Windows 7/Visual Studio 2013 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e5efd2b
0933426
c5a6819
bdb0ba1
2579604
575a2cb
7f93a3b
5454072
c6ce76b
9e0db00
46f0680
0839a6d
7b145d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.sln merge=union | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; | |
|
||
#define arraysize(array) (sizeof(ArraySizeHelper(array))) | ||
|
||
// If you include both this library and glog, glog must come first. | ||
#ifndef CHECK | ||
#define CHECK(b) \ | ||
do { \ | ||
if (!(b)) assert(false); \ | ||
|
@@ -45,7 +47,15 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; | |
#define CHECK_LE(a, b) CHECK((a) <= (b)) | ||
#define CHECK_GT(a, b) CHECK((a) > (b)) | ||
#define CHECK_LT(a, b) CHECK((a) < (b)) | ||
#endif | ||
|
||
#ifdef _MSC_VER | ||
#define ATTRIBUTE_UNUSED | ||
#define ATTRIBUTE_ALWAYS_INLINE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be defined to __forceinline, or is the order different between this and gcc attributes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax is different: |
||
#define HAVE_ATTRIBUTE_ALWAYS_INLINE 0 | ||
#define ATTRIBUTE_NOINLINE | ||
#define HAVE_ATTRIBUTE_NOINLINE 0 | ||
#else | ||
// | ||
// Prevent the compiler from complaining about or optimizing away variables | ||
// that appear unused. | ||
|
@@ -58,5 +68,6 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; | |
#define HAVE_ATTRIBUTE_ALWAYS_INLINE 1 | ||
#define ATTRIBUTE_NOINLINE __attribute__((noinline)) | ||
#define HAVE_ATTRIBUTE_NOINLINE 1 | ||
#endif | ||
|
||
#endif // BENCHMARK_MACROS_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* Copyright (c) 2008, Google Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google Inc. nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* --- | ||
* Author: Craig Silverstein | ||
* | ||
* These are some portability typedefs and defines to make it a bit | ||
* easier to compile this code under VC++. | ||
* | ||
* Several of these are taken from glib: | ||
* http://developer.gnome.org/doc/API/glib/glib-windows-compatability-functions.html | ||
*/ | ||
|
||
#ifndef BENCHMARK_PORT_H_ | ||
#define BENCHMARK_PORT_H_ | ||
|
||
#ifdef _WIN32 | ||
|
||
#define NOMINMAX | ||
|
||
#ifdef _MSC_VER | ||
#define COMPILER_MSVC | ||
#endif | ||
|
||
#include <windows.h> | ||
#include <winsock.h> /* for timeval */ | ||
#include <stdio.h> /* read in vsnprintf decl. before redifining it */ | ||
#include <time.h> /* for localtime_s() */ | ||
#include <Shlwapi.h> | ||
|
||
/* 4244: otherwise we get problems when substracting two size_t's to an int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should be able to remove a bunch of these given that we don't compile nearly the same set of things that Craig Silverstein had in mind when he wrote this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have trimmed down |
||
* 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() | ||
*/ | ||
#pragma warning(disable:4244 4996) | ||
|
||
/* We can't just use _vsnprintf and _snprintf as drop-in-replacements, | ||
* because they don't always NUL-terminate. :-( We also can't use the | ||
* name vsnprintf, since windows defines that (but not snprintf (!)). | ||
*/ | ||
extern int snprintf(char *str, size_t size, | ||
const char *format, ...); | ||
|
||
inline struct tm* localtime_r(const time_t* timep, struct tm* result) { | ||
localtime_s(result, timep); | ||
return result; | ||
} | ||
|
||
inline struct tm* gmtime_r(const time_t *timer, struct tm *result) { | ||
errno_t e = gmtime_s(result, timer); | ||
return result; | ||
} | ||
|
||
extern int gettimeofday(struct timeval *tv, void* tz); | ||
|
||
// The rest of this file is a poor man's config.h. | ||
|
||
#undef HAVE_GNUREGEX_H | ||
#undef HAVE_PTHREAD_H | ||
#define HAVE_REGEX | ||
#undef HAVE_REGEX_H | ||
#undef HAVE_SEMAPHORE_H | ||
#undef HAVE_SYS_RESOURCE_H | ||
#undef HAVE_SYS_SYSCTL_H | ||
#undef HAVE_SYS_TIME_H | ||
#undef HAVE_UNISTD_H | ||
|
||
#else /* _WIN32 */ | ||
|
||
#undef HAVE_GNUREGEX_H | ||
#define HAVE_PTHREAD_H | ||
#undef HAVE_REGEX | ||
#define HAVE_REGEX_H | ||
#define HAVE_SEMAPHORE_H | ||
#define HAVE_SYS_RESOURCE_H | ||
#define HAVE_SYS_SYSCTL_H | ||
#define HAVE_SYS_TIME_H | ||
#define HAVE_UNISTD_H | ||
|
||
#endif /* _WIN32 */ | ||
|
||
#endif /* BENCHMARK_PORT_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,19 @@ | |
#include "colorprint.h" | ||
#include "commandlineflags.h" | ||
#include "mutex_lock.h" | ||
#include "pthread.h" | ||
#include "re.h" | ||
#include "sleep.h" | ||
#include "stat.h" | ||
#include "sysinfo.h" | ||
#include "walltime.h" | ||
|
||
#if defined HAVE_SYS_TIME_H | ||
#include <sys/time.h> | ||
#include <pthread.h> | ||
#endif | ||
#if defined HAVE_SEMAPHORE_H | ||
#include <semaphore.h> | ||
#endif | ||
#include <string.h> | ||
|
||
#include <algorithm> | ||
|
@@ -1151,7 +1155,18 @@ bool State::FinishInterval() { | |
const double accumulated_time = walltime::Now() - start_time_; | ||
const double total_overhead = overhead * iterations_; | ||
CHECK_LT(pause_real_time_, accumulated_time); | ||
#if defined OS_WINDOWS | ||
// The clock accuracy is poor on Windows. | ||
if (pause_real_time_ + total_overhead >= accumulated_time) { | ||
fprintf(stderr, | ||
"Overhead measurement flawed: test ran faster (%f s) than expected " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there might be better advice here .. set a minimum time using --benchmark_min_time ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, this doesn't help, even with a very long --benchmark_min_time. I'll need to rethink the way overhead is measured on Windows because the real-time numbers look semi-random at the moment (but the CPU times are good, which is what I am after at this point). |
||
"overhead (%f s). Try again and be aware that elapsed times may " | ||
"be unreliable.\n", | ||
accumulated_time, pause_real_time_ + total_overhead); | ||
} | ||
#else | ||
CHECK_LT(pause_real_time_ + total_overhead, accumulated_time); | ||
#endif | ||
data.real_accumulated_time = | ||
accumulated_time - (pause_real_time_ + total_overhead); | ||
data.cpu_accumulated_time = (MyCPUUsage() + ChildrenCPUUsage()) - | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* Copyright (c) 2008, Google Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google Inc. nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* --- | ||
* Author: Craig Silverstein | ||
* Copied from google-perftools and modified by Shinichiro Hamaji | ||
*/ | ||
|
||
#ifndef _WIN32 | ||
# error You should only be including windows/port.cc in a windows environment! | ||
#endif | ||
|
||
#include "benchmark/port.h" | ||
|
||
#include <stdarg.h> // for va_list, va_start, va_end | ||
#include <stdint.h> | ||
|
||
// This calls the windows _vsnprintf, but always NUL-terminate. | ||
int snprintf(char *str, size_t size, const char *format, ...) { | ||
va_list ap; | ||
va_start(ap, format); | ||
const int r = vsnprintf(str, size, format, ap); | ||
va_end(ap); | ||
return r; | ||
} | ||
|
||
// Based on: https://code.google.com/p/google-glog/source/browse/trunk/src/utilities.cc | ||
int gettimeofday(struct timeval *tv, void* tz) { | ||
#define EPOCHFILETIME (116444736000000000ULL) | ||
FILETIME ft; | ||
LARGE_INTEGER li; | ||
uint64_t tt; | ||
|
||
// This seems to return time with a granularity of 10 ms on Windows 7. Sigh. | ||
GetSystemTimeAsFileTime(&ft); | ||
li.LowPart = ft.dwLowDateTime; | ||
li.HighPart = ft.dwHighDateTime; | ||
tt = (li.QuadPart - EPOCHFILETIME) / 10; | ||
tv->tv_sec = tt / 1000000; | ||
tv->tv_usec = tt % 1000000; | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef BENCHMARK_PTHREAD_H_ | ||
#define BENCHMARK_PTHREAD_H_ | ||
|
||
#include "benchmark/port.h" | ||
|
||
#if defined HAVE_PTHREAD_H | ||
#include <pthread.h> | ||
#endif | ||
|
||
#if defined OS_WINDOWS | ||
#include "windows/pthread.h" | ||
#endif | ||
|
||
#endif // BENCHMARK_PTHREAD_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ namespace benchmark { | |
Regex::Regex() : init_(false) { } | ||
|
||
bool Regex::Init(const std::string& spec, std::string* error) { | ||
#if defined HAVE_REGEX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please pull this out. i actually had some issues when i tried using std::regex for this project as the matching wasn't quite the same. I don't remember the details, i'm afraid, but i'd want much more testing before making this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nominally going to be addressed by #30, but I would want to merge that (and test it) before moving forward with the rest of this patch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dominichamon: I don't understand why you want it pulled out. There is just no alternative on Windows. We can argue whether the C++11 library is the right thing to use in general (that's the topic of #30) but there is no other way to do it on Windows. Even if the regex matching is not quite the same, it's probably no big deal, it's just for a flag anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the changes here are confined entirely to these two files, you would be able to revert the changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the point: I don't think that the changes will be restricted to these two files. There is no reason to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we won't just use regex directly. we need to support older compilers that don't have it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, this discussion is superseded by #41 anyway. |
||
re_ = std::regex(spec, std::regex::extended | std::regex::nosubs); | ||
#else | ||
int ec = regcomp(&re_, spec.c_str(), REG_EXTENDED | REG_NOSUB); | ||
if (ec != 0) { | ||
if (error) { | ||
|
@@ -38,13 +41,16 @@ bool Regex::Init(const std::string& spec, std::string* error) { | |
return false; | ||
} | ||
|
||
#endif | ||
init_ = true; | ||
return true; | ||
} | ||
|
||
Regex::~Regex() { | ||
if (init_) { | ||
#if !defined HAVE_REGEX | ||
regfree(&re_); | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -53,7 +59,11 @@ bool Regex::Match(const std::string& str) { | |
return false; | ||
} | ||
|
||
#if defined HAVE_REGEX | ||
return std::regex_search(str, re_); | ||
#else | ||
return regexec(&re_, str.c_str(), 0, NULL, 0) == 0; | ||
#endif | ||
} | ||
|
||
} // end namespace benchmark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be the only one we care about, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2579604.