Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
fcl::detail::Profiler Class Reference

This is a simple thread-safe tool for counting time spent in various chunks of code. This is different from external profiling tools in that it allows the user to count time spent in various bits of code (sub-function granularity) or count how many times certain pieces of code are executed. More...

#include <profiler.h>

Classes

struct  AvgInfo
 Information maintained about averaged values. More...
 
struct  PerThread
 Information to be maintained for each thread. More...
 
struct  TimeInfo
 Information about time spent in a section of the code. More...
 

Public Member Functions

void average (const std::string &name, const double value)
 Maintain the average of a specific value. More...
 
void begin (const std::string &name)
 Begin counting time for a specific chunk of code. More...
 
void clear (void)
 Clear counted time and events. More...
 
void end (const std::string &name)
 Stop counting time for a specific chunk of code. More...
 
void event (const std::string &name, const unsigned int times=1)
 Count a specific event for a number of times. More...
 
Profileroperator= (const Profiler &)=delete
 
 Profiler (bool printOnDestroy=false, bool autoStart=false)
 Constructor. It is allowed to separately instantiate this class (not only as a singleton) More...
 
 Profiler (const Profiler &)=delete
 
bool running (void) const
 Check if the profiler is counting time or not. More...
 
 ScopedBlock (const std::string &name, Profiler &prof=Profiler::Instance())
 Start counting time for the block named name of the profiler prof. More...
 
 ScopedStart (Profiler &prof=Profiler::Instance())
 Take as argument the profiler instance to operate on (prof) More...
 
void start (void)
 Start counting time. More...
 
void status (std::ostream &out=std::cout, bool merge=true)
 Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately. More...
 
void stop (void)
 Stop counting time. More...
 
 ~Profiler (void)
 Destructor. More...
 
 ~ScopedBlock (void)
 
 ~ScopedStart (void)
 

Static Public Member Functions

static void Average (const std::string &name, const double value)
 Maintain the average of a specific value. More...
 
static void Begin (const std::string &name)
 Begin counting time for a specific chunk of code. More...
 
static void Clear (void)
 Clear counted time and events. More...
 
static void End (const std::string &name)
 Stop counting time for a specific chunk of code. More...
 
static void Event (const std::string &name, const unsigned int times=1)
 Count a specific event for a number of times. More...
 
static ProfilerInstance (void)
 Return an instance of the class. More...
 
static bool Running (void)
 Check if the profiler is counting time or not. More...
 
static void Start (void)
 Start counting time. More...
 
static void Status (std::ostream &out=std::cout, bool merge=true)
 Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately. More...
 
static void Stop (void)
 Stop counting time. More...
 

Public Attributes

class FCL_EXPORT ScopedBlock
 This instance will call Profiler::begin() when constructed and Profiler::end() when it goes out of scope. More...
 
class FCL_EXPORT ScopedStart
 This instance will call Profiler::start() when constructed and Profiler::stop() when it goes out of scope. If the profiler was already started, this block's constructor and destructor take no action. More...
 

Private Member Functions

void printThreadInfo (std::ostream &out, const PerThread &data)
 

Private Attributes

std::map< std::thread::id, PerThreaddata_
 
std::mutex lock_
 
std::string name_
 
bool printOnDestroy_
 
Profilerprof_
 
bool running_
 
TimeInfo tinfo_
 
bool wasRunning_
 

Detailed Description

This is a simple thread-safe tool for counting time spent in various chunks of code. This is different from external profiling tools in that it allows the user to count time spent in various bits of code (sub-function granularity) or count how many times certain pieces of code are executed.

This instance will call Profiler::start() when constructed and Profiler::stop() when it goes out of scope. If the profiler was already started, this block's constructor and destructor take no action.

This instance will call Profiler::begin() when constructed and Profiler::end() when it goes out of scope.

Definition at line 62 of file detail/profiler.h.

Constructor & Destructor Documentation

◆ Profiler() [1/2]

fcl::detail::Profiler::Profiler ( const Profiler )
delete

◆ Profiler() [2/2]

fcl::detail::Profiler::Profiler ( bool  printOnDestroy = false,
bool  autoStart = false 
)

Constructor. It is allowed to separately instantiate this class (not only as a singleton)

Definition at line 51 of file profiler.cpp.

◆ ~Profiler()

fcl::detail::Profiler::~Profiler ( void  )

Destructor.

Definition at line 59 of file profiler.cpp.

◆ ~ScopedBlock()

fcl::detail::Profiler::~ScopedBlock ( void  )

◆ ~ScopedStart()

fcl::detail::Profiler::~ScopedStart ( void  )

Member Function Documentation

◆ Average()

void fcl::detail::Profiler::Average ( const std::string &  name,
const double  value 
)
static

Maintain the average of a specific value.

Definition at line 133 of file profiler.cpp.

◆ average()

void fcl::detail::Profiler::average ( const std::string &  name,
const double  value 
)

Maintain the average of a specific value.

Definition at line 139 of file profiler.cpp.

◆ Begin()

