diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-14 00:12:59 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-14 00:12:59 -0400 |
commit | c6b82f8359ef3b2ce5cc0dc57741f9f7c48c0e90 (patch) | |
tree | 85b0799c6e08c75ba204003d6dff8498e1c7ab68 /timing.h | |
parent | 02798277683dbc8a43e5908e62fadf9c28b321b2 (diff) | |
download | fork-ledger-c6b82f8359ef3b2ce5cc0dc57741f9f7c48c0e90.tar.gz fork-ledger-c6b82f8359ef3b2ce5cc0dc57741f9f7c48c0e90.tar.bz2 fork-ledger-c6b82f8359ef3b2ce5cc0dc57741f9f7c48c0e90.zip |
added timing debug code
Diffstat (limited to 'timing.h')
-rw-r--r-- | timing.h | 53 |
1 files changed, 53 insertions, 0 deletions
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 <ctime> + +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 |