Quick Links:

bal | bbl | bdl | bsl

Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends

bslmt::ThroughputBenchmark Class Reference

#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::Allocatorallocator () 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);
              // Run the main part of the benchmark having the specified
              // 'threadIndex'.  The behavior is undefined unless
              // 'threadIndex' is in the range '[0, numThreadsInGroup)',
              // where 'numThreadsInGroup' is the number of threads in a
              // thread group for the associated throughput benchmark.

An alias to a function meeting the following contract:

          void initializeSample(bool isFirst);
              // Initialize the sample run.  If the specified 'isFirst' is
              // 'true', this is the first sample run.

An alias to a function meeting the following contract:

          void shutdownSample(bool isLast);
              // Clean up at the end of the sample run, before threads have
              // been joined.  If the specified 'isLast' is 'true', this is
              // the last sample run.

An alias to a function meeting the following contract:

          void cleanupSample(bool isLast);
              // Clean up after the sample run.  If the specified 'isLast' is
              // 'true', this is the last sample run.

An alias to a function meeting the following contract:

          void initializeThread();
              // Initialize each thread in a sample run.

An alias to a function meeting the following contract:

          void cleanupThread();
              // Clean up after each thread in a sample run.

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

bslmt::ThroughputBenchmark::BSLMF_NESTED_TRAIT_DECLARATION ( ThroughputBenchmark  ,
bslma::UsesBslmaAllocator   
)
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.

static bsls::Types::Int64 bslmt::ThroughputBenchmark::estimateBusyWorkAmount ( bsls::TimeInterval  duration  )  [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.

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.

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.

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().

bslma::Allocator* bslmt::ThroughputBenchmark::allocator (  )  const

Return the allocator used by this object.


Friends And Related Function Documentation

friend class ThroughputBenchmark_WorkFunction [friend]
friend class ThroughputBenchmark_TestUtil [friend]

The documentation for this class was generated from the following file: