Kanzi  3.9.6
Kanzi Engine API
kanzi::AbstractProfiler Class Referenceabstract

AbstractProfiler. More...

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

Inheritance diagram for kanzi::AbstractProfiler:
[legend]

Public Types

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

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

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

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
{
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 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 " << visit(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 " << visit(stringifier, fieldValue)
<< "\n";
}
}
}
}

Member Typedef Documentation

◆ Value

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

Container for profiling data field value.

Member Enumeration Documentation

◆ DataType

Supported profiling data field value types.

Enumerator
DataTypeNotDefined 

Undefined data type.

DataTypeBoolean 

Boolean.

DataTypeUint64 

Unsigned 64 bit integer.

DataTypeFloat 

Float.

DataTypeString 

String.

DataTypeCount 

Enumerator count.

Constructor & Destructor Documentation

◆ ~AbstractProfiler()

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

Destructor.

◆ AbstractProfiler()

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

◆ getName()

string_view kanzi::AbstractProfiler::getName ( ) const

Gets the name of the profiler.

Returns
The name of the profiler.

◆ getCategory()

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.

◆ getAggregateDataFieldCount()

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.

◆ getAggregateDataFieldName()

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.

◆ getAggregateDataFieldValue()

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.

◆ getSampleFieldCount()

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.

◆ getSampleFieldName()

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.

◆ getSampleFieldDataType()

DataType kanzi::AbstractProfiler::getSampleFieldDataType ( size_t  fieldIndex) const

Gets the data type of a data sample field.

Calls getSampleFieldDataTypeOverride() overriden in the derived profiler class.

Parameters
fieldIndexThe index of the sample field.
Returns
The data type of the sample field.

◆ getSampleCount()

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.

◆ getSampleFieldValue()

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.

◆ getDataType()

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.

◆ logAggregateData()

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

Logs aggregate profiling data.

◆ logAllData()

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

Logs all profiling data.

◆ getAggregateDataFieldCountOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getAggregateDataFieldNameOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getAggregateDataFieldValueOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getSampleFieldCountOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getSampleFieldNameOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getSampleFieldDataTypeOverride()

virtual DataType kanzi::AbstractProfiler::getSampleFieldDataTypeOverride ( size_t  fieldIndex) const
protectedpure virtual

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

Parameters
fieldIndexThe index of the field.
Returns
The data type of sample field.

Implemented in kanzi::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getSampleFieldValueOverride()

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::NamedIntervalProfiler, kanzi::MainLoopProfiler, and kanzi::IntervalProfiler.

◆ getSampleCountOverride()

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 >, kanzi::AbstractValueProfiler< NamedIntervalProfilerSampleData, NamedIntervalProfilerSampleStatistics >, and kanzi::AbstractValueProfiler< MainLoopProfilingSampleData, MainLoopProfilingAggregateData >.

◆ logAggregateDataOverride()

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

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

◆ logAllDataOverride()

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: