Skip to content

Commit

Permalink
Update contrib/restricted/google/benchmark to 1.9.0
Browse files Browse the repository at this point in the history
As [#1836](google/benchmark#1836) has landed into upstream, there is no need to keep [#946](google/benchmark#946) as a patch.
d9d33ff20e1e7767759fc07ea97c1e661716f26a
  • Loading branch information
robot-piglet committed Aug 23, 2024
1 parent 0c3b7e9 commit 3c97d60
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,8 @@ class BENCHMARK_EXPORT State {
State(std::string name, IterationCount max_iters,
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
internal::ThreadTimer* timer, internal::ThreadManager* manager,
internal::PerfCountersMeasurement* perf_counters_measurement);
internal::PerfCountersMeasurement* perf_counters_measurement,
ProfilerManager* profiler_manager);

void StartKeepRunning();
// Implementation of KeepRunning() and KeepRunningBatch().
Expand All @@ -1019,6 +1020,7 @@ class BENCHMARK_EXPORT State {
internal::ThreadTimer* const timer_;
internal::ThreadManager* const manager_;
internal::PerfCountersMeasurement* const perf_counters_measurement_;
ProfilerManager* const profiler_manager_;

friend class internal::BenchmarkInstance;
};
Expand Down Expand Up @@ -1832,14 +1834,11 @@ class BENCHMARK_EXPORT BenchmarkReporter {
internal::Skipped skipped;
std::string skip_message;

// Total iterations across all threads.
IterationCount iterations;
int64_t threads;
int64_t repetition_index;
int64_t repetitions;
TimeUnit time_unit;

// Total time across all threads.
double real_accumulated_time;
double cpu_accumulated_time;

Expand Down
14 changes: 10 additions & 4 deletions contrib/restricted/google/benchmark/src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ void UseCharPointer(char const volatile* const v) {
State::State(std::string name, IterationCount max_iters,
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
internal::ThreadTimer* timer, internal::ThreadManager* manager,
internal::PerfCountersMeasurement* perf_counters_measurement)
internal::PerfCountersMeasurement* perf_counters_measurement,
ProfilerManager* profiler_manager)
: total_iterations_(0),
batch_leftover_(0),
max_iterations(max_iters),
Expand All @@ -182,7 +183,8 @@ State::State(std::string name, IterationCount max_iters,
threads_(n_threads),
timer_(timer),
manager_(manager),
perf_counters_measurement_(perf_counters_measurement) {
perf_counters_measurement_(perf_counters_measurement),
profiler_manager_(profiler_manager) {
BM_CHECK(max_iterations != 0) << "At least one iteration must be run";
BM_CHECK_LT(thread_index_, threads_)
<< "thread_index must be less than threads";
Expand All @@ -207,7 +209,7 @@ State::State(std::string name, IterationCount max_iters,
#if defined(__INTEL_COMPILER)
#pragma warning push
#pragma warning(disable : 1875)
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
Expand All @@ -225,7 +227,7 @@ State::State(std::string name, IterationCount max_iters,
offsetof(State, skipped_) <= (cache_line_size - sizeof(skipped_)), "");
#if defined(__INTEL_COMPILER)
#pragma warning pop
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#if defined(__NVCC__)
Expand Down Expand Up @@ -302,6 +304,8 @@ void State::StartKeepRunning() {
BM_CHECK(!started_ && !finished_);
started_ = true;
total_iterations_ = skipped() ? 0 : max_iterations;
if (BENCHMARK_BUILTIN_EXPECT(profiler_manager_ != nullptr, false))
profiler_manager_->AfterSetupStart();
manager_->StartStopBarrier();
if (!skipped()) ResumeTiming();
}
Expand All @@ -315,6 +319,8 @@ void State::FinishKeepRunning() {
total_iterations_ = 0;
finished_ = true;
manager_->StartStopBarrier();
if (BENCHMARK_BUILTIN_EXPECT(profiler_manager_ != nullptr, false))
profiler_manager_->BeforeTeardownStop();
}

namespace internal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,26 @@ BenchmarkInstance::BenchmarkInstance(Benchmark* benchmark, int family_idx,
State BenchmarkInstance::Run(
IterationCount iters, int thread_id, internal::ThreadTimer* timer,
internal::ThreadManager* manager,
internal::PerfCountersMeasurement* perf_counters_measurement) const {
internal::PerfCountersMeasurement* perf_counters_measurement,
ProfilerManager* profiler_manager) const {
State st(name_.function_name, iters, args_, thread_id, threads_, timer,
manager, perf_counters_measurement);
manager, perf_counters_measurement, profiler_manager);
benchmark_.Run(st);
return st;
}

void BenchmarkInstance::Setup() const {
if (setup_) {
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
nullptr, nullptr, nullptr);
nullptr, nullptr, nullptr, nullptr);
setup_(st);
}
}

void BenchmarkInstance::Teardown() const {
if (teardown_) {
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
nullptr, nullptr, nullptr);
nullptr, nullptr, nullptr, nullptr);
teardown_(st);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class BenchmarkInstance {

State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer,
internal::ThreadManager* manager,
internal::PerfCountersMeasurement* perf_counters_measurement) const;
internal::PerfCountersMeasurement* perf_counters_measurement,
ProfilerManager* profiler_manager) const;

private:
BenchmarkName name_;
Expand Down
29 changes: 12 additions & 17 deletions contrib/restricted/google/benchmark/src/benchmark_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ BenchmarkReporter::Run CreateRunReport(
report.repetitions = repeats;

if (!report.skipped) {
// This is the total time across all threads.
if (b.use_manual_time()) {
report.real_accumulated_time = results.manual_time_used;
} else {
Expand Down Expand Up @@ -126,14 +125,15 @@ BenchmarkReporter::Run CreateRunReport(
// Adds the stats collected for the thread into manager->results.
void RunInThread(const BenchmarkInstance* b, IterationCount iters,
int thread_id, ThreadManager* manager,
PerfCountersMeasurement* perf_counters_measurement) {
PerfCountersMeasurement* perf_counters_measurement,
ProfilerManager* profiler_manager) {
internal::ThreadTimer timer(
b->measure_process_cpu_time()
? internal::ThreadTimer::CreateProcessCpuTime()
: internal::ThreadTimer::Create());

State st =
b->Run(iters, thread_id, &timer, manager, perf_counters_measurement);
State st = b->Run(iters, thread_id, &timer, manager,
perf_counters_measurement, profiler_manager);
BM_CHECK(st.skipped() || st.iterations() >= st.max_iterations)
<< "Benchmark returned before State::KeepRunning() returned false!";
{
Expand Down Expand Up @@ -269,12 +269,14 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() {
// Run all but one thread in separate threads
for (std::size_t ti = 0; ti < pool.size(); ++ti) {
pool[ti] = std::thread(&RunInThread, &b, iters, static_cast<int>(ti + 1),
manager.get(), perf_counters_measurement_ptr);
manager.get(), perf_counters_measurement_ptr,
/*profiler_manager=*/nullptr);
}
// And run one thread here directly.
// (If we were asked to run just one thread, we don't create new threads.)
// Yes, we need to do this here *after* we start the separate threads.
RunInThread(&b, iters, 0, manager.get(), perf_counters_measurement_ptr);
RunInThread(&b, iters, 0, manager.get(), perf_counters_measurement_ptr,
/*profiler_manager=*/nullptr);

// The main thread has finished. Now let's wait for the other threads.
manager->WaitForAllThreads();
Expand All @@ -290,10 +292,6 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() {
// And get rid of the manager.
manager.reset();

// If we were measuring whole-process CPU usage then each thread reports
// total CPU time of all threads. Divide by threads to get real value.
if (b.measure_process_cpu_time()) i.results.cpu_time_used /= b.threads();

BM_VLOG(2) << "Ran in " << i.results.cpu_time_used << "/"
<< i.results.real_time_used << "\n";

Expand All @@ -309,9 +307,6 @@ BenchmarkRunner::IterationResults BenchmarkRunner::DoNIterations() {
i.seconds = i.results.real_time_used;
}

// Adjust time stats to average since they were reported by all threads.
i.seconds /= b.threads();

return i;
}

Expand Down Expand Up @@ -417,7 +412,8 @@ MemoryManager::Result* BenchmarkRunner::RunMemoryManager(
manager.reset(new internal::ThreadManager(1));
b.Setup();
RunInThread(&b, memory_iterations, 0, manager.get(),
perf_counters_measurement_ptr);
perf_counters_measurement_ptr,
/*profiler_manager=*/nullptr);
manager->WaitForAllThreads();
manager.reset();
b.Teardown();
Expand All @@ -431,11 +427,10 @@ void BenchmarkRunner::RunProfilerManager() {
std::unique_ptr<internal::ThreadManager> manager;
manager.reset(new internal::ThreadManager(1));
b.Setup();
profiler_manager->AfterSetupStart();
RunInThread(&b, profile_iterations, 0, manager.get(),
/*perf_counters_measurement_ptr=*/nullptr);
/*perf_counters_measurement_ptr=*/nullptr,
/*profiler_manager=*/profiler_manager);
manager->WaitForAllThreads();
profiler_manager->BeforeTeardownStop();
manager.reset();
b.Teardown();
}
Expand Down
12 changes: 4 additions & 8 deletions contrib/restricted/google/benchmark/src/complexity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace benchmark {

// Internal function to calculate the different scalability forms
BigOFunc* FittingCurve(BigO complexity) {
static const double kLog2E = 1.44269504088896340736;
switch (complexity) {
case oN:
return [](IterationCount n) -> double { return static_cast<double>(n); };
Expand All @@ -36,15 +35,12 @@ BigOFunc* FittingCurve(BigO complexity) {
case oNCubed:
return [](IterationCount n) -> double { return std::pow(n, 3); };
case oLogN:
/* Note: can't use log2 because Android's GNU STL lacks it */
return [](IterationCount n) {
return kLog2E * std::log(static_cast<double>(n));
return [](IterationCount n) -> double {
return std::log2(static_cast<double>(n));
};
case oNLogN:
/* Note: can't use log2 because Android's GNU STL lacks it */
return [](IterationCount n) {
return kLog2E * static_cast<double>(n) *
std::log(static_cast<double>(n));
return [](IterationCount n) -> double {
return static_cast<double>(n) * std::log2(static_cast<double>(n));
};
case o1:
default:
Expand Down
2 changes: 1 addition & 1 deletion contrib/restricted/google/benchmark/src/perf_counters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ PerfCounters PerfCounters::Create(
GetErrorLogInstance() << "***WARNING*** Failed to start counters. "
"Claring out all counters.\n";

// Close all peformance counters
// Close all performance counters
for (int id : counter_ids) {
::close(id);
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/restricted/google/benchmark/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

LIBRARY()

VERSION(1.8.5)
VERSION(1.9.0)

ORIGINAL_SOURCE(https://github.com/google/benchmark/archive/v1.8.5.tar.gz)
ORIGINAL_SOURCE(https://github.com/google/benchmark/archive/v1.9.0.tar.gz)

LICENSE(Apache-2.0)

Expand All @@ -21,7 +21,7 @@ NO_UTIL()

CFLAGS(
GLOBAL -DBENCHMARK_STATIC_DEFINE
-DBENCHMARK_VERSION=\"v1.8.5\"
-DBENCHMARK_VERSION=\"v1.9.0\"
-DHAVE_POSIX_REGEX
-DHAVE_PTHREAD_AFFINITY
-DHAVE_STD_REGEX
Expand Down

0 comments on commit 3c97d60

Please sign in to comment.