summaryrefslogtreecommitdiffstats
path: root/kmail/kmdebug.h
blob: 46262aeb407d7d1a390abaa352d9c42a6c0eb07f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// -*- c++ -*- convenience wrappers around kdDebug/kdWarning/etc

#ifndef __KMAIL_KMDEBUG_H__
#define __KMAIL_KMDEBUG_H__

#include <kdebug.h>

// Enable this to debug timing
// #define DEBUG_TIMING

// return type of kmDebug() depends on NDEBUG define:
#ifdef NDEBUG
# define kmail_dbgstream kndbgstream
#else
# define kmail_dbgstream kdbgstream
#endif

/** KMail's debug area code */
static const int kmail_debug_area = 5006;

static inline kmail_dbgstream kmDebug() { return kdDebug( kmail_debug_area ); }
static inline kmail_dbgstream kmDebug( bool cond ) { return kdDebug( cond, kmail_debug_area ); }

static inline kdbgstream kmWarning() { return kdWarning( kmail_debug_area ); }
static inline kdbgstream kmWarning( bool cond ) { return kdWarning( cond, kmail_debug_area ); }

static inline kdbgstream kmError() { return kdError( kmail_debug_area ); }
static inline kdbgstream kmError( bool cond ) { return kdError( cond, kmail_debug_area ); }

static inline kdbgstream kmFatal() { return kdFatal( kmail_debug_area ); }
static inline kdbgstream kmFatal( bool cond ) { return kdFatal( cond, kmail_debug_area ); }

// timing utilities
#if !defined( NDEBUG ) && defined( DEBUG_TIMING )
#include <tqdatetime.h>
#define CREATE_TIMER(x) int x=0, x ## _tmp=0; TQTime x ## _tmp2
#define START_TIMER(x) x ## _tmp2 = TQTime::currentTime()
#define GRAB_TIMER(x) x ## _tmp2.msecsTo(TQTime::currentTime())
#define END_TIMER(x) x += GRAB_TIMER(x); x ## _tmp++
#define SHOW_TIMER(x) kdDebug(5006) << #x " == " << x << "(" << x ## _tmp << ")\n"
#else
#define CREATE_TIMER(x)
#define START_TIMER(x)
#define GRAB_TIMER(x)
#define END_TIMER(x)
#define SHOW_TIMER(x)
#endif

// profiling utilities
#if !defined( NDEBUG )
#define CREATE_COUNTER(x) int x ## _cnt=0
#define RESET_COUNTER(x) x ## _cnt=0
#define INC_COUNTER(x) x ## _cnt++
#define SHOW_COUNTER(x) kdDebug(5006) << #x " == " << x ## _cnt << endl
#else
#define CREATE_COUNTER(x)
#define RESET_COUNTER(x)
#define INC_COUNTER(x)
#define SHOW_COUNTER(x)
#endif

#endif // __KMAIL_KMDEBUG_H__