Kanzi  3.9.9
Kanzi Engine C++ API
kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData > Class Template Reference

Abstract value profiler. More...

#include <kanzi/core/profiling/abstract_value_profiler.hpp>

Inheritance diagram for kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >:
[legend]

Public Types

typedef function< void(AbstractValueProfiler &)> FullBufferCallback
 The typedef used for full buffer callback. More...
 
typedef weak_ptr< void > FullBufferCallbackHandle
 The typedef used for full buffer callback handle. More...
 
- Public Types inherited from kanzi::AbstractProfiler
enum  DataType {
  DataTypeNotDefined, DataTypeBoolean, DataTypeUint64, DataTypeFloat,
  DataTypeString, DataTypeCount
}
 Supported profiling data field value types. More...
 
typedef variant< monostate, bool, uint64_t, float, string > Value
 Container for profiling data field value. More...
 

Public Member Functions

FullBufferCallbackHandle addFullBufferCallback (FullBufferCallback callback)
 Adds a new full buffer callback. More...
 
void removeFullBufferCallback (const FullBufferCallbackHandle &callbackHandle)
 Removes a full buffer callback. More...
 
void resetSampleData ()
 Resets the aggregate profiling data and sample buffer. More...
 
- Public Member Functions inherited from kanzi::AbstractProfiler
size_t getAggregateDataFieldCount () const
 Gets the number of aggregate data fields. More...
 
string getAggregateDataFieldName (size_t fieldIndex) const
 Gets the name of an aggregate data field. More...
 
Value getAggregateDataFieldValue (size_t fieldIndex) const
 Gets the value of an aggregate profiling data field. More...
 
const ProfilingCategorygetCategory () const
 Gets a reference to the profiling category assigned to the profiler. More...
 
string_view getName () const
 Gets the name of the profiler. More...
 
size_t getSampleCount () const
 Gets the number of collected profiling data samples. More...
 
size_t getSampleFieldCount () const
 Gets the number of sample data fields. More...
 
DataType getSampleFieldDataType (size_t fieldIndex) const
 Gets the data type of a data sample field. More...
 
string getSampleFieldName (size_t fieldIndex) const
 Gets the name of a data sample field. More...
 
Value getSampleFieldValue (size_t sampleIndex, size_t fieldIndex) const
 Gets the value of a profiling data sample field. More...
 
void logAggregateData () const
 Logs aggregate profiling data. More...
 
void logAllData () const
 Logs all profiling data. More...
 
virtual ~AbstractProfiler ()
 Destructor. More...
 

Protected Types

typedef TAggregateProfilingData AggregateProfilingDataType
 The aggregate profiling data type typedef used in derived classes. More...
 
typedef vector< FullBufferCallbackSharedPtrFullBufferCallbackContainer
 The typedef used for container of full buffer callback shared pointers. More...
 
typedef shared_ptr< FullBufferCallbackFullBufferCallbackSharedPtr
 The typedef used for shared pointer to full buffer callback. More...
 
typedef TProfilingDataSample SampleDataType
 The sample data type typedef used in derived classes. More...
 

Protected Member Functions

 AbstractValueProfiler (string_view name, const ProfilingCategory &category, size_t sampleBufferSize)
 Constructor. More...
 
void addSample (const TProfilingDataSample &sample)
 Adds a new profiling data sample. More...
 
void addSample (TProfilingDataSample &&sample)
 Adds a new movable profiling data sample to the profiler. More...
 
void checkBufferFull ()
 Performs all buffer full callbacks and clears samples if buffer is full. More...
 
const TProfilingDataSample & getSample (size_t index) const
 Accesses a profiling data sample stored in the sample buffer. More...
 
size_t getSampleCountOverride () const override
 Override of AbstractProfiler::getSampleCountOverride(). More...
 
void resetSampleBufferSize (size_t sampleBufferSize)
 Resets the size of the sample buffer. More...
 
