kanzi::AbstractProfiler Class Referenceabstract

AbstractProfiler. More...

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

Inheritance diagram for kanzi::AbstractProfiler:
kanzi::AbstractValueProfiler< IntervalProfilerSampleData, IntervalProfilerSampleStatistics > kanzi::AbstractValueProfiler< MainLoopTaskProfilerSampleData, IntervalProfilerSampleStatistics > kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData > kanzi::IntervalProfiler kanzi::MainLoopTaskProfiler

Public Types

enum  DataType {
  DataTypeNotDefined, DataTypeBoolean, DataTypeUint64, DataTypeFloat,
  DataTypeString
}
 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

virtual ~AbstractProfiler ()
 Destructor. More...
 
string_view getName () const
 Gets the name of the profiler. More...
 
const ProfilingCategorygetCategory () const
 Gets a reference to the profiling category assigned to the profiler. More...
 
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...
 
size_t getSampleFieldCount () const
 Gets the number of sample data fields. More...
 
string getSampleFieldName (size_t fieldIndex) const
 Gets the name of a data sample field. More...
 
size_t getSampleCount () const
 Gets the number of collected profiling data samples. 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...
 

Static Public Member Functions

static DataType getDataType (const Value &value)
 Gets the type of the data stored in a profiling data field. More...
 

Protected Member Functions

 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 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 size_t getSampleCountOverride () const =0
 To provide the number of profiling data samples stored in 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...
 

Detailed Description

AbstractProfiler.

This is the abstract base class of all profilers. See derived class AbstractValueProfiler for a concrete implementation.

See Profiling macros on how to use your profilers.

Examples

To extract profiler samples:

// Helps stringify AbstractProfiler::Value.
struct Stringifier : public boost::static_visitor<string>
{
string operator()(const string& str) const
{
return str;
}
string operator()(const monostate&) const
{
return "<empty>";
}
template <typename T>
string operator()(const T& t) const
{
return to_string(t);
}
};
void extractProfilerSamples()
{
stringstream stream;
Stringifier stringifier;
// Get the DefaultRegistry.
// To get the main loop task profiler registry, use Domain::getMainLoopTaskProfilerRegistry().
// To get the startup profiler registry, use Application::getStartupProfilerRegistry().
// Extract all profilers from DefaultRegistry.
for (AbstractProfilerRegistry::ProfilerContainer::const_iterator it = registry.beginProfilers();
it != registry.endProfilers();
++it)
{
// Extract only enabled profilers of type IntervalProfiler.
IntervalProfilerSharedPtr profiler = dynamic_pointer_cast<IntervalProfiler>(*it);
if (profiler && profiler->getCategory().isEnabled())
{
// Extract samples.
for (size_t sampleIndex = 0; sampleIndex < profiler->getSampleCount(); ++sampleIndex)
{
stream << "Sample " << sampleIndex
<< " Timestamp "
<< chrono::duration_cast<chrono::nanoseconds>(
profiler->getSample(sampleIndex).m_startTimePoint.time_since_epoch())
.count()
<< " Duration " << profiler->getSample(sampleIndex).m_duration.count()
<< "\n";
// Extract sample fields.
for (size_t fieldIndex = 0; fieldIndex < profiler->getSampleFieldCount(); ++fieldIndex)
{
AbstractProfiler::Value fieldValue = profiler->getSampleFieldValue(sampleIndex, fieldIndex);
stream << "Field " << fieldIndex
<< " Name " << profiler->getSampleFieldName(fieldIndex)
<< " Value " << boost::apply_visitor(stringifier, fieldValue)
<< "\n";
}
}
// Extract aggregate fields.
for (size_t fieldIndex = 0; fieldIndex < profiler->getAggregateDataFieldCount(); ++fieldIndex)
{
AbstractProfiler::Value fieldValue = profiler->getAggregateDataFieldValue(fieldIndex);
stream << "Aggregate " << fieldIndex
<< " Name " << profiler->getAggregateDataFieldName(fieldIndex)
<< " Value " << boost::apply_visitor(stringifier, fieldValue)
<< "\n";
}
}
}
}

Member Typedef Documentation

typedef variant<monostate, bool, uint64_t, float, string> kanzi::AbstractProfiler::Value

Container for profiling data field value.

Member Enumeration Documentation

Supported profiling data field value types.

Enumerator
DataTypeNotDefined 

Undefined data type.

DataTypeBoolean 

Boolean.

DataTypeUint64 

Unsigned 64 bit integer.

DataTypeFloat 

Float.

DataTypeString 

String.

Constructor & Destructor Documentation

virtual kanzi::AbstractProfiler::~AbstractProfiler ( )
virtual

Destructor.

kanzi::AbstractProfiler::AbstractProfiler ( string_view  name,
const ProfilingCategory category 
)
explicitprotected

Constructor.

Parameters
nameThe name of the profiler.
categoryThe profiling category assigned to the profiler.

Member Function Documentation

string_view kanzi::AbstractProfiler::getName ( ) const

Gets the name of the profiler.

Returns
The name of the profiler.
const ProfilingCategory& kanzi::AbstractProfiler::getCategory ( ) const

Gets a reference to the profiling category assigned to the profiler.

Returns
The profiling category assigned to the profiler.
size_t kanzi::AbstractProfiler::getAggregateDataFieldCount ( ) const

