BFD: fix timing in the main loop
[vpp.git] / vnet / vnet / bfd / bfd_debug.h
1 /*
2  * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file
17  * @brief BFD global declarations
18  */
19 #ifndef __included_bfd_debug_h__
20 #define __included_bfd_debug_h__
21
22 /* controls debug prints */
23 #define BFD_DEBUG (0)
24
25 #if BFD_DEBUG
26 #define BFD_DEBUG_FILE_DEF              \
27   static const char *__file = NULL;     \
28   if (!__file)                          \
29     {                                   \
30       __file = strrchr (__FILE__, '/'); \
31       if (__file)                       \
32         {                               \
33           ++__file;                     \
34         }                               \
35       else                              \
36         {                               \
37           __file = __FILE__;            \
38         }                               \
39     }
40
41 #define BFD_DBG(fmt, ...)                                                \
42   do                                                                     \
43     {                                                                    \
44       BFD_DEBUG_FILE_DEF                                                 \
45       u8 *_s = NULL;                                                     \
46       vlib_main_t *vm = vlib_get_main ();                                \
47       _s = format (_s, "%6.02f:DBG:%s:%d:%s():" fmt, vlib_time_now (vm), \
48                    __file, __LINE__, __func__, ##__VA_ARGS__);           \
49       printf ("%s\n", _s);                                               \
50       fflush (stdout);                                                   \
51       vec_free (_s);                                                     \
52     }                                                                    \
53   while (0);
54
55 #define BFD_ERR(fmt, ...)                                                \
56   do                                                                     \
57     {                                                                    \
58       BFD_DEBUG_FILE_DEF                                                 \
59       u8 *_s = NULL;                                                     \
60       vlib_main_t *vm = vlib_get_main ();                                \
61       _s = format (_s, "%6.02f:ERR:%s:%d:%s():" fmt, vlib_time_now (vm), \
62                    __file, __LINE__, __func__, ##__VA_ARGS__);           \
63       printf ("%s\n", _s);                                               \
64       fflush (stdout);                                                   \
65       vec_free (_s);                                                     \
66     }                                                                    \
67   while (0);
68
69 #else
70 #define BFD_DBG(...)
71 #define BFD_ERR(...)
72 #endif
73
74 #endif /* __included_bfd_debug_h__ */
75
76 /*
77  * fd.io coding-style-patch-verification: ON
78  *
79  * Local Variables:
80  * eval: (c-set-style "gnu")
81  * End:
82  */