22 #define DRWN_FCN_TIC {drwnCodeProfiler::tic(drwnCodeProfiler::getHandle(__PRETTY_FUNCTION__));}
23 #define DRWN_FCN_TOC {drwnCodeProfiler::toc(drwnCodeProfiler::getHandle(__PRETTY_FUNCTION__));}
74 class drwnCodeProfilerEntry {
78 unsigned long totalClock;
82 drwnCodeProfilerEntry() {
clear(); };
83 ~drwnCodeProfilerEntry() { };
89 startTime = std::time(NULL);
96 startTime = std::time(NULL);
99 clock_t endClock = clock();
101 endTime = std::time(NULL);
103 if (endClock >= startClock) {
104 totalClock += (endClock - startClock);
106 totalClock += ((clock_t)(-1) - startClock) + endClock;
108 startClock = endClock;
110 totalTime += difftime(endTime, startTime);
117 static std::vector<drwnCodeProfilerEntry> _entries;
118 static std::map<std::string, int> _names;
128 static inline void clear(
int handle) {
129 if (
enabled) _entries[handle].clear();
132 static inline void tic(
int handle) {
133 if (
enabled) _entries[handle].tic();
136 static inline void toc(
int handle) {
137 if (
enabled) _entries[handle].toc();
142 return _entries[handle].totalTime;
145 static inline double time(
int handle) {
147 return (
double)_entries[handle].totalClock / (double)CLOCKS_PER_SEC;
150 static inline int calls(
int handle) {
152 return _entries[handle].totalCalls;
static int calls(int handle)
return number of times handle has been profiled
Definition: drwnCodeProfiler.h:150
static void tic(int handle)
starting timing execution of handle
Definition: drwnCodeProfiler.h:132
static double time(int handle)
return total CPU running time of handle (in seconds)
Definition: drwnCodeProfiler.h:145
static void toc(int handle)
stop timing execution of handle (and update number of calls)
Definition: drwnCodeProfiler.h:136
static double walltime(int handle)
return total real-world running time of handle (in seconds)
Definition: drwnCodeProfiler.h:140
static int getHandle(const char *name)
return a handle for profiling a code block called name
Definition: drwnCodeProfiler.cpp:34
static bool enabled
set true to enable profiling
Definition: drwnCodeProfiler.h:70
Static class for providing profile information on functions.
Definition: drwnCodeProfiler.h:68
static void print()
display profile information for all handles (to message logger)
Definition: drwnCodeProfiler.cpp:52
static void clear(int handle)
clear all profiling information for handle
Definition: drwnCodeProfiler.h:128