Hermes
hermes::profiler::Profiler Class Reference

Singleton code profiler. More...

Classes

class  Block
 Holds a labeled profiler block with start/end time points. More...
 
struct  BlockDescriptor
 Describes a block label. More...
 
class  ScopedBlock
 RAII Profiler Block. More...
 

Public Member Functions

 Profiler (Profiler &&other)=delete
 
 Profiler (const Profiler &other)=delete
 
Profileroperator= (const Profiler &other)=delete
 
Profileroperator= (Profiler &&other)=delete
 

Static Public Member Functions

static const std::vector< Block > & blockList ()
 Raw block data. More...
 
static const BlockDescriptorblockDescriptor (const Block &block)
 Get block descriptor from block. More...
 
static u64 initTime ()
 Get time point when Profiler was instantiated. More...
 
static i64 cpuFrequency ()
 Computed CPU frequency. More...
 
static bool isEnabled ()
 Checks if Profiler is currently enabled. More...
 
static void enable ()
 Enables Profiler.
 
static void disable ()
 Disables Profiler.
 
static u32 pushBlockDescriptor (const char *name, u32 color=argb_colors::Default)
 Registers a new block description. More...
 
static void startBlock (Block &block)
 Starts a new block by taking this call time point. More...
 
static void endBlock ()
 Finishes the block at the top of the stack. More...
 
static void setMaxBlockCount (size_t max_block_count)
 Sets a limit into the maximum number of stored blocks. More...
 
static void reset ()
 Clears all blocks.
 
static void iterateBlocks (const std::function< void(const Block &)> &f)
 Iterates over stored blocks sequentially. More...
 
static std::string dump ()
 Dumps profiling into a string.
 

Detailed Description

Singleton code profiler.

This profiler works by registering a sequence labeled blocks (time intervals). The labeled blocks can represent blocks of code lines, functions bodies and sections. Blocks can also reside inside other blocks constituting hierarchies - useful to find out which section of a function is slower for example.

Ideally, the class should be used indirectly by the auxiliary MACROS. Here is an example of different types of blocks being used:

void profiled_function() {
// register a block taking the function's name as the label
// the block is automatically finished after leaving this function
// some code
{
// register a block with the label "code scope"
// the block is automatically finished after leaving this function
HERMES_PROFILE_SCOPE("code scope")
}
// you can also initiate and finish a block manually
// some code
// remember to finish blocks consistently, as the profiler uses a simple stack
// to manage block creation/completion
}
#define HERMES_PROFILE_START_BLOCK(name,...)
Starts a new non-scoped block with a given label.
Definition: profiler.h:369
#define HERMES_PROFILE_END_BLOCK
Finishes the current top block.
Definition: profiler.h:377
#define HERMES_PROFILE_FUNCTION(...)
Starts a scoped block using the enclosing function as label.
Definition: profiler.h:390
#define HERMES_PROFILE_SCOPE(name,...)
Starts a scoped block with a given label.
Definition: profiler.h:382

Member Function Documentation

◆ blockDescriptor()

const Profiler::BlockDescriptor & hermes::profiler::Profiler::blockDescriptor ( const Block block)
static

Get block descriptor from block.

Parameters
block
Returns

◆ blockList()

const std::vector< Profiler::Block > & hermes::profiler::Profiler::blockList ( )
static

Raw block data.

Returns

◆ cpuFrequency()

i64 hermes::profiler::Profiler::cpuFrequency ( )
static

Computed CPU frequency.

Returns
frequency in Hz

◆ endBlock()

void hermes::profiler::Profiler::endBlock ( )
static

Finishes the block at the top of the stack.

Note
The top of the stack is popped

◆ initTime()

u64 hermes::profiler::Profiler::initTime ( )
static

Get time point when Profiler was instantiated.

Returns
time in CPU ticks

◆ isEnabled()

bool hermes::profiler::Profiler::isEnabled ( )
static

Checks if Profiler is currently enabled.

Returns

◆ iterateBlocks()

void hermes::profiler::Profiler::iterateBlocks ( const std::function< void(const Block &)> &  f)
static

Iterates over stored blocks sequentially.

Parameters
fcallback function for each block

◆ pushBlockDescriptor()

u32 hermes::profiler::Profiler::pushBlockDescriptor ( const char *  name,
u32  color = argb_colors::Default 
)
static

Registers a new block description.

Parameters
name
color
Returns

◆ setMaxBlockCount()

void hermes::profiler::Profiler::setMaxBlockCount ( size_t  max_block_count)
static

Sets a limit into the maximum number of stored blocks.

Parameters
max_block_count

◆ startBlock()

void hermes::profiler::Profiler::startBlock ( Profiler::Block block)
static

Starts a new block by taking this call time point.

Note
The block is put on top of the stack
Parameters
block

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