Update of /cvsroot/mod-c/ehtml/include
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12035/include
Modified Files:
Profiling.h
Log Message:
* Code reordering & added C function for accessing profile statistics.
Index: Profiling.h
===================================================================
RCS file: /cvsroot/mod-c/ehtml/include/Profiling.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Profiling.h 12 Sep 2006 20:02:52 -0000 1.3
--- Profiling.h 13 Sep 2006 00:11:22 -0000 1.4
***************
*** 3,15 ****
#define __PROFILING_H_
- //////////////////////////////////////////////////////////////////////////////
- //
- // Profiling declarations
- //
-
#include <stdint.h>
typedef int64_t hrtime_t;
/**
* Gets the cpu 'read time stamp' instruction.
--- 3,21 ----
#define __PROFILING_H_
#include <stdint.h>
typedef int64_t hrtime_t;
+ struct runspec {
+ hrtime_t accum;
+ int64_t ncalls;
+ int overflows;
+ int depth;
+ const char* name;
+ const char* file;
+ int line;
+ };
+
+ #ifdef __cplusplus
/**
* Gets the cpu 'read time stamp' instruction.
***************
*** 27,37 ****
*/
class ProfileFunction {
! hrtime_t _accum;
! int64_t _ncalls;
! int _overflows;
! int _depth;
! const char* _name;
! const char* _file;
! int _line;
ProfileFunction *_next, *_prev;
static ProfileFunction *_head;
--- 33,37 ----
*/
class ProfileFunction {
! runspec spec;
ProfileFunction *_next, *_prev;
static ProfileFunction *_head;
***************
*** 39,69 ****
public:
! ProfileFunction(const char* name, const char* file, int line):
! _accum(0), _ncalls(0), _overflows(0), _depth(0),
! _name(name), _file(file), _line(line) {
! _next = _head;
! _prev = NULL;
! if (_next)
! _next->_prev = this;
! _head = this;
! }
! ~ProfileFunction() {
! if (_next)
! _next->_prev = _prev;
! if (_prev)
! _prev->_next = _next;
! else
! _head = _next;
! }
static ProfileFunction* Head() { return _head; }
ProfileFunction* Next() { return _next; }
-
- hrtime_t Accum() const { return _accum; }
- int64_t NCalls() const { return _ncalls; }
- int Overflows() const { return _overflows; }
- const char* Function() const { return _name; }
- const char* File() const { return _file; }
- int Line() const { return _line; }
};
--- 39,49 ----
public:
! ProfileFunction(const char* name, const char* file, int line);
! ~ProfileFunction();
!
! runspec* Spec() { return &spec; }
static ProfileFunction* Head() { return _head; }
ProfileFunction* Next() { return _next; }
};
***************
*** 82,90 ****
hrtime_t now = get_tick();
if (now < _started) {
! ++_f->_overflows;
return;
}
! _f->_accum += now - _started;
! ++_f->_ncalls;
}
};
--- 62,70 ----
hrtime_t now = get_tick();
if (now < _started) {
! ++_f->spec.overflows;
return;
}
! _f->spec.accum += now - _started;
! ++_f->spec.ncalls;
}
};
***************
*** 100,103 ****
--- 80,104 ----
ProfileRun __profile_run(&__profileme);
+ #define EXTERNC extern "C"
+ #else
+ #define EXTERNC
+ #endif /* #ifdef __cplusplus */
+
+ /**
+ * C function for traversing the profile information
+ *
+ * The right way to use it:
+ * <code>
+ * void* cb = NULL;
+ * struct runspec spec;
+ * while (profile_tick(&cb, &spec), cb != NULL) {
+ * printf("%20llu %20lld %11d %11d %s/%s:%d\n",
+ * spec.accum, spec.ncalls, spec.overflows, spec.depth,
+ * spec.name, spec.file, spec.line);
+ * }
+ * </code>
+ */
+ EXTERNC void profile_tick(void** cbdata, struct runspec* spec);
+
#endif
|