rtmlib
debug_compat.h
Go to the documentation of this file.
1 /*
2  * rtmlib is a Real-Time Monitoring Library.
3  *
4  * Copyright (C) 2018-2020 AndrĂ© Pedro
5  *
6  * This file is part of rtmlib.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef _DEBUG_COMPAT_H_
23 #define _DEBUG_COMPAT_H_
24 
25 #ifndef DEBUG
26 #define DEBUG 0
27 #endif
28 
29 #if defined(__x86__) || defined(__x86_64__)
30 #define x86 1
31 #endif
32 
33 #if defined(DEBUG) && DEBUG > 0 && defined(x86)
34 
35 #define DEBUGV_ERROR(fmt, args...) \
36  fprintf(stderr, "ERROR: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
37  ##args)
38 
39 #define DEBUGV(fmt, args...) \
40  fprintf(stdout, "DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
41  ##args)
42 
43 #if defined(DEBUG) && DEBUG > 2 && defined(x86)
44 
45 #define DEBUGV3(fmt, args...) \
46  fprintf(stdout, "DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
47  ##args)
48 
49 #define DEBUGV3_APPEND(fmt, args...) fprintf(stdout, fmt, ##args)
50 
51 #else
52 #define DEBUGV3(...)
53 
54 #define DEBUGV3_APPEND(...)
55 
56 #endif
57 
58 #elif defined(DEBUG) && DEBUG > 0 && defined(ARM_CM4_FP)
59 
60 #define DEBUGV_ERROR(fmt, args...) \
61  ::printf("ERROR: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##args)
62 
63 #define DEBUGV(fmt, args...) \
64  ::printf("DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##args)
65 
66 #if defined(DEBUG) && DEBUG > 2 && defined(ARM_CM4_FP)
67 
68 #define DEBUGV3(fmt, args...) \
69  ::printf("DEBUG3: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##args)
70 
71 #define DEBUGV3_APPEND(fmt, args...) ::printf(fmt, ##args)
72 
73 #else
74 
75 #define DEBUGV3(...)
76 
77 #define DEBUGV3_APPEND(...)
78 
79 #endif
80 
81 #else
82 
83 #define DEBUGV(...)
84 #define DEBUGV3(...)
85 #define DEBUGV_ERROR(...)
86 #define DEBUGV3_APPEND(...)
87 
88 #endif
89 
90 // Helpers for debuging measures
91 
92 #define START_MEASURE() \
93  uint64_t start, stop; \
94  volatile int cycle_count = 0; \
95  start = clockgettime(); \
96  // DEBUGV3("START_TIME: %lld\n", start);
97 
98 #define COUNT_CYCLE() cycle_count++;
99 
100 #define STOP_MEASURE() \
101  stop = clockgettime(); \
102  DEBUGV("DURATION_TIME:%llu:%u\n", stop - start, cycle_count);
103 
104 #endif //_DEBUG_COMPAT_H_