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... | |
Profiler & | operator= (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 Profiler & | Instance (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, PerThread > | data_ |
std::mutex | lock_ |
std::string | name_ |
bool | printOnDestroy_ |
Profiler & | prof_ |
bool | running_ |
TimeInfo | tinfo_ |
bool | wasRunning_ |
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.
|
delete |
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.
fcl::detail::Profiler::~Profiler | ( | void | ) |
Destructor.
Definition at line 59 of file profiler.cpp.
fcl::detail::Profiler::~ScopedBlock | ( | void | ) |
fcl::detail::Profiler::~ScopedStart | ( | void | ) |
|
static |
Maintain the average of a specific value.
Definition at line 133 of file profiler.cpp.
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.
|
static |
Begin counting time for a specific chunk of code.
Definition at line 150 of file profiler.cpp.
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.
|
static |
Clear counted time and events.
Definition at line 78 of file profiler.cpp.
void fcl::detail::Profiler::clear | ( | void | ) |
Clear counted time and events.
Definition at line 108 of file profiler.cpp.
|
static |
Stop counting time for a specific chunk of code.
Definition at line 156 of file profiler.cpp.
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.
|
static |
Count a specific event for a number of times.
Definition at line 119 of file profiler.cpp.
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.
|
static |
Return an instance of the class.
Definition at line 44 of file profiler.cpp.
|
private |
Definition at line 273 of file profiler.cpp.
|
static |
Check if the profiler is counting time or not.
Definition at line 235 of file profiler.cpp.
bool fcl::detail::Profiler::running | ( | void | ) | const |
Check if the profiler is counting time or not.
Definition at line 229 of file profiler.cpp.
fcl::detail::Profiler::ScopedBlock | ( | const std::string & | name, |
Profiler & | prof = Profiler::Instance() |
||
) |
Start counting time for the block named name of the profiler prof.
fcl::detail::Profiler::ScopedStart | ( | Profiler & | prof = Profiler::Instance() | ) |
Take as argument the profiler instance to operate on (prof)
|
static |
Start counting time.
Definition at line 66 of file profiler.cpp.
void fcl::detail::Profiler::start | ( | void | ) |
Start counting time.
Definition at line 84 of file profiler.cpp.
|
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.
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.
|
static |
Stop counting time.
Definition at line 72 of file profiler.cpp.
void fcl::detail::Profiler::stop | ( | void | ) |
Stop counting time.
Definition at line 96 of file profiler.cpp.
|
private |
Definition at line 205 of file detail/profiler.h.
|
private |
Definition at line 204 of file detail/profiler.h.
|
private |
Definition at line 225 of file detail/profiler.h.
|
private |
Definition at line 208 of file detail/profiler.h.
|
private |
Definition at line 226 of file detail/profiler.h.
|
private |
Definition at line 207 of file detail/profiler.h.
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.
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.
|
private |
Definition at line 206 of file detail/profiler.h.
|
private |
Definition at line 245 of file detail/profiler.h.