-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add support for other multi-threading APIs #1667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
12b8cbe
a75f6cf
16d5f2a
dd29368
63e64f2
b8f41ce
795cd5a
2ae4a49
b985090
b027d02
afa85ec
febafa2
96569c6
82ad95f
f8543fd
d9a71d0
a8fc4af
c333d80
c559b1f
6514086
e1d7ff9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -930,6 +930,9 @@ class BENCHMARK_EXPORT State { | |
| return max_iterations - total_iterations_ + batch_leftover_; | ||
| } | ||
|
|
||
| BENCHMARK_ALWAYS_INLINE | ||
| int GetNumThreadStates() const { return num_thread_states_; } | ||
|
|
||
| BENCHMARK_ALWAYS_INLINE | ||
| std::string name() const { return name_; } | ||
|
|
||
|
|
@@ -976,12 +979,31 @@ class BENCHMARK_EXPORT State { | |
| const std::string name_; | ||
| const int thread_index_; | ||
| const int threads_; | ||
| int num_thread_states_; | ||
|
|
||
| internal::ThreadTimer* const timer_; | ||
| internal::ThreadManager* const manager_; | ||
| internal::PerfCountersMeasurement* const perf_counters_measurement_; | ||
|
|
||
| friend class internal::BenchmarkInstance; | ||
| friend class ThreadState; | ||
|
|
||
| protected: | ||
| void MergeThreadStateToParent(State& parent) const; | ||
| bool started() const { return started_; } | ||
|
|
||
| internal::ThreadTimer* timer_; | ||
| internal::PerfCountersMeasurement* perf_counters_measurement_; | ||
| }; | ||
|
|
||
| // ThreadState can be used in a manually multithreaded benchmark loop. | ||
| class BENCHMARK_EXPORT ThreadState : public State { | ||
| public: | ||
| explicit ThreadState(State& s); | ||
| ~ThreadState(); | ||
|
|
||
| private: | ||
| State* parent_; | ||
|
|
||
| ThreadState(const ThreadState&); | ||
| }; | ||
|
|
||
| inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunning() { | ||
|
|
@@ -1274,6 +1296,13 @@ class BENCHMARK_EXPORT Benchmark { | |
| // Equivalent to ThreadRange(NumCPUs(), NumCPUs()) | ||
| Benchmark* ThreadPerCpu(); | ||
|
|
||
| // Don't create threads. Let the user evaluate state.threads and/or use | ||
| // ThreadState. | ||
| Benchmark* ManualThreading() { | ||
|
Comment on lines
+1299
to
+1301
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This presumably should assert that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually fine to have a non-empty |
||
| manual_threading_ = true; | ||
| return this; | ||
| } | ||
|
|
||
| virtual void Run(State& state) = 0; | ||
|
|
||
| TimeUnit GetTimeUnit() const; | ||
|
|
@@ -1286,6 +1315,7 @@ class BENCHMARK_EXPORT Benchmark { | |
| const char* GetName() const; | ||
| int ArgsCnt() const; | ||
| const char* GetArgName(int arg) const; | ||
| bool GetExplicitThreading() const { return !thread_counts_.empty(); } | ||
|
|
||
| private: | ||
| friend class BenchmarkFamilies; | ||
|
|
@@ -1307,6 +1337,7 @@ class BENCHMARK_EXPORT Benchmark { | |
| bool measure_process_cpu_time_; | ||
| bool use_real_time_; | ||
| bool use_manual_time_; | ||
| bool manual_threading_; | ||
| BigO complexity_; | ||
| BigOFunc* complexity_lambda_; | ||
| std::vector<Statistics> statistics_; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
|
|
||
| #include "benchmark/benchmark.h" | ||
| #include "commandlineflags.h" | ||
| #include "mutex.h" | ||
|
|
||
| namespace benchmark { | ||
| namespace internal { | ||
|
|
@@ -41,6 +42,8 @@ class BenchmarkInstance { | |
| int threads() const { return threads_; } | ||
| void Setup() const; | ||
| void Teardown() const; | ||
| bool explicit_threading() const { return explicit_threading_; } | ||
| bool manual_threading() const { return manual_threading_; } | ||
|
|
||
| State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer, | ||
| internal::ThreadManager* manager, | ||
|
|
@@ -66,6 +69,9 @@ class BenchmarkInstance { | |
| double min_warmup_time_; | ||
| IterationCount iterations_; | ||
| int threads_; // Number of concurrent threads to us | ||
| bool manual_threading_; | ||
| bool explicit_threading_; // true: Number of threads come from a Threads() | ||
| // call | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't fully looked at things, but preliminary, i don't really like the names chosen. |
||
|
|
||
| typedef void (*callback_function)(const benchmark::State&); | ||
| callback_function setup_ = nullptr; | ||
|
|
@@ -78,6 +84,10 @@ bool FindBenchmarksInternal(const std::string& re, | |
|
|
||
| bool IsZero(double n); | ||
|
|
||
| // only call while holding benchmark_mutex_: | ||
| void MergeResults(const State& st, const ThreadTimer* timer, | ||
| ThreadManager* manager) NO_THREAD_SAFETY_ANALYSIS; | ||
LebedevRI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| BENCHMARK_EXPORT | ||
| ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These all should probably assert
!manual_threading_.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said above, it is fine to combine these functions with manual threading.