MIRA
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Friends | List of all members
Profiler Class Reference

The main Profiler class. More...

#include <utils/Profiler.h>

Inheritance diagram for Profiler:
Inheritance graph
[legend]

Classes

struct  Scope
 

Public Types

typedef Base::Type Type
 

Public Member Functions

 Profiler ()
 
 ~Profiler ()
 
double getCPUSpeed ()
 Returns the set or calibrated CPU speed (in cycles/second i.e. More...
 
void setCPUSpeed (double speed)
 Overwrites the calibrated CPU speed with the specified value (in Hz!). More...
 

Static Public Member Functions

static void writeReport (const std::string &directory, const std::string &dotCommand="", const std::string &imgFormat="png")
 
static uint64 getCycleCount ()
 
static Type & instance ()
 Returns a reference to the singleton instance. More...
 
static bool isDestroyed ()
 Returns true, if the singleton was already destroyed. More...
 

Static Protected Member Functions

static Type * makeInstance ()
 
static void destroyInstance (void)
 

Friends

struct ThreadInfo
 

Detailed Description

The main Profiler class.

This class is used as singleton. The global instance can be obtained using Profiler::instance().

USAGE:

Add a pair of MIRA_PROFILE_BEGIN and MIRA_PROFILE_END macros around
the code you want to profile, or add the MIRA_PROFILE_SCOPE macro
into the scope of code you want to profile (see example below).

To enable profiling add the following compiler option:
-DMIRA_PROFILER_ENABLED

e.g. by adding

ADD_DEFINITIONS(-DMIRA_PROFILER_ENABLED)

to your CMakeLists.txt file.

EXAMPLE:

#include <utils/Profiler.h>
void test()
{
MIRA_PROFILE_BEGIN(function_test);
int sum=0;
for(int i=0; i<10; ++i)
{
MIRA_PROFILE_SCOPE(in_for_loop);
sum+=i; // the code we want to measure
}
MIRA_PROFILE_END(function_test);
}
// Write the report to the output directory.
// Note: The directory must exist
Profiler::writeReport("./reportdir", "dot");
// choose the desired image output format (default: png)
// Note: "dot -T?" returns a list of possible formats
Profiler::writeReport("./reportdir", "dot", "pdf");
// or if no GraphViz dot tool is available:
// Profiler::writeReport("./reportdir");

Within the for-loop the MIRA_PROFILE_SCOPE macro is used to profile the execution time of the code within the for-loop. However, sometimes you need more control where to place the start and ending point of the timing measurements. In these cases you can use the MIRA_PROFILE_BEGIN and MIRA_PROFILE_END macro pair.

Note
If you want to profile a module or class that is used through a MIRA framework by running e.g. mira/miracenter, these tools have a CLI parameter '–enable-profiler' which can be used to trigger the report writing on process exit. If used that way, there is no need to call Profiler::writeReport in own code.

Member Typedef Documentation

◆ Type

typedef Base::Type Type
inherited

Constructor & Destructor Documentation

◆ Profiler()

Profiler ( )

◆ ~Profiler()

~Profiler ( )

Member Function Documentation

◆ writeReport()

static void writeReport ( const std::string &  directory,
const std::string &  dotCommand = "",
const std::string &  imgFormat = "png" 
)
inlinestatic

◆ getCPUSpeed()

double getCPUSpeed ( )

Returns the set or calibrated CPU speed (in cycles/second i.e.

Hz). If this function is called the first time AND setCPUSpeed was not called before, the CPU speed will be calibrated automatically by sleeping one second.

◆ setCPUSpeed()

void setCPUSpeed ( double  speed)
inline

Overwrites the calibrated CPU speed with the specified value (in Hz!).

◆ getCycleCount()

uint64 getCycleCount ( )
inlinestatic

◆ instance()

static Type& instance ( )
inlinestaticinherited

Returns a reference to the singleton instance.

Exceptions
XSingletonIf the singleton was already destroyed (dead reference) or not yet created (when using ExplicitInstantiation).

◆ isDestroyed()

static bool isDestroyed ( )
inlinestaticinherited

Returns true, if the singleton was already destroyed.

Trying to access it will result in an exception.

◆ makeInstance()

static Type* makeInstance ( )
inlinestaticprotectedinherited

◆ destroyInstance()

static void destroyInstance ( void  )
inlinestaticprotectedinherited

Friends And Related Function Documentation

◆ ThreadInfo

friend struct ThreadInfo
friend

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