mirror of https://github.com/google/benchmark.git
Fixed build issues on window (#1449)
* Fixed build issues on window - Added missing dlimport/export attributes in function definitions. (They are needed in both decls and defs) - Removed dlimport/dlexprt attribute in private field. (global_context is not exported anywhere). * fixed incorrect include path * undo changes w.r.t HelperPrintf * removed forward decl of private variable - instead, introduce a getter and use it. * Removed forward decl from benchmark_gtest too Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
This commit is contained in:
parent
7d48eff772
commit
1cca1d091c
|
@ -417,6 +417,8 @@ class Benchmark;
|
||||||
class BenchmarkImp;
|
class BenchmarkImp;
|
||||||
class BenchmarkFamilies;
|
class BenchmarkFamilies;
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext();
|
||||||
|
|
||||||
BENCHMARK_EXPORT
|
BENCHMARK_EXPORT
|
||||||
void UseCharPointer(char const volatile*);
|
void UseCharPointer(char const volatile*);
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,11 @@ BM_DEFINE_int32(v, 0);
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
BENCHMARK_EXPORT std::map<std::string, std::string>* global_context = nullptr;
|
std::map<std::string, std::string>* global_context = nullptr;
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext() {
|
||||||
|
return global_context;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: wouldn't LTO mess this up?
|
// FIXME: wouldn't LTO mess this up?
|
||||||
void UseCharPointer(char const volatile*) {}
|
void UseCharPointer(char const volatile*) {}
|
||||||
|
|
|
@ -51,6 +51,7 @@ std::string join(char delimiter, const Ts&... ts) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
std::string BenchmarkName::str() const {
|
std::string BenchmarkName::str() const {
|
||||||
return join('/', function_name, args, min_time, min_warmup_time, iterations,
|
return join('/', function_name, args, min_time, min_warmup_time, iterations,
|
||||||
repetitions, time_type, threads);
|
repetitions, time_type, threads);
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace internal {
|
||||||
|
|
||||||
static AbortHandlerT* handler = &std::abort;
|
static AbortHandlerT* handler = &std::abort;
|
||||||
|
|
||||||
AbortHandlerT*& GetAbortHandler() { return handler; }
|
BENCHMARK_EXPORT AbortHandlerT*& GetAbortHandler() { return handler; }
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace benchmark
|
} // namespace benchmark
|
||||||
|
|
|
@ -121,12 +121,14 @@ static std::string FlagToEnvVar(const char* flag) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool BoolFromEnv(const char* flag, bool default_val) {
|
bool BoolFromEnv(const char* flag, bool default_val) {
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const value_str = getenv(env_var.c_str());
|
const char* const value_str = getenv(env_var.c_str());
|
||||||
return value_str == nullptr ? default_val : IsTruthyFlagValue(value_str);
|
return value_str == nullptr ? default_val : IsTruthyFlagValue(value_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
int32_t Int32FromEnv(const char* flag, int32_t default_val) {
|
int32_t Int32FromEnv(const char* flag, int32_t default_val) {
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const value_str = getenv(env_var.c_str());
|
const char* const value_str = getenv(env_var.c_str());
|
||||||
|
@ -139,6 +141,7 @@ int32_t Int32FromEnv(const char* flag, int32_t default_val) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
double DoubleFromEnv(const char* flag, double default_val) {
|
double DoubleFromEnv(const char* flag, double default_val) {
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const value_str = getenv(env_var.c_str());
|
const char* const value_str = getenv(env_var.c_str());
|
||||||
|
@ -151,12 +154,14 @@ double DoubleFromEnv(const char* flag, double default_val) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
const char* StringFromEnv(const char* flag, const char* default_val) {
|
const char* StringFromEnv(const char* flag, const char* default_val) {
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const value = getenv(env_var.c_str());
|
const char* const value = getenv(env_var.c_str());
|
||||||
return value == nullptr ? default_val : value;
|
return value == nullptr ? default_val : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
std::map<std::string, std::string> KvPairsFromEnv(
|
std::map<std::string, std::string> KvPairsFromEnv(
|
||||||
const char* flag, std::map<std::string, std::string> default_val) {
|
const char* flag, std::map<std::string, std::string> default_val) {
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
|
@ -201,6 +206,7 @@ const char* ParseFlagValue(const char* str, const char* flag,
|
||||||
return flag_end + 1;
|
return flag_end + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
|
bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
|
||||||
// Gets the value of the flag as a string.
|
// Gets the value of the flag as a string.
|
||||||
const char* const value_str = ParseFlagValue(str, flag, true);
|
const char* const value_str = ParseFlagValue(str, flag, true);
|
||||||
|
@ -213,6 +219,7 @@ bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
|
bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
|
||||||
// Gets the value of the flag as a string.
|
// Gets the value of the flag as a string.
|
||||||
const char* const value_str = ParseFlagValue(str, flag, false);
|
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||||
|
@ -225,6 +232,7 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
|
bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
|
||||||
// Gets the value of the flag as a string.
|
// Gets the value of the flag as a string.
|
||||||
const char* const value_str = ParseFlagValue(str, flag, false);
|
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||||
|
@ -237,6 +245,7 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
||||||
// Gets the value of the flag as a string.
|
// Gets the value of the flag as a string.
|
||||||
const char* const value_str = ParseFlagValue(str, flag, false);
|
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||||
|
@ -248,6 +257,7 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ParseKeyValueFlag(const char* str, const char* flag,
|
bool ParseKeyValueFlag(const char* str, const char* flag,
|
||||||
std::map<std::string, std::string>* value) {
|
std::map<std::string, std::string>* value) {
|
||||||
const char* const value_str = ParseFlagValue(str, flag, false);
|
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||||
|
@ -263,10 +273,12 @@ bool ParseKeyValueFlag(const char* str, const char* flag,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool IsFlag(const char* str, const char* flag) {
|
bool IsFlag(const char* str, const char* flag) {
|
||||||
return (ParseFlagValue(str, flag, true) != nullptr);
|
return (ParseFlagValue(str, flag, true) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool IsTruthyFlagValue(const std::string& value) {
|
bool IsTruthyFlagValue(const std::string& value) {
|
||||||
if (value.size() == 1) {
|
if (value.size() == 1) {
|
||||||
char v = value[0];
|
char v = value[0];
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool ConsoleReporter::ReportContext(const Context& context) {
|
bool ConsoleReporter::ReportContext(const Context& context) {
|
||||||
name_field_width_ = context.name_field_width;
|
name_field_width_ = context.name_field_width;
|
||||||
printed_header_ = false;
|
printed_header_ = false;
|
||||||
|
@ -52,6 +53,7 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
void ConsoleReporter::PrintHeader(const Run& run) {
|
void ConsoleReporter::PrintHeader(const Run& run) {
|
||||||
std::string str =
|
std::string str =
|
||||||
FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
||||||
|
@ -69,6 +71,7 @@ void ConsoleReporter::PrintHeader(const Run& run) {
|
||||||
GetOutputStream() << line << "\n" << str << "\n" << line << "\n";
|
GetOutputStream() << line << "\n" << str << "\n" << line << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
|
void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
|
||||||
for (const auto& run : reports) {
|
for (const auto& run : reports) {
|
||||||
// print the header:
|
// print the header:
|
||||||
|
@ -120,6 +123,7 @@ static std::string FormatTime(double time) {
|
||||||
return FormatString("%10.0f", time);
|
return FormatString("%10.0f", time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
void ConsoleReporter::PrintRunData(const Run& result) {
|
void ConsoleReporter::PrintRunData(const Run& result) {
|
||||||
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
|
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
|
||||||
auto& Out = GetOutputStream();
|
auto& Out = GetOutputStream();
|
||||||
|
|
|
@ -52,11 +52,13 @@ std::string CsvEscape(const std::string& s) {
|
||||||
return '"' + tmp + '"';
|
return '"' + tmp + '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
bool CSVReporter::ReportContext(const Context& context) {
|
bool CSVReporter::ReportContext(const Context& context) {
|
||||||
PrintBasicContext(&GetErrorStream(), context);
|
PrintBasicContext(&GetErrorStream(), context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
void CSVReporter::ReportRuns(const std::vector<Run>& reports) {
|
void CSVReporter::ReportRuns(const std::vector<Run>& reports) {
|
||||||
std::ostream& Out = GetOutputStream();
|
std::ostream& Out = GetOutputStream();
|
||||||
|
|
||||||
|
@ -103,6 +105,7 @@ void CSVReporter::ReportRuns(const std::vector<Run>& reports) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BENCHMARK_EXPORT
|
||||||
void CSVReporter::PrintRunData(const Run& run) {
|
void CSVReporter::PrintRunData(const Run& run) {
|
||||||
std::ostream& Out = GetOutputStream();
|
std::ostream& Out = GetOutputStream();
|
||||||
Out << CsvEscape(run.benchmark_name()) << ",";
|
Out << CsvEscape(run.benchmark_name()) << ",";
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
namespace internal {
|
|
||||||
extern std::map<std::string, std::string>* global_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string StrEscape(const std::string& s) {
|
std::string StrEscape(const std::string& s) {
|
||||||
|
@ -178,8 +174,11 @@ bool JSONReporter::ReportContext(const Context& context) {
|
||||||
#endif
|
#endif
|
||||||
out << indent << FormatKV("library_build_type", build_type);
|
out << indent << FormatKV("library_build_type", build_type);
|
||||||
|
|
||||||
if (internal::global_context != nullptr) {
|
std::map<std::string, std::string>* global_context =
|
||||||
for (const auto& kv : *internal::global_context) {
|
internal::GetGlobalContext();
|
||||||
|
|
||||||
|
if (global_context != nullptr) {
|
||||||
|
for (const auto& kv : *global_context) {
|
||||||
out << ",\n";
|
out << ",\n";
|
||||||
out << indent << FormatKV(kv.first, kv.second);
|
out << indent << FormatKV(kv.first, kv.second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,6 @@
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
namespace internal {
|
|
||||||
extern std::map<std::string, std::string> *global_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
BenchmarkReporter::BenchmarkReporter()
|
BenchmarkReporter::BenchmarkReporter()
|
||||||
: output_stream_(&std::cout), error_stream_(&std::cerr) {}
|
: output_stream_(&std::cout), error_stream_(&std::cerr) {}
|
||||||
|
@ -67,8 +64,11 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
|
||||||
Out << "\n";
|
Out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (internal::global_context != nullptr) {
|
std::map<std::string, std::string> *global_context =
|
||||||
for (const auto &kv : *internal::global_context) {
|
internal::GetGlobalContext();
|
||||||
|
|
||||||
|
if (global_context != nullptr) {
|
||||||
|
for (const auto &kv : *global_context) {
|
||||||
Out << kv.first << ": " << kv.second << "\n";
|
Out << kv.first << ": " << kv.second << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
BENCHMARK_EXPORT extern std::map<std::string, std::string>* global_context;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -134,6 +133,8 @@ TEST(AddRangeTest, Simple8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AddCustomContext, Simple) {
|
TEST(AddCustomContext, Simple) {
|
||||||
|
std::map<std::string, std::string> *&global_context =
|
||||||
|
internal::GetGlobalContext();
|
||||||
EXPECT_THAT(global_context, nullptr);
|
EXPECT_THAT(global_context, nullptr);
|
||||||
|
|
||||||
AddCustomContext("foo", "bar");
|
AddCustomContext("foo", "bar");
|
||||||
|
@ -148,6 +149,8 @@ TEST(AddCustomContext, Simple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AddCustomContext, DuplicateKey) {
|
TEST(AddCustomContext, DuplicateKey) {
|
||||||
|
std::map<std::string, std::string> *&global_context =
|
||||||
|
internal::GetGlobalContext();
|
||||||
EXPECT_THAT(global_context, nullptr);
|
EXPECT_THAT(global_context, nullptr);
|
||||||
|
|
||||||
AddCustomContext("foo", "bar");
|
AddCustomContext("foo", "bar");
|
||||||
|
|
Loading…
Reference in New Issue