#include <bslmt_throughputbenchmark.h>
List of all members.
Classes |
struct | ThreadGroup |
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 |
int | numThreadGroups () const |
int | numThreadsInGroup (int threadGroupIndex) const |
bslma::Allocator * | allocator () const |
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 |
Detailed Description
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.
See Component bslmt_throughputbenchmark
Member Typedef Documentation
An alias to a function meeting the following contract:
void runTest(int threadIndex);
An alias to a function meeting the following contract:
void initializeSample(bool isFirst);
An alias to a function meeting the following contract:
void shutdownSample(bool isLast);
An alias to a function meeting the following contract:
void cleanupSample(bool isLast);
An alias to a function meeting the following contract:
An alias to a function meeting the following contract:
Constructor & Destructor Documentation
bslmt::ThroughputBenchmark::ThroughputBenchmark |
( |
bslma::Allocator * |
basicAllocator = 0 |
) |
[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.
Member Function Documentation
static unsigned int bslmt::ThroughputBenchmark::antiOptimization |
( |
|
) |
[static] |
Return the value calculated by busyWork
. Note that this method is provided to prevent the compiler from optimizing the simulated workload away.
static void bslmt::ThroughputBenchmark::busyWork |
( |
bsls::Types::Int64 |
busyWorkAmount |
) |
[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.
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.
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
.
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.
int bslmt::ThroughputBenchmark::numThreads |
( |
|
) |
const |
Return the total number of threads.
int bslmt::ThroughputBenchmark::numThreadGroups |
( |
|
) |
const |
Return the number of thread groups.
int bslmt::ThroughputBenchmark::numThreadsInGroup |
( |
int |
threadGroupIndex |
) |
const |
Return the number of threads in the specified threadGroupIndex
. The behavior is undefined unless 0 <= threadGroupIndex < numThreadGroups()
.
Return the allocator used by this object.
Friends And Related Function Documentation
The documentation for this class was generated from the following file: