kmail

kmdebug.h
1#ifndef __KMAIL_KMDEBUG_H__
2#define __KMAIL_KMDEBUG_H__
3
4#include <kdebug.h>
5
6// Enable this to debug timing
7// #define DEBUG_TIMING
8
9// return type of kmDebug() depends on NDEBUG define:
10#ifdef NDEBUG
11# define kmail_dbgstream kndbgstream
12#else
13# define kmail_dbgstream kdbgstream
14#endif
15
17static const int kmail_debug_area = 5006;
18
19static inline kmail_dbgstream kmDebug() { return kdDebug( kmail_debug_area ); }
20static inline kmail_dbgstream kmDebug( bool cond ) { return kdDebug( cond, kmail_debug_area ); }
21
22static inline kdbgstream kmWarning() { return kdWarning( kmail_debug_area ); }
23static inline kdbgstream kmWarning( bool cond ) { return kdWarning( cond, kmail_debug_area ); }
24
25static inline kdbgstream kmError() { return kdError( kmail_debug_area ); }
26static inline kdbgstream kmError( bool cond ) { return kdError( cond, kmail_debug_area ); }
27
28static inline kdbgstream kmFatal() { return kdFatal( kmail_debug_area ); }
29static inline kdbgstream kmFatal( bool cond ) { return kdFatal( cond, kmail_debug_area ); }
30
31// timing utilities
32#if !defined( NDEBUG ) && defined( DEBUG_TIMING )
33#include <tqdatetime.h>
34#define CREATE_TIMER(x) int x=0, x ## _tmp=0; TQTime x ## _tmp2
35#define START_TIMER(x) x ## _tmp2 = TQTime::currentTime()
36#define GRAB_TIMER(x) x ## _tmp2.msecsTo(TQTime::currentTime())
37#define END_TIMER(x) x += GRAB_TIMER(x); x ## _tmp++
38#define SHOW_TIMER(x) kdDebug(5006) << #x " == " << x << "(" << x ## _tmp << ")\n"
39#else
40#define CREATE_TIMER(x)
41#define START_TIMER(x)
42#define GRAB_TIMER(x)
43#define END_TIMER(x)
44#define SHOW_TIMER(x)
45#endif
46
47// profiling utilities
48#if !defined( NDEBUG )
49#define CREATE_COUNTER(x) int x ## _cnt=0
50#define RESET_COUNTER(x) x ## _cnt=0
51#define INC_COUNTER(x) x ## _cnt++
52#define SHOW_COUNTER(x) kdDebug(5006) << #x " == " << x ## _cnt << endl
53#else
54#define CREATE_COUNTER(x)
55#define RESET_COUNTER(x)
56#define INC_COUNTER(x)
57#define SHOW_COUNTER(x)
58#endif
59
60#endif // __KMAIL_KMDEBUG_H__