- Protected Member Functions inherited from kanzi::AbstractProfiler
 AbstractProfiler (string_view name, const ProfilingCategory &category)
 Constructor. More...
 
virtual size_t getAggregateDataFieldCountOverride () const =0
 To provide the number of the aggregate data fields, override this function in the derived profiler class. More...
 
virtual string getAggregateDataFieldNameOverride (size_t fieldIndex) const =0
 To provide the name of aggregate data field with given index, override this function in the derived profiler class. More...
 
virtual Value getAggregateDataFieldValueOverride (size_t fieldIndex) const =0
 To provide access to aggregate profiling data field values, override this function in the derived profiler class. More...
 
virtual size_t getSampleFieldCountOverride () const =0
 To provide the number of sample fields, override this function in the derived profiler class. More...
 
virtual DataType getSampleFieldDataTypeOverride (size_t fieldIndex) const =0
 To provide the data type of a sample field with a given index, override this function in the derived profiler class. More...
 
virtual string getSampleFieldNameOverride (size_t fieldIndex) const =0
 To provide the name of a sample field with a given index, override this function in the derived profiler class. More...
 
virtual Value getSampleFieldValueOverride (size_t sampleIndex, size_t fieldIndex) const =0
 To provide access to profiling data sample fields of the derived profiler, override this function in the derived profiler class. More...
 
virtual void logAggregateDataOverride () const
 To implement your own logging of aggregate profiling data, override this function in the derived profiler class. More...
 
virtual void logAllDataOverride () const
 To implement your own logging of all profiling data, override this function in the derived profiler class. More...
 

Static Protected Member Functions

static void invokeBufferFullCallback (AbstractValueProfiler &profiler, FullBufferCallbackSharedPtr &callback)
 Internal helper function used by checkBufferFull. More...
 

Protected Attributes

TAggregateProfilingData m_aggregateProfilingData
 The aggregate profiling data. More...
 
FullBufferCallbackContainer m_fullBufferCallbacks
 The container of buffer full callbacks. More...
 
circular_buffer< TProfilingDataSample > m_sampleBuffer
 The profiling data sample buffer. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from kanzi::AbstractProfiler
static DataType getDataType (const Value &value)
 Gets the type of the data stored in a profiling data field. More...
 

Detailed Description

template<typename TProfilingDataSample, typename TAggregateProfilingData>
class kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >

Abstract value profiler.

Derive from AbstractValueProfiler to implement your own profiler which uses a circular buffer to store profiling samples.

The AbstractValueProfiler is a template class which stores profiling data samples of arbitrary type in a circular sample buffer. When the circular buffer runs out of space, new samples overwrite the oldest samples. The size of the sample buffer is set in constructor AbstractValueProfiler::AbstractValueProfiler().

To add a new sample to the profiler use the addSample() function in the derived class. To get a sample reference use the getSample() function in the derived class.

The AbstractValueProfiler provides a placeholder for arbitrary aggregate profiling data. You can access aggregate profiling data from the derived class through m_aggregateProfilingData.

Since internal circular buffer of samples can overflow, callbacks compatible with FullBufferCallback can be added and get called after the addSample() which completely fills the buffer. In case there are callbacks, after invoking all of them, the buffer is cleared. To add a callback use addFullBufferCallback() and to remove use removeFullBufferCallback().

Example:

static void myFullBufferCallback(IntervalProfiler::BaseValueProfiler&)
{
// ....
}
{
IntervalProfiler::FullBufferCallback callback(&myFullBufferCallback);
m_callbackHandle = m_someProfiler->addFullBufferCallback(kanzi::move(callback));
}
{
m_someProfiler->removeFullBufferCallback(m_callbackHandle);
}
private:

See base class AbstractProfiler on how to extract profiler samples.

Member Typedef Documentation

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef function<void(AbstractValueProfiler&)> kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::FullBufferCallback

