mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
0f55045526
This patch pulls google/benchmark v1.4.1 into the LLVM tree so that any project could use it for benchmark generation. A dummy benchmark is added to `llvm/benchmarks/DummyYAML.cpp` to validate the correctness of the build process. The current version does not utilize LLVM LNT and LLVM CMake infrastructure, but that might be sufficient for most users. Two introduced CMake variables: * `LLVM_INCLUDE_BENCHMARKS` (`ON` by default) generates benchmark targets * `LLVM_BUILD_BENCHMARKS` (`OFF` by default) adds generated benchmark targets to the list of default LLVM targets (i.e. if `ON` benchmarks will be built upon standard build invocation, e.g. `ninja` or `make` with no specific targets) List of modifications: * `BENCHMARK_ENABLE_TESTING` is disabled * `BENCHMARK_ENABLE_EXCEPTIONS` is disabled * `BENCHMARK_ENABLE_INSTALL` is disabled * `BENCHMARK_ENABLE_GTEST_TESTS` is disabled * `BENCHMARK_DOWNLOAD_DEPENDENCIES` is disabled Original discussion can be found here: http://lists.llvm.org/pipermail/llvm-dev/2018-August/125023.html Reviewed by: dberris, lebedev.ri Subscribers: ilya-biryukov, ioeric, EricWF, lebedev.ri, srhines, dschuff, mgorny, krytarowski, fedor.sergeev, mgrang, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D50894 llvm-svn: 340809
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#ifndef BENCHMARK_THREAD_MANAGER_H
|
|
#define BENCHMARK_THREAD_MANAGER_H
|
|
|
|
#include <atomic>
|
|
|
|
#include "benchmark/benchmark.h"
|
|
#include "mutex.h"
|
|
|
|
namespace benchmark {
|
|
namespace internal {
|
|
|
|
class ThreadManager {
|
|
public:
|
|
ThreadManager(int num_threads)
|
|
: alive_threads_(num_threads), start_stop_barrier_(num_threads) {}
|
|
|
|
Mutex& GetBenchmarkMutex() const RETURN_CAPABILITY(benchmark_mutex_) {
|
|
return benchmark_mutex_;
|
|
}
|
|
|
|
bool StartStopBarrier() EXCLUDES(end_cond_mutex_) {
|
|
return start_stop_barrier_.wait();
|
|
}
|
|
|
|
void NotifyThreadComplete() EXCLUDES(end_cond_mutex_) {
|
|
start_stop_barrier_.removeThread();
|
|
if (--alive_threads_ == 0) {
|
|
MutexLock lock(end_cond_mutex_);
|
|
end_condition_.notify_all();
|
|
}
|
|
}
|
|
|
|
void WaitForAllThreads() EXCLUDES(end_cond_mutex_) {
|
|
MutexLock lock(end_cond_mutex_);
|
|
end_condition_.wait(lock.native_handle(),
|
|
[this]() { return alive_threads_ == 0; });
|
|
}
|
|
|
|
public:
|
|
struct Result {
|
|
int64_t iterations = 0;
|
|
double real_time_used = 0;
|
|
double cpu_time_used = 0;
|
|
double manual_time_used = 0;
|
|
int64_t bytes_processed = 0;
|
|
int64_t items_processed = 0;
|
|
int64_t complexity_n = 0;
|
|
std::string report_label_;
|
|
std::string error_message_;
|
|
bool has_error_ = false;
|
|
UserCounters counters;
|
|
};
|
|
GUARDED_BY(GetBenchmarkMutex()) Result results;
|
|
|
|
private:
|
|
mutable Mutex benchmark_mutex_;
|
|
std::atomic<int> alive_threads_;
|
|
Barrier start_stop_barrier_;
|
|
Mutex end_cond_mutex_;
|
|
Condition end_condition_;
|
|
};
|
|
|
|
} // namespace internal
|
|
} // namespace benchmark
|
|
|
|
#endif // BENCHMARK_THREAD_MANAGER_H
|