design_pattern_for_c  V 1.00
dp_debug.h
Go to the documentation of this file.
1 
5 #ifndef DP_UTIL_DEBUG_H_
6 #define DP_UTIL_DEBUG_H_
7 
8 #include <stddef.h>
9 #include <stdarg.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 /*************
14  * define debug
15 *************/
19 struct dp_timelog_t;
21 
32 DPTimeLog dp_timelog_init(const char *delimiter, size_t maxloglen, unsigned long maxstoresize, int is_threadsafe);
33 
42 int dp_timelog_print(DPTimeLog handle, const char *format, ...);
43 
51 
52 /*************
53  * define debug macro
54 *************/
55 #define DEBUG_PRINT(...)
56 
57 #define DBGFLAG/*if you want to disable all debug information, please comment out it*/
58 //#define DBGFLAG_ALL/*if you want to enaable all debug(at threadpool)information, please enable itr*/
59 
60 #ifdef DBGFLAG
61 #include <pthread.h>
63 extern DPTimeLog timelog_g;
65 #define DPDEBUG_INIT timelog_g=dp_timelog_init(",", 2048, 8192, 0); dp_timelog_print(timelog_g,"init\n");
66 
67 #define DPDEBUG_INIT_THREADSAFE timelog_g=dp_timelog_init(",", 2048, 1, 1); dp_timelog_print(timelog_g,"init\n");
68 #include <errno.h>
69 #define DEBUG_ERRPRINT(...) DEBUG_ERRPRINT_(__VA_ARGS__, "")
70 #define DEBUG_ERRPRINT_(fmt, ...) \
71  dp_timelog_print(timelog_g, "[%s(%s:%d)thread:%x]: "fmt"%s", __FUNCTION__,__FILE__,__LINE__,(unsigned int)pthread_self(), __VA_ARGS__)
72 
73 #define DPDEBUG_EXIT dp_timelog_print(timelog_g,"exit\n");dp_timelog_exit(timelog_g);timelog_g=NULL;
74 
75 /*define DEBUG_PRINT*/
76 #ifdef DBGFLAG_ALL
77 #undef DEBUG_PRINT
78 #define DEBUG_PRINT(...) DEBUG_ERRPRINT_(__VA_ARGS__, "")
79 #endif
80 
81 #else/*DBGFLAG*/
82 
83 #define DPDEBUG_INIT
84 #define DPDEBUG_INIT_THREDSAFE
85 #define DEBUG_ERRPRINT(...)
86 #define DPDEBUG_EXIT
87 
88 #endif/*DBGFLAG*/
89 
90 #endif/*DP_UTIL_DEBUG_H_*/
size_t maxloglen
log list
Definition: dp_timelog.c:53
int dp_timelog_print(DPTimeLog handle, const char *format,...)
Store log.
Definition: dp_timelog.c:139
unsigned long maxstoresize
numnber of current stored log
Definition: dp_timelog.c:51
void * handle
Definition: event_thread.c:30
void dp_timelog_exit(DPTimeLog handle)
Exit stored log, and show stored log.
Definition: dp_timelog.c:162
DPTimeLog dp_timelog_init(const char *delimiter, size_t maxloglen, unsigned long maxstoresize, int is_threadsafe)
Init store log.
Definition: dp_timelog.c:85
struct dp_timelog_t * DPTimeLog
Definition: dp_debug.h:20
storaged log data management structure
Definition: dp_timelog.c:45
const char * delimiter
Definition: dp_timelog.c:47
DPTimeLog timelog_g
global timelog handle to show debug log
Definition: dp_timelog.c:14