The typedef used for full buffer callback.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef weak_ptr<void> kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::FullBufferCallbackHandle

The typedef used for full buffer callback handle.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef TProfilingDataSample kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::SampleDataType
protected

The sample data type typedef used in derived classes.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef TAggregateProfilingData kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::AggregateProfilingDataType
protected

The aggregate profiling data type typedef used in derived classes.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef shared_ptr<FullBufferCallback> kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::FullBufferCallbackSharedPtr
protected

The typedef used for shared pointer to full buffer callback.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
typedef vector<FullBufferCallbackSharedPtr> kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::FullBufferCallbackContainer
protected

The typedef used for container of full buffer callback shared pointers.

Constructor & Destructor Documentation

template<typename TProfilingDataSample, typename TAggregateProfilingData>
kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::AbstractValueProfiler ( string_view  name,
const ProfilingCategory category,
size_t  sampleBufferSize 
)
inlineexplicitprotected

Constructor.

Parameters
nameThe name of the profiler.
categoryThe profiling category assigned to the profiler.
sampleBufferSizeThe maximum size of the sample buffer.

Member Function Documentation

template<typename TProfilingDataSample, typename TAggregateProfilingData>
FullBufferCallbackHandle kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::addFullBufferCallback ( FullBufferCallback  callback)
inline

Adds a new full buffer callback.

Parameters
callbackA full buffer callback.
Returns
Handle to added full buffer callback, used to later remove the callback if needed
template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::removeFullBufferCallback ( const FullBufferCallbackHandle callbackHandle)
inline

Removes a full buffer callback.

Parameters
callbackHandleHandle to the callback, returned from addFullBufferCallback
template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::resetSampleData ( )
inline

Resets the aggregate profiling data and sample buffer.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::resetSampleBufferSize ( size_t  sampleBufferSize)
inlineprotected

Resets the size of the sample buffer.

Parameters
sampleBufferSizeSize of the sample buffer.
template<typename TProfilingDataSample, typename TAggregateProfilingData>
const TProfilingDataSample& kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::getSample ( size_t  index) const
inlineprotected

Accesses a profiling data sample stored in the sample buffer.

The sample buffer is zero-based, meaning that oldest sample is stored at index 0.

Parameters
indexThe index of the sample.
Returns
The constant profiling data sample reference.
template<typename TProfilingDataSample, typename TAggregateProfilingData>
static void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::invokeBufferFullCallback ( AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData > &  profiler,
FullBufferCallbackSharedPtr callback 
)
inlinestaticprotected

Internal helper function used by checkBufferFull.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::checkBufferFull ( )
inlineprotected

Performs all buffer full callbacks and clears samples if buffer is full.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::addSample ( const TProfilingDataSample &  sample)
inlineprotected

Adds a new profiling data sample.

Parameters
sampleThe profiling data sample.
template<typename TProfilingDataSample, typename TAggregateProfilingData>
void kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::addSample ( TProfilingDataSample &&  sample)
inlineprotected

Adds a new movable profiling data sample to the profiler.

Parameters
sampleThe profiling data sample.
template<typename TProfilingDataSample, typename TAggregateProfilingData>
size_t kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::getSampleCountOverride ( ) const
inlineoverrideprotectedvirtual

Override of AbstractProfiler::getSampleCountOverride().

Returns
The number of collected profiling data samples.

Implements kanzi::AbstractProfiler.

Member Data Documentation

template<typename TProfilingDataSample, typename TAggregateProfilingData>
TAggregateProfilingData kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::m_aggregateProfilingData
protected

The aggregate profiling data.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
FullBufferCallbackContainer kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::m_fullBufferCallbacks
protected

The container of buffer full callbacks.

template<typename TProfilingDataSample, typename TAggregateProfilingData>
circular_buffer<TProfilingDataSample> kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >::m_sampleBuffer
protected

The profiling data sample buffer.


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