Gets the number of aggregate data fields.

Calls getAggregateDataFieldCountOverride() overriden in the derived profiler class.

Returns
The number of aggregate data fields.
string kanzi::AbstractProfiler::getAggregateDataFieldName ( size_t  fieldIndex) const

Gets the name of an aggregate data field.

Calls getAggregateDataFieldNameOverride() overriden in the derived profiler class.

Parameters
fieldIndexThe index of the field.
Returns
The name of the aggregate data field.
Value kanzi::AbstractProfiler::getAggregateDataFieldValue ( size_t  fieldIndex) const

Gets the value of an aggregate profiling data field.

Calls getAggregateDataFieldValueOverride() overriden in the derived profiler class.

Parameters
fieldIndexThe index of the aggregate profiling data field.
Returns
The value of the aggregate profiling data field.
size_t kanzi::AbstractProfiler::getSampleFieldCount ( ) const

Gets the number of sample data fields.

Calls getSampleFieldCountOverride() overriden in the derived profiler class.

Returns
The number of sample data fields.
string kanzi::AbstractProfiler::getSampleFieldName ( size_t  fieldIndex) const

Gets the name of a data sample field.

Calls getSampleFieldNameOverride() overriden in the derived profiler class.

Parameters
fieldIndexThe index of the sample field.
Returns
The name of the sample field.
size_t kanzi::AbstractProfiler::getSampleCount ( ) const

Gets the number of collected profiling data samples.

Calls getSampleCountOverride() overriden in the derived profiler class.

Returns
The number of collected profiling data samples.
Value kanzi::AbstractProfiler::getSampleFieldValue ( size_t  sampleIndex,
size_t  fieldIndex 
) const

Gets the value of a profiling data sample field.

Calls getSampleFieldValueOverride() overriden in the derived profiler class.

Parameters
sampleIndexThe index of the profiling data sample.
fieldIndexThe index of the field of the profiling data sample.
Returns
The value of the profiling data sample field.
static DataType kanzi::AbstractProfiler::getDataType ( const Value value)
static

Gets the type of the data stored in a profiling data field.

Parameters
valueProfiling data field value.
Returns
Type of the data stored in profiling data field.
void kanzi::AbstractProfiler::logAggregateData ( ) const
inline

Logs aggregate profiling data.

void kanzi::AbstractProfiler::logAllData ( ) const
inline

Logs all profiling data.

virtual size_t kanzi::AbstractProfiler::getAggregateDataFieldCountOverride ( ) const
protectedpure virtual

To provide the number of the aggregate data fields, override this function in the derived profiler class.

Returns
The number of aggregate data fields.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual string kanzi::AbstractProfiler::getAggregateDataFieldNameOverride ( size_t  fieldIndex) const
protectedpure virtual

To provide the name of aggregate data field with given index, override this function in the derived profiler class.

Parameters
fieldIndexThe index of the field.
Returns
The name of the aggregate data field.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual Value kanzi::AbstractProfiler::getAggregateDataFieldValueOverride ( size_t  fieldIndex) const
protectedpure virtual

To provide access to aggregate profiling data field values, override this function in the derived profiler class.

Parameters
fieldIndexThe index of the aggregate profiling data field.
Returns
The value of the aggregate profiling data field.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual size_t kanzi::AbstractProfiler::getSampleFieldCountOverride ( ) const
protectedpure virtual

To provide the number of sample fields, override this function in the derived profiler class.

Returns
The number of sample fields.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual string kanzi::AbstractProfiler::getSampleFieldNameOverride ( size_t  fieldIndex) const
protectedpure virtual

To provide the name of a sample field with a given index, override this function in the derived profiler class.

Parameters
fieldIndexThe index of the field.
Returns
The name of sample field.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual Value kanzi::AbstractProfiler::getSampleFieldValueOverride ( size_t  sampleIndex,
size_t  fieldIndex 
) const
protectedpure virtual

To provide access to profiling data sample fields of the derived profiler, override this function in the derived profiler class.

Parameters
sampleIndexThe index of the profiling data sample.
fieldIndexThe index of the field of the profiling data sample.
Returns
The value of the profiling data sample field.

Implemented in kanzi::IntervalProfiler, and kanzi::MainLoopTaskProfiler.

virtual size_t kanzi::AbstractProfiler::getSampleCountOverride ( ) const
protectedpure virtual

To provide the number of profiling data samples stored in the derived profiler, override this function in the derived profiler class.

Returns
The number of the profiling data samples stored in the derived profiler.

Implemented in kanzi::AbstractValueProfiler< TProfilingDataSample, TAggregateProfilingData >, kanzi::AbstractValueProfiler< IntervalProfilerSampleData, IntervalProfilerSampleStatistics >, and kanzi::AbstractValueProfiler< MainLoopTaskProfilerSampleData, IntervalProfilerSampleStatistics >.

virtual void kanzi::AbstractProfiler::logAggregateDataOverride ( ) const
protectedvirtual

To implement your own logging of aggregate profiling data, override this function in the derived profiler class.

virtual void kanzi::AbstractProfiler::logAllDataOverride ( ) const
protectedvirtual

To implement your own logging of all profiling data, override this function in the derived profiler class.


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