Skip to content

Commit 10ac4b5

Browse files
committed
Intermediate changes
1 parent 3195166 commit 10ac4b5

File tree

11 files changed

+44
-46
lines changed

11 files changed

+44
-46
lines changed

contrib/restricted/google/benchmark/include/benchmark/benchmark.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,8 @@ class BENCHMARK_EXPORT State {
10041004
State(std::string name, IterationCount max_iters,
10051005
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
10061006
internal::ThreadTimer* timer, internal::ThreadManager* manager,
1007-
internal::PerfCountersMeasurement* perf_counters_measurement);
1007+
internal::PerfCountersMeasurement* perf_counters_measurement,
1008+
ProfilerManager* profiler_manager);
10081009

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

10231025
friend class internal::BenchmarkInstance;
10241026
};
@@ -1832,14 +1834,11 @@ class BENCHMARK_EXPORT BenchmarkReporter {
18321834
internal::Skipped skipped;
18331835
std::string skip_message;
18341836

1835-
// Total iterations across all threads.
18361837
IterationCount iterations;
18371838
int64_t threads;
18381839
int64_t repetition_index;
18391840
int64_t repetitions;
18401841
TimeUnit time_unit;
1841-
1842-
// Total time across all threads.
18431842
double real_accumulated_time;
18441843
double cpu_accumulated_time;
18451844

contrib/restricted/google/benchmark/src/benchmark.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void UseCharPointer(char const volatile* const v) {
168168
State::State(std::string name, IterationCount max_iters,
169169
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
170170
internal::ThreadTimer* timer, internal::ThreadManager* manager,
171-
internal::PerfCountersMeasurement* perf_counters_measurement)
171+
internal::PerfCountersMeasurement* perf_counters_measurement,
172+
ProfilerManager* profiler_manager)
172173
: total_iterations_(0),
173174
batch_leftover_(0),
174175
max_iterations(max_iters),
@@ -182,7 +183,8 @@ State::State(std::string name, IterationCount max_iters,
182183
threads_(n_threads),
183184
timer_(timer),
184185
manager_(manager),
185-
perf_counters_measurement_(perf_counters_measurement) {
186+
perf_counters_measurement_(perf_counters_measurement),
187+
profiler_manager_(profiler_manager) {
186188
BM_CHECK(max_iterations != 0) << "At least one iteration must be run";
187189
BM_CHECK_LT(thread_index_, threads_)
188190
<< "thread_index must be less than threads";
@@ -207,7 +209,7 @@ State::State(std::string name, IterationCount max_iters,
207209
#if defined(__INTEL_COMPILER)
208210
#pragma warning push
209211
#pragma warning(disable : 1875)
210-
#elif defined(__GNUC__)
212+
#elif defined(__GNUC__) || defined(__clang__)
211213
#pragma GCC diagnostic push
212214
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
213215
#endif
@@ -225,7 +227,7 @@ State::State(std::string name, IterationCount max_iters,
225227
offsetof(State, skipped_) <= (cache_line_size - sizeof(skipped_)), "");
226228
#if defined(__INTEL_COMPILER)
227229
#pragma warning pop
228-
#elif defined(__GNUC__)
230+
#elif defined(__GNUC__) || defined(__clang__)
229231
#pragma GCC diagnostic pop
230232
#endif
231233
#if defined(__NVCC__)
@@ -302,6 +304,8 @@ void State::StartKeepRunning() {
302304
BM_CHECK(!started_ && !finished_);
303305
started_ = true;
304306
total_iterations_ = skipped() ? 0 : max_iterations;
307+
if (BENCHMARK_BUILTIN_EXPECT(profiler_manager_ != nullptr, false))
308+
profiler_manager_->AfterSetupStart();
305309
manager_->StartStopBarrier();
306310
if (!skipped()) ResumeTiming();
307311
}
@@ -315,6 +319,8 @@ void State::FinishKeepRunning() {
315319
total_iterations_ = 0;
316320
finished_ = true;
317321
manager_->StartStopBarrier();
322+
if (BENCHMARK_BUILTIN_EXPECT(profiler_manager_ != nullptr, false))
323+
profiler_manager_->BeforeTeardownStop();
318324
}
319325

320326
namespace internal {

contrib/restricted/google/benchmark/src/benchmark_api_internal.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,26 @@ BenchmarkInstance::BenchmarkInstance(Benchmark* benchmark, int family_idx,
9292
State BenchmarkInstance::Run(
9393
IterationCount iters, int thread_id, internal::ThreadTimer* timer,
9494
internal::ThreadManager* manager,
95-
internal::PerfCountersMeasurement* perf_counters_measurement) const {
95+
internal::PerfCountersMeasurement* perf_counters_measurement,
96+
ProfilerManager* profiler_manager) const {
9697
State st(name_.function_name, iters, args_, thread_id, threads_, timer,
97-
manager, perf_counters_measurement);
98+
manager, perf_counters_measurement, profiler_manager);
9899
benchmark_.Run(st);
99100
return st;
100101
}
101102

102103
void BenchmarkInstance::Setup() const {
103104
if (setup_) {
104105
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
105-
nullptr, nullptr, nullptr);
106+
nullptr, nullptr, nullptr, nullptr);
106107
setup_(st);
107108
}
108109
}
109110

110111
void BenchmarkInstance::Teardown() const {
111112
if (teardown_) {
112113
State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_,
113-
nullptr, nullptr, nullptr);
114+
nullptr, nullptr, nullptr, nullptr);
114115
teardown_(st);
115116
}
116117
}

contrib/restricted/google/benchmark/src/benchmark_api_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class BenchmarkInstance {
4444

4545
State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer,
4646
internal::ThreadManager* manager,
47-
internal::PerfCountersMeasurement* perf_counters_measurement) const;
47+
internal::PerfCountersMeasurement* perf_counters_measurement,
48+
ProfilerManager* profiler_manager) const;
4849

4950
private:
5051
BenchmarkName name_;

contrib/restricted/google/benchmark/src/benchmark_runner.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ BenchmarkReporter::Run CreateRunReport(
9393
report.repetitions = repeats;
9494

9595
if (!report.skipped) {
96-
// This is the total time across all threads.
9796
if (b.use_manual_time()) {
9897
report.real_accumulated_time = results.manual_time_used;
9998
} else {
@@ -126,14 +125,15 @@ BenchmarkReporter::Run CreateRunReport(
126125
// Adds the stats collected for the thread into manager->results.
127126
void RunInThread(const BenchmarkInstance* b, IterationCount iters,
128127
int thread_id, ThreadManager* manager,
129-
PerfCountersMeasurement* perf_counters_measurement) {
128+
PerfCountersMeasurement* perf_counters_measurement,
129+
ProfilerManager* profiler_manager) {
130130
internal::ThreadTimer timer(
131131
b->measure_process_cpu_time()
132132
? internal::ThreadTimer::CreateProcessCpuTime()
133133
: internal::ThreadTimer::Create());
134134

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

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

293-
// If we were measuring whole-process CPU usage then each thread reports
294-
// total CPU time of all threads. Divide by threads to get real value.
295-
if (b.measure_process_cpu_time()) i.results.cpu_time_used /= b.threads();
296-
297295
BM_VLOG(2) << "Ran in " << i.results.cpu_time_used << "/"
298296
<< i.results.real_time_used << "\n";
299297

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

312-
// Adjust time stats to average since they were reported by all threads.
313-
i.seconds /= b.threads();
314-
315310
return i;
316311
}
317312

@@ -417,7 +412,8 @@ MemoryManager::Result* BenchmarkRunner::RunMemoryManager(
417412
manager.reset(new internal::ThreadManager(1));
418413
b.Setup();
419414
RunInThread(&b, memory_iterations, 0, manager.get(),
420-
perf_counters_measurement_ptr);
415+
perf_counters_measurement_ptr,
416+
/*profiler_manager=*/nullptr);
421417
manager->WaitForAllThreads();
422418
manager.reset();
423419
b.Teardown();
@@ -431,11 +427,10 @@ void BenchmarkRunner::RunProfilerManager() {
431427
std::unique_ptr<internal::ThreadManager> manager;
432428
manager.reset(new internal::ThreadManager(1));
433429
b.Setup();
434-
profiler_manager->AfterSetupStart();
435430
RunInThread(&b, profile_iterations, 0, manager.get(),
436-
/*perf_counters_measurement_ptr=*/nullptr);
431+
/*perf_counters_measurement_ptr=*/nullptr,
432+
/*profiler_manager=*/profiler_manager);
437433
manager->WaitForAllThreads();
438-
profiler_manager->BeforeTeardownStop();
439434
manager.reset();
440435
b.Teardown();
441436
}

contrib/restricted/google/benchmark/src/complexity.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace benchmark {
2727

2828
// Internal function to calculate the different scalability forms
2929
BigOFunc* FittingCurve(BigO complexity) {
30-
static const double kLog2E = 1.44269504088896340736;
3130
switch (complexity) {
3231
case oN:
3332
return [](IterationCount n) -> double { return static_cast<double>(n); };
@@ -36,15 +35,12 @@ BigOFunc* FittingCurve(BigO complexity) {
3635
case oNCubed:
3736
return [](IterationCount n) -> double { return std::pow(n, 3); };
3837
case oLogN:
39-
/* Note: can't use log2 because Android's GNU STL lacks it */
40-
return [](IterationCount n) {
41-
return kLog2E * std::log(static_cast<double>(n));
38+
return [](IterationCount n) -> double {
39+
return std::log2(static_cast<double>(n));
4240
};
4341
case oNLogN:
44-
/* Note: can't use log2 because Android's GNU STL lacks it */
45-
return [](IterationCount n) {
46-
return kLog2E * static_cast<double>(n) *
47-
std::log(static_cast<double>(n));
42+
return [](IterationCount n) -> double {
43+
return static_cast<double>(n) * std::log2(static_cast<double>(n));
4844
};
4945
case o1:
5046
default:

contrib/restricted/google/benchmark/src/perf_counters.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ PerfCounters PerfCounters::Create(
218218
GetErrorLogInstance() << "***WARNING*** Failed to start counters. "
219219
"Claring out all counters.\n";
220220

221-
// Close all peformance counters
221+
// Close all performance counters
222222
for (int id : counter_ids) {
223223
::close(id);
224224
}

contrib/restricted/google/benchmark/test/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GTEST(benchmark_gtest)
44

55
WITHOUT_LICENSE_TEXTS()
66

7-
VERSION(1.8.5)
7+
VERSION(1.9.0)
88

99
LICENSE(Apache-2.0)
1010

contrib/restricted/google/benchmark/tools/compare/ya.make

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ PY3_PROGRAM()
44

55
WITHOUT_LICENSE_TEXTS()
66

7-
VERSION(1.8.5)
7+
VERSION(1.9.0)
88

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

1111
LICENSE(Apache-2.0)
1212

contrib/restricted/google/benchmark/tools/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by devtools/yamaker.
22

3-
VERSION(1.8.5)
3+
VERSION(1.9.0)
44

55
IF (NOT USE_STL_SYSTEM)
66
IF (NOT USE_SYSTEM_PYTHON OR NOT _SYSTEM_PYTHON27)

0 commit comments

Comments
 (0)