BDE 4.14.0 Production release
|
#include <bslmt_throughputbenchmark.h>
Classes | |
struct | ThreadGroup |
Data used by a thread group. More... | |
Public Types | |
typedef bsl::function< void(int)> | RunFunction |
typedef bsl::function< void(bool)> | InitializeSampleFunction |
typedef bsl::function< void(bool)> | ShutdownSampleFunction |
typedef bsl::function< void(bool)> | CleanupSampleFunction |
typedef bsl::function< void()> | InitializeThreadFunction |
typedef bsl::function< void()> | CleanupThreadFunction |
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (ThroughputBenchmark, bslma::UsesBslmaAllocator) | |
ThroughputBenchmark (bslma::Allocator *basicAllocator=0) | |
int | addThreadGroup (const RunFunction &runFunction, int numThreads, bsls::Types::Int64 busyWorkAmount) |
int | addThreadGroup (const RunFunction &runFunction, int numThreads, bsls::Types::Int64 busyWorkAmount, const InitializeThreadFunction &initializeFunctor, const CleanupThreadFunction &cleanupFunctor) |
void | execute (ThroughputBenchmarkResult *result, int millisecondsPerSample, int numSamples) |
void | execute (ThroughputBenchmarkResult *result, int millisecondsPerSample, int numSamples, const InitializeSampleFunction &initializeFunctor, const ShutdownSampleFunction &shutdownFunctor, const CleanupSampleFunction &cleanupFunctor) |
int | numThreads () const |
Return the total number of threads. | |
int | numThreadGroups () const |
Return the number of thread groups. | |
int | numThreadsInGroup (int threadGroupIndex) const |
bslma::Allocator * | allocator () const |
Return the allocator used by this object. | |
Static Public Member Functions | |
static unsigned int | antiOptimization () |
static void | busyWork (bsls::Types::Int64 busyWorkAmount) |
static bsls::Types::Int64 | estimateBusyWorkAmount (bsls::TimeInterval duration) |
Friends | |
class | ThroughputBenchmark_WorkFunction |
class | ThroughputBenchmark_TestUtil |
This class is a mechanism that provides performance testing for multi- threaded components. It allows running different thread functions at the same time, and simulates a work load between subsequent calls to the tested thread functions. The results are loaded into a bslmt::ThroughputBenchmarkResult
object, which provides access to counts of the work done by each thread, thread group, and sample, divided by the number of actual seconds of execution.
typedef bsl::function<void(bool)> bslmt::ThroughputBenchmark::CleanupSampleFunction |
An alias to a function meeting the following contract:
typedef bsl::function<void()> bslmt::ThroughputBenchmark::CleanupThreadFunction |
An alias to a function meeting the following contract:
typedef bsl::function<void(bool)> bslmt::ThroughputBenchmark::InitializeSampleFunction |
An alias to a function meeting the following contract:
typedef bsl::function<void()> bslmt::ThroughputBenchmark::InitializeThreadFunction |
An alias to a function meeting the following contract:
typedef bsl::function<void(int)> bslmt::ThroughputBenchmark::RunFunction |
An alias to a function meeting the following contract:
typedef bsl::function<void(bool)> bslmt::ThroughputBenchmark::ShutdownSampleFunction |
An alias to a function meeting the following contract:
|
explicit |
Create an empty ThroughputBenchmark
object. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
int bslmt::ThroughputBenchmark::addThreadGroup | ( | const RunFunction & | runFunction, |
int | numThreads, | ||
bsls::Types::Int64 | busyWorkAmount | ||
) |
int bslmt::ThroughputBenchmark::addThreadGroup | ( | const RunFunction & | runFunction, |
int | numThreads, | ||
bsls::Types::Int64 | busyWorkAmount, | ||
const InitializeThreadFunction & | initializeFunctor, | ||
const CleanupThreadFunction & | cleanupFunctor | ||
) |
Create a set of threads, with cardinality the specified numThreads
, that will repeatedly execute the specified runFunction
followed by the specified busyWork
, with the specified busyWorkAmount
as its argument. Return the index for the thread group. Optionally specify initializeFunctor
, which is run at the beginning of each thread of the sample and accepts a boolean flag isFirst
, that is set to true
on the first sample, and false
otherwise. Optionally specify cleanupFunctor
, which is run at the end of each thread of the sample and accepts a boolean flag isLast
, that is set to true
on the last sample, and false
otherwise. Return an id for the added thread group. The behavior is undefined unless 0 < numThreads
and 0 <= busyWorkAmount
.
|
inline |
|
static |
Return the value calculated by busyWork
. Note that this method is provided to prevent the compiler from optimizing the simulated workload away.
bslmt::ThroughputBenchmark::BSLMF_NESTED_TRAIT_DECLARATION | ( | ThroughputBenchmark | , |
bslma::UsesBslmaAllocator | |||
) |
|
static |
Perform arithmetic operations to consume an amount of time in linear relation to the specified busyWorkAmount
. Note that the duration of busyWork
invoked with a particular busyWorkAmount
will vary with system load.
|
static |
Return an estimate of the work amount so that busyWork
invoked with the returned work amount executes, approximately, for the specified duration
. Note that this estimate varies with system load.
void bslmt::ThroughputBenchmark::execute | ( | ThroughputBenchmarkResult * | result, |
int | millisecondsPerSample, | ||
int | numSamples | ||
) |
void bslmt::ThroughputBenchmark::execute | ( | ThroughputBenchmarkResult * | result, |
int | millisecondsPerSample, | ||
int | numSamples, | ||
const InitializeSampleFunction & | initializeFunctor, | ||
const ShutdownSampleFunction & | shutdownFunctor, | ||
const CleanupSampleFunction & | cleanupFunctor | ||
) |
Run the tests previously added with calls to the addThreadGroup
method. The tests are run for the specified numSamples
times. Each sample is run for the specified millisecondsPerSample
duration. The results are stored in the specified result
object. Optionally specify initializeFunctor
, which is run at the beginning of the sample and accepts a boolean flag isFirst
, that is set to true
on the first sample, and false
otherwise. Optionally specify shutdownFunctor
, which is run at the end of each sample before threads have been joined, and accepts a boolean flag isLast
, that is set to true
on the last sample, and false
otherwise. Optionally specify cleanupFunctor
, which is run at the end of each sample after threads have been joined, and accepts a boolean flag isLast
, that is set to true
on the last sample, and false
otherwise. The behavior is undefined unless 0 < millisecondsPerSample
, 0 < numSamples
, and 0 < numThreadGroups()
. Also see {Structure of a Test}.
|
inline |
|
inline |
|
inline |
Return the number of threads in the specified threadGroupIndex
. The behavior is undefined unless 0 <= threadGroupIndex < numThreadGroups()
.
|
friend |
|
friend |