22 #define DRWN_FCN_TIC static int __drwn_fcn_handle__ = drwnCodeProfiler::getHandle(__PRETTY_FUNCTION__); drwnCodeProfiler::tic(__drwn_fcn_handle__); 23 #define DRWN_FCN_TOC drwnCodeProfiler::toc(__drwn_fcn_handle__); 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;
130 for (std::vector<drwnCodeProfilerEntry>::iterator it = _entries.begin(); it != _entries.end(); ++it) {
136 static inline void clear(
int handle) {
137 if (enabled) _entries[handle].clear();
140 static inline void tic(
int handle) {
141 if (enabled) _entries[handle].tic();
144 static inline void toc(
int handle) {
145 if (enabled) _entries[handle].toc();
149 if (!enabled)
return -1.0;
150 return _entries[handle].totalTime;
153 static inline double time(
int handle) {
154 if (!enabled)
return -1.0;
155 return (
double)_entries[handle].totalClock / (double)CLOCKS_PER_SEC;
158 static inline int calls(
int handle) {
159 if (!enabled)
return -1;
160 return _entries[handle].totalCalls;
static int calls(int handle)
return number of times handle has been profiled
Definition: drwnCodeProfiler.h:158
static void tic(int handle)
starting timing execution of handle
Definition: drwnCodeProfiler.h:140
static double time(int handle)
return total CPU running time of handle (in seconds)
Definition: drwnCodeProfiler.h:153
static void toc(int handle)
stop timing execution of handle (and update number of calls)
Definition: drwnCodeProfiler.h:144
static void clear()
clear all profiling information
Definition: drwnCodeProfiler.h:128
static double walltime(int handle)
return total real-world running time of handle (in seconds)
Definition: drwnCodeProfiler.h:148
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:136