From c6b82f8359ef3b2ce5cc0dc57741f9f7c48c0e90 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Aug 2004 00:12:59 -0400 Subject: added timing debug code --- timing.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 timing.h (limited to 'timing.h') diff --git a/timing.h b/timing.h new file mode 100644 index 00000000..bb36d99d --- /dev/null +++ b/timing.h @@ -0,0 +1,53 @@ +#ifndef _TIMING_H +#define _TIMING_H + +#include "debug.h" + +#include + +namespace ledger { + +class timing_t +{ + public: + std::clock_t begin; + std::clock_t cumulative; + std::string file; + unsigned long line; + std::string symbol; + std::string category; + + timing_t(const std::string& _symbol, const std::string& _category) + : begin(0), cumulative(0), symbol(_symbol), category(_category) {} + + ~timing_t() { + std::string cls = "timing.results."; + cls += symbol; + DEBUG_PRINT(cls.c_str(), file << ":" << line << ": " + << category << " = " + << (double(cumulative) / double(CLOCKS_PER_SEC)) << "s"); + } + + void start(const std::string& _file, unsigned long _line) { + file = _file; + line = _line; + begin = std::clock(); + } + + void stop() { + cumulative += std::clock() - begin; + } +}; + +#ifdef DEBUG_ENABLED +#define TIMER_DEF(sym, cat) static timing_t sym(#sym, cat) +#define TIMER_START(sym) sym.start(__FILE__, __LINE__) +#define TIMER_STOP(sym) sym.stop() +#else +#define TIMER_START(sym, cat) +#define TIMER_STOP(sym) +#endif + +} // namespace ledger + +#endif // _TIMING_H -- cgit v1.2.3