mirror of
https://github.com/google/benchmark.git
synced 2025-03-28 04:50:34 +08:00
clang-format Google on {src/,include/} (#1280)
This commit is contained in:
parent
431abd149f
commit
fcef4fb669
@ -245,8 +245,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
|
|||||||
#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
|
#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
|
||||||
_Pragma("GCC diagnostic push") \
|
_Pragma("GCC diagnostic push") \
|
||||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
||||||
#define BENCHMARK_RESTORE_DEPRECATED_WARNING \
|
#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop")
|
||||||
_Pragma("GCC diagnostic pop")
|
|
||||||
#else
|
#else
|
||||||
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
|
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
|
||||||
#define BENCHMARK_DEPRECATED_MSG(msg)
|
#define BENCHMARK_DEPRECATED_MSG(msg)
|
||||||
@ -1440,11 +1439,7 @@ struct CPUInfo {
|
|||||||
int num_sharing;
|
int num_sharing;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Scaling {
|
enum Scaling { UNKNOWN, ENABLED, DISABLED };
|
||||||
UNKNOWN,
|
|
||||||
ENABLED,
|
|
||||||
DISABLED
|
|
||||||
};
|
|
||||||
|
|
||||||
int num_cpus;
|
int num_cpus;
|
||||||
Scaling scaling;
|
Scaling scaling;
|
||||||
@ -1704,7 +1699,6 @@ class BENCHMARK_DEPRECATED_MSG(
|
|||||||
std::set<std::string> user_counter_names_;
|
std::set<std::string> user_counter_names_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline const char* GetTimeUnitString(TimeUnit unit) {
|
inline const char* GetTimeUnitString(TimeUnit unit) {
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case kSecond:
|
case kSecond:
|
||||||
@ -1745,8 +1739,7 @@ inline double GetTimeUnitMultiplier(TimeUnit unit) {
|
|||||||
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi);
|
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi);
|
||||||
|
|
||||||
// Creates a list of integer values for the given range and step.
|
// Creates a list of integer values for the given range and step.
|
||||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
|
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit, int step);
|
||||||
int step);
|
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace benchmark
|
||||||
|
|
||||||
|
@ -617,9 +617,7 @@ void Initialize(int* argc, char** argv) {
|
|||||||
internal::LogLevel() = FLAGS_v;
|
internal::LogLevel() = FLAGS_v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() { delete internal::global_context; }
|
||||||
delete internal::global_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReportUnrecognizedArguments(int argc, char** argv) {
|
bool ReportUnrecognizedArguments(int argc, char** argv) {
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
@ -466,8 +466,7 @@ std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi) {
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
|
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit, int step) {
|
||||||
int step) {
|
|
||||||
BM_CHECK_LE(start, limit);
|
BM_CHECK_LE(start, limit);
|
||||||
std::vector<int64_t> args;
|
std::vector<int64_t> args;
|
||||||
for (int64_t arg = start; arg <= limit; arg += step) {
|
for (int64_t arg = start; arg <= limit; arg += step) {
|
||||||
|
@ -12,8 +12,8 @@ namespace internal {
|
|||||||
// Append the powers of 'mult' in the closed interval [lo, hi].
|
// Append the powers of 'mult' in the closed interval [lo, hi].
|
||||||
// Returns iterator to the start of the inserted range.
|
// Returns iterator to the start of the inserted range.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::vector<T>::iterator
|
typename std::vector<T>::iterator AddPowers(std::vector<T>* dst, T lo, T hi,
|
||||||
AddPowers(std::vector<T>* dst, T lo, T hi, int mult) {
|
int mult) {
|
||||||
BM_CHECK_GE(lo, 0);
|
BM_CHECK_GE(lo, 0);
|
||||||
BM_CHECK_GE(hi, lo);
|
BM_CHECK_GE(hi, lo);
|
||||||
BM_CHECK_GE(mult, 2);
|
BM_CHECK_GE(mult, 2);
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#include "internal_macros.h"
|
#include "internal_macros.h"
|
||||||
|
|
||||||
#ifdef BENCHMARK_OS_WINDOWS
|
#ifdef BENCHMARK_OS_WINDOWS
|
||||||
#include <windows.h>
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif // BENCHMARK_OS_WINDOWS
|
#endif // BENCHMARK_OS_WINDOWS
|
||||||
|
@ -248,8 +248,7 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseKeyValueFlag(
|
bool ParseKeyValueFlag(const char* str, const char* flag,
|
||||||
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);
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
// Source project : https://github.com/ismaelJimenez/cpp.leastsq
|
// Source project : https://github.com/ismaelJimenez/cpp.leastsq
|
||||||
// Adapted to be used with google benchmark
|
// Adapted to be used with google benchmark
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "complexity.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "benchmark/benchmark.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "complexity.h"
|
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
|||||||
GetErrorStream()
|
GetErrorStream()
|
||||||
<< "Color printing is only supported for stdout on windows."
|
<< "Color printing is only supported for stdout on windows."
|
||||||
" Disabling color printing\n";
|
" Disabling color printing\n";
|
||||||
output_options_ = static_cast< OutputOptions >(output_options_ & ~OO_Color);
|
output_options_ = static_cast<OutputOptions>(output_options_ & ~OO_Color);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -53,11 +53,12 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleReporter::PrintHeader(const Run& run) {
|
void ConsoleReporter::PrintHeader(const Run& run) {
|
||||||
std::string str = FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
std::string str =
|
||||||
|
FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
||||||
"Benchmark", "Time", "CPU", "Iterations");
|
"Benchmark", "Time", "CPU", "Iterations");
|
||||||
if(!run.counters.empty()) {
|
if (!run.counters.empty()) {
|
||||||
if(output_options_ & OO_Tabular) {
|
if (output_options_ & OO_Tabular) {
|
||||||
for(auto const& c : run.counters) {
|
for (auto const& c : run.counters) {
|
||||||
str += FormatString(" %10s", c.first.c_str());
|
str += FormatString(" %10s", c.first.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -97,7 +98,6 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::string FormatTime(double time) {
|
static std::string FormatTime(double time) {
|
||||||
// Align decimal places...
|
// Align decimal places...
|
||||||
if (time < 1.0) {
|
if (time < 1.0) {
|
||||||
@ -115,8 +115,9 @@ static std::string FormatTime(double time) {
|
|||||||
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();
|
||||||
PrinterFn* printer = (output_options_ & OO_Color) ?
|
PrinterFn* printer = (output_options_ & OO_Color)
|
||||||
static_cast<PrinterFn*>(ColorPrintf) : IgnoreColorPrint;
|
? static_cast<PrinterFn*>(ColorPrintf)
|
||||||
|
: IgnoreColorPrint;
|
||||||
auto name_color =
|
auto name_color =
|
||||||
(result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN;
|
(result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN;
|
||||||
printer(Out, name_color, "%-*s ", name_field_width_,
|
printer(Out, name_color, "%-*s ", name_field_width_,
|
||||||
@ -134,19 +135,18 @@ void ConsoleReporter::PrintRunData(const Run& result) {
|
|||||||
const std::string real_time_str = FormatTime(real_time);
|
const std::string real_time_str = FormatTime(real_time);
|
||||||
const std::string cpu_time_str = FormatTime(cpu_time);
|
const std::string cpu_time_str = FormatTime(cpu_time);
|
||||||
|
|
||||||
|
|
||||||
if (result.report_big_o) {
|
if (result.report_big_o) {
|
||||||
std::string big_o = GetBigOString(result.complexity);
|
std::string big_o = GetBigOString(result.complexity);
|
||||||
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ", real_time, big_o.c_str(),
|
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ", real_time,
|
||||||
cpu_time, big_o.c_str());
|
big_o.c_str(), cpu_time, big_o.c_str());
|
||||||
} else if (result.report_rms) {
|
} else if (result.report_rms) {
|
||||||
printer(Out, COLOR_YELLOW, "%10.0f %-4s %10.0f %-4s ", real_time * 100, "%",
|
printer(Out, COLOR_YELLOW, "%10.0f %-4s %10.0f %-4s ", real_time * 100, "%",
|
||||||
cpu_time * 100, "%");
|
cpu_time * 100, "%");
|
||||||
} else if (result.run_type != Run::RT_Aggregate ||
|
} else if (result.run_type != Run::RT_Aggregate ||
|
||||||
result.aggregate_unit == StatisticUnit::kTime) {
|
result.aggregate_unit == StatisticUnit::kTime) {
|
||||||
const char* timeLabel = GetTimeUnitString(result.time_unit);
|
const char* timeLabel = GetTimeUnitString(result.time_unit);
|
||||||
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(), timeLabel,
|
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(),
|
||||||
cpu_time_str.c_str(), timeLabel);
|
timeLabel, cpu_time_str.c_str(), timeLabel);
|
||||||
} else {
|
} else {
|
||||||
assert(result.aggregate_unit == StatisticUnit::kPercentage);
|
assert(result.aggregate_unit == StatisticUnit::kPercentage);
|
||||||
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ",
|
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ",
|
||||||
@ -159,8 +159,8 @@ void ConsoleReporter::PrintRunData(const Run& result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& c : result.counters) {
|
for (auto& c : result.counters) {
|
||||||
const std::size_t cNameLen = std::max(std::string::size_type(10),
|
const std::size_t cNameLen =
|
||||||
c.first.length());
|
std::max(std::string::size_type(10), c.first.length());
|
||||||
std::string s;
|
std::string s;
|
||||||
const char* unit = "";
|
const char* unit = "";
|
||||||
if (result.run_type == Run::RT_Aggregate &&
|
if (result.run_type == Run::RT_Aggregate &&
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
|
||||||
#include "complexity.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -22,7 +19,9 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "benchmark/benchmark.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
#include "complexity.h"
|
||||||
#include "string_util.h"
|
#include "string_util.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
@ -37,13 +36,17 @@ std::vector<std::string> elements = {
|
|||||||
"error_occurred", "error_message"};
|
"error_occurred", "error_message"};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::string CsvEscape(const std::string & s) {
|
std::string CsvEscape(const std::string& s) {
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
tmp.reserve(s.size() + 2);
|
tmp.reserve(s.size() + 2);
|
||||||
for (char c : s) {
|
for (char c : s) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '"' : tmp += "\"\""; break;
|
case '"':
|
||||||
default : tmp += c; break;
|
tmp += "\"\"";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tmp += c;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '"' + tmp + '"';
|
return '"' + tmp + '"';
|
||||||
|
@ -317,6 +317,7 @@ void JSONReporter::PrintRunData(Run const& run) {
|
|||||||
out << '\n';
|
out << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
const int64_t MemoryManager::TombstoneValue = std::numeric_limits<int64_t>::max();
|
const int64_t MemoryManager::TombstoneValue =
|
||||||
|
std::numeric_limits<int64_t>::max();
|
||||||
|
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
|
@ -49,7 +49,7 @@ PerfCounters PerfCounters::Create(
|
|||||||
const int mode = PFM_PLM3; // user mode only
|
const int mode = PFM_PLM3; // user mode only
|
||||||
for (size_t i = 0; i < counter_names.size(); ++i) {
|
for (size_t i = 0; i < counter_names.size(); ++i) {
|
||||||
const bool is_first = i == 0;
|
const bool is_first = i == 0;
|
||||||
struct perf_event_attr attr{};
|
struct perf_event_attr attr {};
|
||||||
attr.size = sizeof(attr);
|
attr.size = sizeof(attr);
|
||||||
const int group_id = !is_first ? counter_ids[0] : -1;
|
const int group_id = !is_first ? counter_ids[0] : -1;
|
||||||
const auto& name = counter_names[i];
|
const auto& name = counter_names[i];
|
||||||
|
@ -12,23 +12,21 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "benchmark/benchmark.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "string_util.h"
|
#include "string_util.h"
|
||||||
|
#include "timers.h"
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
extern std::map<std::string, std::string>* global_context;
|
extern std::map<std::string, std::string> *global_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
BenchmarkReporter::BenchmarkReporter()
|
BenchmarkReporter::BenchmarkReporter()
|
||||||
@ -70,7 +68,7 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (internal::global_context != nullptr) {
|
if (internal::global_context != nullptr) {
|
||||||
for (const auto& kv: *internal::global_context) {
|
for (const auto &kv : *internal::global_context) {
|
||||||
Out << kv.first << ": " << kv.second << "\n";
|
Out << kv.first << ": " << kv.second << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,7 @@ void SleepForMicroseconds(int microseconds) {
|
|||||||
// argument is greater than 1000000.
|
// argument is greater than 1000000.
|
||||||
div_t sleepTime = div(microseconds, kNumMicrosPerSecond);
|
div_t sleepTime = div(microseconds, kNumMicrosPerSecond);
|
||||||
int seconds = sleepTime.quot;
|
int seconds = sleepTime.quot;
|
||||||
while (seconds != 0)
|
while (seconds != 0) seconds = sleep(seconds);
|
||||||
seconds = sleep(seconds);
|
|
||||||
while (usleep(sleepTime.rem) == -1 && errno == EINTR)
|
while (usleep(sleepTime.rem) == -1 && errno == EINTR)
|
||||||
;
|
;
|
||||||
#else
|
#else
|
||||||
|
@ -13,15 +13,16 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "statistics.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "benchmark/benchmark.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "statistics.h"
|
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
|
||||||
|
@ -198,11 +198,10 @@ unsigned long stoul(const std::string& str, size_t* pos, int base) {
|
|||||||
|
|
||||||
/* Check for errors and return */
|
/* Check for errors and return */
|
||||||
if (strtoulErrno == ERANGE) {
|
if (strtoulErrno == ERANGE) {
|
||||||
throw std::out_of_range(
|
throw std::out_of_range("stoul failed: " + str +
|
||||||
"stoul failed: " + str + " is outside of range of unsigned long");
|
" is outside of range of unsigned long");
|
||||||
} else if (strEnd == strStart || strtoulErrno != 0) {
|
} else if (strEnd == strStart || strtoulErrno != 0) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||||
"stoul failed: " + str + " is not an integer");
|
|
||||||
}
|
}
|
||||||
if (pos != nullptr) {
|
if (pos != nullptr) {
|
||||||
*pos = static_cast<size_t>(strEnd - strStart);
|
*pos = static_cast<size_t>(strEnd - strStart);
|
||||||
@ -225,11 +224,10 @@ int stoi(const std::string& str, size_t* pos, int base) {
|
|||||||
|
|
||||||
/* Check for errors and return */
|
/* Check for errors and return */
|
||||||
if (strtolErrno == ERANGE || long(int(result)) != result) {
|
if (strtolErrno == ERANGE || long(int(result)) != result) {
|
||||||
throw std::out_of_range(
|
throw std::out_of_range("stoul failed: " + str +
|
||||||
"stoul failed: " + str + " is outside of range of int");
|
" is outside of range of int");
|
||||||
} else if (strEnd == strStart || strtolErrno != 0) {
|
} else if (strEnd == strStart || strtolErrno != 0) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||||
"stoul failed: " + str + " is not an integer");
|
|
||||||
}
|
}
|
||||||
if (pos != nullptr) {
|
if (pos != nullptr) {
|
||||||
*pos = static_cast<size_t>(strEnd - strStart);
|
*pos = static_cast<size_t>(strEnd - strStart);
|
||||||
@ -252,11 +250,10 @@ double stod(const std::string& str, size_t* pos) {
|
|||||||
|
|
||||||
/* Check for errors and return */
|
/* Check for errors and return */
|
||||||
if (strtodErrno == ERANGE) {
|
if (strtodErrno == ERANGE) {
|
||||||
throw std::out_of_range(
|
throw std::out_of_range("stoul failed: " + str +
|
||||||
"stoul failed: " + str + " is outside of range of int");
|
" is outside of range of int");
|
||||||
} else if (strEnd == strStart || strtodErrno != 0) {
|
} else if (strEnd == strStart || strtodErrno != 0) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument("stoul failed: " + str + " is not an integer");
|
||||||
"stoul failed: " + str + " is not an integer");
|
|
||||||
}
|
}
|
||||||
if (pos != nullptr) {
|
if (pos != nullptr) {
|
||||||
*pos = static_cast<size_t>(strEnd - strStart);
|
*pos = static_cast<size_t>(strEnd - strStart);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "internal_macros.h"
|
#include "internal_macros.h"
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
@ -51,9 +52,9 @@ unsigned long stoul(const std::string& str, size_t* pos = nullptr,
|
|||||||
int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
|
int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
|
||||||
double stod(const std::string& str, size_t* pos = nullptr);
|
double stod(const std::string& str, size_t* pos = nullptr);
|
||||||
#else
|
#else
|
||||||
using std::stoul;
|
|
||||||
using std::stoi;
|
|
||||||
using std::stod;
|
using std::stod;
|
||||||
|
using std::stoi;
|
||||||
|
using std::stoul;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA
|
#undef StrCat // Don't let StrCat in string_util.h be renamed to lstrcatA
|
||||||
#include <versionhelpers.h>
|
#include <versionhelpers.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#else
|
#else
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -55,9 +56,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <locale>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <locale>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
@ -147,7 +148,7 @@ ValueUnion GetSysctlImp(std::string const& Name) {
|
|||||||
int mib[2];
|
int mib[2];
|
||||||
|
|
||||||
mib[0] = CTL_HW;
|
mib[0] = CTL_HW;
|
||||||
if ((Name == "hw.ncpu") || (Name == "hw.cpuspeed")){
|
if ((Name == "hw.ncpu") || (Name == "hw.cpuspeed")) {
|
||||||
ValueUnion buff(sizeof(int));
|
ValueUnion buff(sizeof(int));
|
||||||
|
|
||||||
if (Name == "hw.ncpu") {
|
if (Name == "hw.ncpu") {
|
||||||
@ -224,7 +225,8 @@ CPUInfo::Scaling CpuScaling(int num_cpus) {
|
|||||||
for (int cpu = 0; cpu < num_cpus; ++cpu) {
|
for (int cpu = 0; cpu < num_cpus; ++cpu) {
|
||||||
std::string governor_file =
|
std::string governor_file =
|
||||||
StrCat("/sys/devices/system/cpu/cpu", cpu, "/cpufreq/scaling_governor");
|
StrCat("/sys/devices/system/cpu/cpu", cpu, "/cpufreq/scaling_governor");
|
||||||
if (ReadFromFile(governor_file, &res) && res != "performance") return CPUInfo::Scaling::ENABLED;
|
if (ReadFromFile(governor_file, &res) && res != "performance")
|
||||||
|
return CPUInfo::Scaling::ENABLED;
|
||||||
}
|
}
|
||||||
return CPUInfo::Scaling::DISABLED;
|
return CPUInfo::Scaling::DISABLED;
|
||||||
#else
|
#else
|
||||||
@ -368,29 +370,29 @@ std::vector<CPUInfo::CacheInfo> GetCacheSizesWindows() {
|
|||||||
#elif BENCHMARK_OS_QNX
|
#elif BENCHMARK_OS_QNX
|
||||||
std::vector<CPUInfo::CacheInfo> GetCacheSizesQNX() {
|
std::vector<CPUInfo::CacheInfo> GetCacheSizesQNX() {
|
||||||
std::vector<CPUInfo::CacheInfo> res;
|
std::vector<CPUInfo::CacheInfo> res;
|
||||||
struct cacheattr_entry *cache = SYSPAGE_ENTRY(cacheattr);
|
struct cacheattr_entry* cache = SYSPAGE_ENTRY(cacheattr);
|
||||||
uint32_t const elsize = SYSPAGE_ELEMENT_SIZE(cacheattr);
|
uint32_t const elsize = SYSPAGE_ELEMENT_SIZE(cacheattr);
|
||||||
int num = SYSPAGE_ENTRY_SIZE(cacheattr) / elsize ;
|
int num = SYSPAGE_ENTRY_SIZE(cacheattr) / elsize;
|
||||||
for(int i = 0; i < num; ++i ) {
|
for (int i = 0; i < num; ++i) {
|
||||||
CPUInfo::CacheInfo info;
|
CPUInfo::CacheInfo info;
|
||||||
switch (cache->flags){
|
switch (cache->flags) {
|
||||||
case CACHE_FLAG_INSTR :
|
case CACHE_FLAG_INSTR:
|
||||||
info.type = "Instruction";
|
info.type = "Instruction";
|
||||||
info.level = 1;
|
info.level = 1;
|
||||||
break;
|
break;
|
||||||
case CACHE_FLAG_DATA :
|
case CACHE_FLAG_DATA:
|
||||||
info.type = "Data";
|
info.type = "Data";
|
||||||
info.level = 1;
|
info.level = 1;
|
||||||
break;
|
break;
|
||||||
case CACHE_FLAG_UNIFIED :
|
case CACHE_FLAG_UNIFIED:
|
||||||
info.type = "Unified";
|
info.type = "Unified";
|
||||||
info.level = 2;
|
info.level = 2;
|
||||||
break;
|
break;
|
||||||
case CACHE_FLAG_SHARED :
|
case CACHE_FLAG_SHARED:
|
||||||
info.type = "Shared";
|
info.type = "Shared";
|
||||||
info.level = 3;
|
info.level = 3;
|
||||||
break;
|
break;
|
||||||
default :
|
default:
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -418,15 +420,14 @@ std::vector<CPUInfo::CacheInfo> GetCacheSizes() {
|
|||||||
std::string GetSystemName() {
|
std::string GetSystemName() {
|
||||||
#if defined(BENCHMARK_OS_WINDOWS)
|
#if defined(BENCHMARK_OS_WINDOWS)
|
||||||
std::string str;
|
std::string str;
|
||||||
const unsigned COUNT = MAX_COMPUTERNAME_LENGTH+1;
|
const unsigned COUNT = MAX_COMPUTERNAME_LENGTH + 1;
|
||||||
TCHAR hostname[COUNT] = {'\0'};
|
TCHAR hostname[COUNT] = {'\0'};
|
||||||
DWORD DWCOUNT = COUNT;
|
DWORD DWCOUNT = COUNT;
|
||||||
if (!GetComputerName(hostname, &DWCOUNT))
|
if (!GetComputerName(hostname, &DWCOUNT)) return std::string("");
|
||||||
return std::string("");
|
|
||||||
#ifndef UNICODE
|
#ifndef UNICODE
|
||||||
str = std::string(hostname, DWCOUNT);
|
str = std::string(hostname, DWCOUNT);
|
||||||
#else
|
#else
|
||||||
//Using wstring_convert, Is deprecated in C++17
|
// Using wstring_convert, Is deprecated in C++17
|
||||||
using convert_type = std::codecvt_utf8<wchar_t>;
|
using convert_type = std::codecvt_utf8<wchar_t>;
|
||||||
std::wstring_convert<convert_type, wchar_t> converter;
|
std::wstring_convert<convert_type, wchar_t> converter;
|
||||||
std::wstring wStr(hostname, DWCOUNT);
|
std::wstring wStr(hostname, DWCOUNT);
|
||||||
@ -474,8 +475,7 @@ int GetNumCPUs() {
|
|||||||
// Returns -1 in case of a failure.
|
// Returns -1 in case of a failure.
|
||||||
int NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
int NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
if (NumCPU < 0) {
|
if (NumCPU < 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
|
||||||
"sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
|
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
return NumCPU;
|
return NumCPU;
|
||||||
@ -498,7 +498,8 @@ int GetNumCPUs() {
|
|||||||
#if defined(__s390__)
|
#if defined(__s390__)
|
||||||
// s390 has another format in /proc/cpuinfo
|
// s390 has another format in /proc/cpuinfo
|
||||||
// it needs to be parsed differently
|
// it needs to be parsed differently
|
||||||
if (SplitIdx != std::string::npos) value = ln.substr(Key.size()+1,SplitIdx-Key.size()-1);
|
if (SplitIdx != std::string::npos)
|
||||||
|
value = ln.substr(Key.size() + 1, SplitIdx - Key.size() - 1);
|
||||||
#else
|
#else
|
||||||
if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx + 1);
|
if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx + 1);
|
||||||
#endif
|
#endif
|
||||||
@ -644,13 +645,13 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
|
|||||||
"~MHz", nullptr, &data, &data_size)))
|
"~MHz", nullptr, &data, &data_size)))
|
||||||
return static_cast<double>((int64_t)data *
|
return static_cast<double>((int64_t)data *
|
||||||
(int64_t)(1000 * 1000)); // was mhz
|
(int64_t)(1000 * 1000)); // was mhz
|
||||||
#elif defined (BENCHMARK_OS_SOLARIS)
|
#elif defined(BENCHMARK_OS_SOLARIS)
|
||||||
kstat_ctl_t *kc = kstat_open();
|
kstat_ctl_t* kc = kstat_open();
|
||||||
if (!kc) {
|
if (!kc) {
|
||||||
std::cerr << "failed to open /dev/kstat\n";
|
std::cerr << "failed to open /dev/kstat\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
kstat_t *ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
|
kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
|
||||||
if (!ksp) {
|
if (!ksp) {
|
||||||
std::cerr << "failed to lookup in /dev/kstat\n";
|
std::cerr << "failed to lookup in /dev/kstat\n";
|
||||||
return -1;
|
return -1;
|
||||||
@ -659,7 +660,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
|
|||||||
std::cerr << "failed to read from /dev/kstat\n";
|
std::cerr << "failed to read from /dev/kstat\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
kstat_named_t *knp =
|
kstat_named_t* knp =
|
||||||
(kstat_named_t*)kstat_data_lookup(ksp, (char*)"current_clock_Hz");
|
(kstat_named_t*)kstat_data_lookup(ksp, (char*)"current_clock_Hz");
|
||||||
if (!knp) {
|
if (!knp) {
|
||||||
std::cerr << "failed to lookup data in /dev/kstat\n";
|
std::cerr << "failed to lookup data in /dev/kstat\n";
|
||||||
@ -673,7 +674,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
|
|||||||
double clock_hz = knp->value.ui64;
|
double clock_hz = knp->value.ui64;
|
||||||
kstat_close(kc);
|
kstat_close(kc);
|
||||||
return clock_hz;
|
return clock_hz;
|
||||||
#elif defined (BENCHMARK_OS_QNX)
|
#elif defined(BENCHMARK_OS_QNX)
|
||||||
return static_cast<double>((int64_t)(SYSPAGE_ENTRY(cpuinfo)->speed) *
|
return static_cast<double>((int64_t)(SYSPAGE_ENTRY(cpuinfo)->speed) *
|
||||||
(int64_t)(1000 * 1000));
|
(int64_t)(1000 * 1000));
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
|
||||||
#include "internal_macros.h"
|
#include "internal_macros.h"
|
||||||
|
|
||||||
#ifdef BENCHMARK_OS_WINDOWS
|
#ifdef BENCHMARK_OS_WINDOWS
|
||||||
@ -125,8 +126,8 @@ double ProcessCPUUsage() {
|
|||||||
// syncronous system calls in Emscripten.
|
// syncronous system calls in Emscripten.
|
||||||
return emscripten_get_now() * 1e-3;
|
return emscripten_get_now() * 1e-3;
|
||||||
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
|
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
|
||||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11. See
|
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
|
||||||
// https://github.com/google/benchmark/pull/292
|
// See https://github.com/google/benchmark/pull/292
|
||||||
struct timespec spec;
|
struct timespec spec;
|
||||||
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0)
|
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0)
|
||||||
return MakeTime(spec);
|
return MakeTime(spec);
|
||||||
@ -149,8 +150,8 @@ double ThreadCPUUsage() {
|
|||||||
&user_time);
|
&user_time);
|
||||||
return MakeTime(kernel_time, user_time);
|
return MakeTime(kernel_time, user_time);
|
||||||
#elif defined(BENCHMARK_OS_MACOSX)
|
#elif defined(BENCHMARK_OS_MACOSX)
|
||||||
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11. See
|
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
|
||||||
// https://github.com/google/benchmark/pull/292
|
// See https://github.com/google/benchmark/pull/292
|
||||||
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
|
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
|
||||||
thread_basic_info_data_t info;
|
thread_basic_info_data_t info;
|
||||||
mach_port_t thread = pthread_mach_thread_np(pthread_self());
|
mach_port_t thread = pthread_mach_thread_np(pthread_self());
|
||||||
@ -192,11 +193,14 @@ std::string LocalDateTimeString() {
|
|||||||
long int offset_minutes;
|
long int offset_minutes;
|
||||||
char tz_offset_sign = '+';
|
char tz_offset_sign = '+';
|
||||||
// tz_offset is set in one of three ways:
|
// tz_offset is set in one of three ways:
|
||||||
// * strftime with %z - This either returns empty or the ISO 8601 time. The maximum length an
|
// * strftime with %z - This either returns empty or the ISO 8601 time. The
|
||||||
|
// maximum length an
|
||||||
// ISO 8601 string can be is 7 (e.g. -03:30, plus trailing zero).
|
// ISO 8601 string can be is 7 (e.g. -03:30, plus trailing zero).
|
||||||
// * snprintf with %c%02li:%02li - The maximum length is 41 (one for %c, up to 19 for %02li,
|
// * snprintf with %c%02li:%02li - The maximum length is 41 (one for %c, up to
|
||||||
|
// 19 for %02li,
|
||||||
// one for :, up to 19 %02li, plus trailing zero).
|
// one for :, up to 19 %02li, plus trailing zero).
|
||||||
// * A fixed string of "-00:00". The maximum length is 7 (-00:00, plus trailing zero).
|
// * A fixed string of "-00:00". The maximum length is 7 (-00:00, plus
|
||||||
|
// trailing zero).
|
||||||
//
|
//
|
||||||
// Thus, the maximum size this needs to be is 41.
|
// Thus, the maximum size this needs to be is 41.
|
||||||
char tz_offset[41];
|
char tz_offset[41];
|
||||||
@ -204,10 +208,10 @@ std::string LocalDateTimeString() {
|
|||||||
char storage[128];
|
char storage[128];
|
||||||
|
|
||||||
#if defined(BENCHMARK_OS_WINDOWS)
|
#if defined(BENCHMARK_OS_WINDOWS)
|
||||||
std::tm *timeinfo_p = ::localtime(&now);
|
std::tm* timeinfo_p = ::localtime(&now);
|
||||||
#else
|
#else
|
||||||
std::tm timeinfo;
|
std::tm timeinfo;
|
||||||
std::tm *timeinfo_p = &timeinfo;
|
std::tm* timeinfo_p = &timeinfo;
|
||||||
::localtime_r(&now, &timeinfo);
|
::localtime_r(&now, &timeinfo);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -224,7 +228,8 @@ std::string LocalDateTimeString() {
|
|||||||
tz_offset_sign = '-';
|
tz_offset_sign = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
tz_len = ::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
|
tz_len =
|
||||||
|
::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
|
||||||
tz_offset_sign, offset_minutes / 100, offset_minutes % 100);
|
tz_offset_sign, offset_minutes / 100, offset_minutes % 100);
|
||||||
BM_CHECK(tz_len == kTzOffsetLen);
|
BM_CHECK(tz_len == kTzOffsetLen);
|
||||||
((void)tz_len); // Prevent unused variable warning in optimized build.
|
((void)tz_len); // Prevent unused variable warning in optimized build.
|
||||||
@ -241,8 +246,8 @@ std::string LocalDateTimeString() {
|
|||||||
strncpy(tz_offset, "-00:00", kTzOffsetLen + 1);
|
strncpy(tz_offset, "-00:00", kTzOffsetLen + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp_len = std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S",
|
timestamp_len =
|
||||||
timeinfo_p);
|
std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S", timeinfo_p);
|
||||||
BM_CHECK(timestamp_len == kTimestampLen);
|
BM_CHECK(timestamp_len == kTimestampLen);
|
||||||
// Prevent unused variable warning in optimized build.
|
// Prevent unused variable warning in optimized build.
|
||||||
((void)kTimestampLen);
|
((void)kTimestampLen);
|
||||||
|
Loading…
Reference in New Issue
Block a user