void fcl::detail::Profiler::Begin ( const std::string &  name)
static

Begin counting time for a specific chunk of code.

Definition at line 150 of file profiler.cpp.

◆ begin()

void fcl::detail::Profiler::begin ( const std::string &  name)

Begin counting time for a specific chunk of code.

Definition at line 162 of file profiler.cpp.

◆ Clear()

void fcl::detail::Profiler::Clear ( void  )
static

Clear counted time and events.

Definition at line 78 of file profiler.cpp.

◆ clear()

void fcl::detail::Profiler::clear ( void  )

Clear counted time and events.

Definition at line 108 of file profiler.cpp.

◆ End()

void fcl::detail::Profiler::End ( const std::string &  name)
static

Stop counting time for a specific chunk of code.

Definition at line 156 of file profiler.cpp.

◆ end()

void fcl::detail::Profiler::end ( const std::string &  name)

Stop counting time for a specific chunk of code.

Definition at line 170 of file profiler.cpp.

◆ Event()

void fcl::detail::Profiler::Event ( const std::string &  name,
const unsigned int  times = 1 
)
static

Count a specific event for a number of times.

Definition at line 119 of file profiler.cpp.

◆ event()

void fcl::detail::Profiler::event ( const std::string &  name,
const unsigned int  times = 1 
)

Count a specific event for a number of times.

Definition at line 125 of file profiler.cpp.

◆ Instance()

Profiler & fcl::detail::Profiler::Instance ( void  )
static

Return an instance of the class.

Definition at line 44 of file profiler.cpp.

◆ operator=()

Profiler& fcl::detail::Profiler::operator= ( const Profiler )
delete

◆ printThreadInfo()

void fcl::detail::Profiler::printThreadInfo ( std::ostream &  out,
const PerThread data 
)
private

Definition at line 273 of file profiler.cpp.

◆ Running()

bool fcl::detail::Profiler::Running ( void  )
static

Check if the profiler is counting time or not.

Definition at line 235 of file profiler.cpp.

◆ running()

bool fcl::detail::Profiler::running ( void  ) const

Check if the profiler is counting time or not.

Definition at line 229 of file profiler.cpp.

◆ ScopedBlock()

fcl::detail::Profiler::ScopedBlock ( const std::string &  name,
Profiler prof = Profiler::Instance() 
)

Start counting time for the block named name of the profiler prof.

◆ ScopedStart()

fcl::detail::Profiler::ScopedStart ( Profiler prof = Profiler::Instance())

Take as argument the profiler instance to operate on (prof)

◆ Start()

void fcl::detail::Profiler::Start ( void  )
static

Start counting time.

Definition at line 66 of file profiler.cpp.

◆ start()

void fcl::detail::Profiler::start ( void  )

Start counting time.

Definition at line 84 of file profiler.cpp.

◆ Status()

void fcl::detail::Profiler::Status ( std::ostream &  out = std::cout,
bool  merge = true 
)
static

Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately.

Definition at line 178 of file profiler.cpp.

◆ status()

void fcl::detail::Profiler::status ( std::ostream &  out = std::cout,
bool  merge = true 
)

Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately.

Definition at line 184 of file profiler.cpp.

◆ Stop()

void fcl::detail::Profiler::Stop ( void  )
static

Stop counting time.

Definition at line 72 of file profiler.cpp.

◆ stop()

void fcl::detail::Profiler::stop ( void  )

Stop counting time.

Definition at line 96 of file profiler.cpp.

Member Data Documentation

◆ data_

std::map<std::thread::id, PerThread> fcl::detail::Profiler::data_
private

Definition at line 205 of file detail/profiler.h.

◆ lock_

std::mutex fcl::detail::Profiler::lock_
private

Definition at line 204 of file detail/profiler.h.

◆ name_

std::string fcl::detail::Profiler::name_
private

Definition at line 225 of file detail/profiler.h.

◆ printOnDestroy_

bool fcl::detail::Profiler::printOnDestroy_
private

Definition at line 208 of file detail/profiler.h.

◆ prof_

Profiler & fcl::detail::Profiler::prof_
private

Definition at line 226 of file detail/profiler.h.

◆ running_

bool fcl::detail::Profiler::running_
private

Definition at line 207 of file detail/profiler.h.

◆ ScopedBlock

class FCL_EXPORT fcl::detail::Profiler::ScopedBlock

This instance will call Profiler::begin() when constructed and Profiler::end() when it goes out of scope.

Definition at line 71 of file detail/profiler.h.

◆ ScopedStart

class FCL_EXPORT fcl::detail::Profiler::ScopedStart

This instance will call Profiler::start() when constructed and Profiler::stop() when it goes out of scope. If the profiler was already started, this block's constructor and destructor take no action.

Definition at line 77 of file detail/profiler.h.

◆ tinfo_

TimeInfo fcl::detail::Profiler::tinfo_
private

Definition at line 206 of file detail/profiler.h.

◆ wasRunning_

bool fcl::detail::Profiler::wasRunning_
private

Definition at line 245 of file detail/profiler.h.


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


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:51