1 /*
2  * Debugging output support. This was originally written for
3  *
4  * Pan - A Newsreader for Gtk+
5  * Copyright (C) 2002  Charles Kerr <charles@rebelbase.com>
6  *
7  * Liferea specific adaptions
8  * Copyright (C) 2004-2007  Lars Windolf <lars.windolf@gmx.de>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; version 2 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #ifndef __DEBUG_H__
25 #define __DEBUG_H__
26 
27 typedef enum
28 {
29 	DEBUG_CACHE		= (1<<0),
30 	DEBUG_CONF		= (1<<1),
31 	DEBUG_UPDATE		= (1<<2),
32 	DEBUG_PARSING		= (1<<3),
33 	DEBUG_GUI		= (1<<4),
34 	DEBUG_TRACE		= (1<<5),
35 	DEBUG_HTML		= (1<<6),
36 	DEBUG_NET		= (1<<7),
37 	DEBUG_DB		= (1<<8),
38 	DEBUG_PERF		= (1<<9),
39 	DEBUG_VFOLDER		= (1<<10),
40 	DEBUG_VERBOSE		= (1<<11)
41 }
42 DebugFlags;
43 
44 /**
45  * Method to save start time for a measurement.
46  *
47  * @param level		debugging flags that enable the measurement
48  *
49  * Not thread-safe!
50  */
51 extern void debug_start_measurement_func (const char * function);
52 
53 #define debug_start_measurement(level) if ((debug_level) & level) debug_start_measurement_func (PRETTY_FUNCTION)
54 
55 /**
56  * Method to calculate the duration for a measurement.
57  * The result will be printed to the debug trace.
58  *
59  * @param level		debugging flags that enable the measurement
60  * @param name		name of the measurement
61  *
62  * Not thread-safe!
63  */
64 extern void debug_end_measurement_func (const char * function, unsigned long flags, const char *name);
65 
66 #define debug_end_measurement(level, name) if ((debug_level) & level) debug_end_measurement_func (PRETTY_FUNCTION, level, name)
67 
68 /**
69  * Enable debugging for one or more of the given debugging flags.
70  *
71  * @param flags		debugging flags (see above)
72  */
73 extern void set_debug_level (unsigned long flags);
74 
75 /** currently configured debug flag set */
76 extern unsigned long debug_level;
77 
78 /** macros for debug output */
79 extern void debug_printf (const char * strloc, const char * function, unsigned long level, const char* fmt, ...);
80 
81 #ifdef __GNUC__
82 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
83 #else
84 #define PRETTY_FUNCTION ""
85 #endif
86 
87 #define debug0(level, fmt) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt)
88 #define debug1(level, fmt, A) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A)
89 #define debug2(level, fmt, A, B) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A, B)
90 #define debug3(level, fmt, A, B, C) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A, B, C)
91 #define debug4(level, fmt, A, B, C, D) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A, B, C, D)
92 #define debug5(level, fmt, A, B, C, D, E) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A, B, C, D, E)
93 #define debug6(level, fmt, A, B, C, D, E, F) if ((debug_level) & level) debug_printf (G_STRLOC, PRETTY_FUNCTION, level,fmt, A, B, C, D, E, F)
94 
95 /**
96  * Trace method to trace function entering when function name
97  * tracing is enabled (--debug-trace|--debug-all). Also implements
98  * slow function detection when performance trace (--debug-perf)
99  * is active.
100  *
101  * @param name		function name
102  */
103 extern void debug_enter (const char *name);
104 
105 /**
106  * Trace method to trace function exiting when function name
107  * tracing is enabled (--debug-trace|--debug-all). Also implements
108  * slow function detection when performance trace (--debug-perf)
109  * is active.
110  *
111  * @param name		function name
112  */
113 extern void debug_exit (const char *name);
114 
115 #endif
116