Update of /cvsroot/mod-c/ehtml/include
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26234/include
Modified Files:
Profiling.h
Log Message:
* Added some documentation.
Index: Profiling.h
===================================================================
RCS file: /cvsroot/mod-c/ehtml/include/Profiling.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Profiling.h 12 Sep 2006 18:05:01 -0000 1.1
--- Profiling.h 12 Sep 2006 18:12:33 -0000 1.2
***************
*** 10,13 ****
--- 10,17 ----
typedef int64_t hrtime_t;
+ /**
+ * Gets the cpu 'read time stamp' instruction.
+ * Returns the value in a 64 bit signed integer.
+ */
static inline hrtime_t get_tick(void) {
hrtime_t regs;
***************
*** 16,19 ****
--- 20,27 ----
}
+ /**
+ * Profiling class.
+ * This provides a placeholder for accumultaed profiling counts.
+ */
class ProfileFunction {
hrtime_t _accum;
***************
*** 58,61 ****
--- 66,75 ----
};
+ /**
+ * Single run profile function.
+ * Measures the CPU time accumulated between object creation & destruction,
+ * and accumulates the result in the ProfileFunction passed by parameter to
+ * the constructor.
+ */
class ProfileRun {
hrtime_t _started;
***************
*** 64,77 ****
ProfileRun(ProfileFunction* f): _started(get_tick()), _f(f) { ; }
~ProfileRun() {
! hrtime_t diff = get_tick() - _started;
! if (diff < 0) {
++_f->_overflows;
return;
}
! _f->_accum += diff;
++_f->_ncalls;
}
};
#define ProfileMe \
static ProfileFunction(__PRETTY_FUNCTION__, __FILE__, __LINE__) __profile;\
--- 78,97 ----
ProfileRun(ProfileFunction* f): _started(get_tick()), _f(f) { ; }
~ProfileRun() {
! hrtime_t now = get_tick();
! if (now < _started) {
++_f->_overflows;
return;
}
! _f->_accum += now - _started;
++_f->_ncalls;
}
};
+ /**
+ * This makes easy to profile a function, simply add the line
+ * <code>ProfileMe;</code>
+ * at the very beggining of the function and you will get your function
+ * profiled.
+ */
#define ProfileMe \
static ProfileFunction(__PRETTY_FUNCTION__, __FILE__, __LINE__) __profile;\
|