-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug_tools.h
85 lines (65 loc) · 2.5 KB
/
debug_tools.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright (C) 2013
Fabien Gaud <fgaud@sfu.ca>, Baptiste Lepers <baptiste.lepers@inria.fr>,
Fabien Mottet <fabien.mottet@inria.fr>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 or later, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __DEBUG_TOOLS_H__
#define __DEBUG_TOOLS_H__
/**
* These macros could be used to monitor a function execution time
* They must be used in the same function
*/
#define START struct timeval start; gettimeofday(&start, NULL)
#define STOP struct timeval stop; gettimeofday(&stop, NULL); printf("%lud\t %s:%d us\n", compare_time(&start, &stop), __FUNCTION__,__LINE__)
/**
* This macro permit to have != debug levels
* -1 : no traces
* 1 : per-session requests dump
*/
#if DEBUG_TASK
#define DEBUG(msg, args...) \
fprintf(stderr,"(%s,%d) ",__FUNCTION__,__LINE__); \
fprintf(stderr,msg, ##args)
#else
#define DEBUG(msg, args...)
#endif
#if DEBUG_LEVEL==1
#define DUMP_REQUEST(client) do { \
if (client->number < MAX_SESSION_DUMP){ \
unsigned long long int t; \
rdtscll(t); \
fprintf(stderr,"[%llu] %d '%s'\n", t, client->number, client->request_buf); \
} \
} while(0)
#else
#define DUMP_REQUEST(msg, args...)
#endif //DEBUG_LEVEL==1
#define DEBUG_TMP(msg, args...) \
fprintf(stderr,"(%s,%d) " msg, __FUNCTION__, __LINE__, ##args)
#define PRINT_ALERT(msg, args...) \
fprintf(stderr,"-------\t(%s,%d) " msg, __FUNCTION__, __LINE__, ##args); \
fflush(stderr);
#define PANIC(msg, args...) {\
fprintf(stderr,"*******\t(%s,%d) " msg, __FUNCTION__, __LINE__, ##args); \
exit(EXIT_FAILURE); \
}
/**
* compare_time returns a long int representing the difference between 2 time
*/
unsigned long compare_time(struct timeval* start_time, struct timeval* stop_time);
/**
* getCurrentTime returns a string representing the current time in a human readable way
*/
char* getCurrentTime();
void do_proc_info(FILE* output, char *proc_file);
#endif /*__DEBUG_TOOLS_H__*/