tudocomp
– The TU Dortmund Compression Framework
tdc::StatPhase Class Reference

Provides access to runtime and memory measurement in statistics phases. More...

#include <StatPhase.hpp>

Public Member Functions

 StatPhase ()
 Creates a inert statistics phase without any effect. More...
 
 StatPhase (const char *title)
 Creates a new statistics phase. More...
 
 StatPhase (const std::string &str)
 Creates a new statistics phase. More...
 
 ~StatPhase ()
 Destroys and ends the phase. More...
 
void split (const char *new_title)
 Starts a new phase as a sibling, reusing the same object. More...
 
void split (const std::string &new_title)
 Starts a new phase as a sibling, reusing the same object. More...
 
template<typename T >
void log_stat (const char *key, const T &value)
 Logs a user statistic for this phase. More...
 
json::Object to_json ()
 Constructs the JSON representation of the measured data. More...
 

Static Public Member Functions

template<typename F >
static auto wrap (const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
 Executes a lambda as a single statistics phase. More...
 
template<typename F >
static auto wrap (const char *title, F func) -> typename std::result_of< F()>::type
 Executes a lambda as a single statistics phase. More...
 
static void track_alloc (size_t bytes)
 Tracks a memory allocation of the given size for the current phase. More...
 
static void track_free (size_t bytes)
 Tracks a memory deallocation of the given size for the current phase. More...
 
static void pause_tracking ()
 Pauses the tracking of memory allocations in the current phase. More...
 
static void resume_tracking ()
 Resumes the tracking of memory allocations in the current phase. More...
 
template<typename T >
static void log (const char *key, const T &value)
 Logs a user statistic for the current phase. More...
 

Detailed Description

Provides access to runtime and memory measurement in statistics phases.

Phases are used to track runtime and memory allocations over the course of the application. The measured data can be printed as a JSON string for use in the tudocomp charter for visualization or third party applications.

Definition at line 44 of file StatPhase.hpp.

Constructor & Destructor Documentation

◆ StatPhase() [1/3]

tdc::StatPhase::StatPhase ( )
inline

Creates a inert statistics phase without any effect.

Definition at line 223 of file StatPhase.hpp.

◆ StatPhase() [2/3]

tdc::StatPhase::StatPhase ( const char *  title)
inline

Creates a new statistics phase.

The new phase is started as a sub phase of the current phase and will immediately become the current phase.

Parameters
titlethe phase title

Definition at line 233 of file StatPhase.hpp.

◆ StatPhase() [3/3]

tdc::StatPhase::StatPhase ( const std::string &  str)
inline

Creates a new statistics phase.

The new phase is started as a sub phase of the current phase and will immediately become the current phase.

Parameters
strthe phase title

Definition at line 245 of file StatPhase.hpp.

◆ ~StatPhase()

tdc::StatPhase::~StatPhase ( )
inline

Destroys and ends the phase.

The phase's parent phase, if any, will become the current phase.

Definition at line 251 of file StatPhase.hpp.

Member Function Documentation

◆ log()

template<typename T >
static void tdc::StatPhase::log ( const char *  key,
const T &  value 
)
inlinestatic

Logs a user statistic for the current phase.

User statistics will be stored in a special data block for a phase and is included in the JSON output.

Parameters
keythe statistic key or name
valuethe value to log (will be converted to a string)

Definition at line 218 of file StatPhase.hpp.

◆ log_stat()

template<typename T >
void tdc::StatPhase::log_stat ( const char *  key,
const T &  value 
)
inline

Logs a user statistic for this phase.

User statistics will be stored in a special data block for a phase and is included in the JSON output.

Parameters
keythe statistic key or name
valuethe value to log (will be converted to a string)

Definition at line 298 of file StatPhase.hpp.

◆ pause_tracking()

static void tdc::StatPhase::pause_tracking ( )
inlinestatic

Pauses the tracking of memory allocations in the current phase.

Memory tracking is paused until pause_tracking is called or the phase object is destroyed.

Definition at line 198 of file StatPhase.hpp.

◆ resume_tracking()

static void tdc::StatPhase::resume_tracking ( )
inlinestatic

Resumes the tracking of memory allocations in the current phase.

This only has an effect if tracking has previously been paused using pause_tracking.

Definition at line 206 of file StatPhase.hpp.

◆ split() [1/2]

void tdc::StatPhase::split ( const char *  new_title)
inline

Starts a new phase as a sibling, reusing the same object.

This function behaves exactly as if the current phase was ended and a new phases was started immediately after.

Parameters
new_titlethe new phase title

Definition at line 264 of file StatPhase.hpp.

◆ split() [2/2]

void tdc::StatPhase::split ( const std::string &  new_title)
inline

Starts a new phase as a sibling, reusing the same object.

This function behaves exactly as if the current phase was ended and a new phases was started immediately after.

Parameters
new_titlethe new phase title

Definition at line 286 of file StatPhase.hpp.

◆ to_json()

json::Object tdc::StatPhase::to_json ( )
inline

Constructs the JSON representation of the measured data.

It contains the subtree of phases beneath this phase.

Returns
the json::Object containing the JSON representation

Definition at line 311 of file StatPhase.hpp.

◆ track_alloc()

static void tdc::StatPhase::track_alloc ( size_t  bytes)
inlinestatic

Tracks a memory allocation of the given size for the current phase.

Use this only if memory is allocated with methods that do not result in calls of malloc but should still be tracked (e.g., when using direct kernel allocations like memory mappings).

Parameters
bytesthe amount of allocated bytes to track for the current phase

Definition at line 178 of file StatPhase.hpp.

◆ track_free()

static void tdc::StatPhase::track_free ( size_t  bytes)
inlinestatic

Tracks a memory deallocation of the given size for the current phase.

Use this only if memory is allocated with methods that do not result in calls of malloc but should still be tracked (e.g., when using direct kernel allocations like memory mappings).

Parameters
bytesthe amount of freed bytes to track for the current phase

Definition at line 190 of file StatPhase.hpp.

◆ wrap() [1/2]

template<typename F >
static auto tdc::StatPhase::wrap ( const char *  title,
func 
) -> typename std::result_of<F(StatPhase&)>::type
inlinestatic

Executes a lambda as a single statistics phase.

The new phase is started as a sub phase of the current phase and will immediately become the current phase.

In case the given lambda accepts a StatPhase reference parameter, the phase object will be passed to it for use during execution.

Parameters
titlethe phase title
functhe lambda to execute
Returns
the return value of the lambda

Definition at line 143 of file StatPhase.hpp.

◆ wrap() [2/2]

template<typename F >
static auto tdc::StatPhase::wrap ( const char *  title,
func 
) -> typename std::result_of<F()>::type
inlinestatic

Executes a lambda as a single statistics phase.

The new phase is started as a sub phase of the current phase and will immediately become the current phase.

In case the given lambda accepts a StatPhase reference parameter, the phase object will be passed to it for use during execution.

Parameters
titlethe phase title
functhe lambda to execute
Returns
the return value of the lambda

Definition at line 162 of file StatPhase.hpp.


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