Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 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 */ |
Klement Sekera | f61bc52 | 2017-02-27 12:49:27 +0100 | [diff] [blame] | 23 | #define BFD_DEBUG (0) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 24 | |
| 25 | #if BFD_DEBUG |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 26 | #define BFD_DEBUG_FILE_DEF \ |
| 27 | static const char *__file = NULL; \ |
| 28 | { \ |
| 29 | __file = strrchr (__FILE__, '/'); \ |
| 30 | if (__file) \ |
| 31 | { \ |
| 32 | ++__file; \ |
| 33 | } \ |
| 34 | else \ |
| 35 | { \ |
| 36 | __file = __FILE__; \ |
| 37 | } \ |
| 38 | } |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 39 | |
| 40 | #define BFD_DBG(fmt, ...) \ |
| 41 | do \ |
| 42 | { \ |
| 43 | BFD_DEBUG_FILE_DEF \ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 44 | static u8 *_s = NULL; \ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 45 | vlib_main_t *vm = vlib_get_main (); \ |
| 46 | _s = format (_s, "%6.02f:DBG:%s:%d:%s():" fmt, vlib_time_now (vm), \ |
| 47 | __file, __LINE__, __func__, ##__VA_ARGS__); \ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 48 | printf ("%.*s\n", vec_len (_s), _s); \ |
| 49 | vec_reset_length (_s); \ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 50 | } \ |
| 51 | while (0); |
| 52 | |
| 53 | #define BFD_ERR(fmt, ...) \ |
| 54 | do \ |
| 55 | { \ |
| 56 | BFD_DEBUG_FILE_DEF \ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 57 | static u8 *_s = NULL; \ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 58 | vlib_main_t *vm = vlib_get_main (); \ |
| 59 | _s = format (_s, "%6.02f:ERR:%s:%d:%s():" fmt, vlib_time_now (vm), \ |
| 60 | __file, __LINE__, __func__, ##__VA_ARGS__); \ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 61 | printf ("%.*s\n", vec_len (_s), _s); \ |
| 62 | vec_reset_length (_s); \ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 63 | } \ |
| 64 | while (0); |
| 65 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 66 | #define BFD_CLK_FMT "%luus/%lu clocks/%.2fs" |
| 67 | #define BFD_CLK_PRN(clocks) \ |
| 68 | (u64) ((((f64)clocks) / vlib_get_main ()->clib_time.clocks_per_second) * \ |
| 69 | USEC_PER_SECOND), \ |
| 70 | (clocks), \ |
| 71 | (((f64)clocks) / vlib_get_main ()->clib_time.clocks_per_second) |
| 72 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 73 | #else |
| 74 | #define BFD_DBG(...) |
| 75 | #define BFD_ERR(...) |
| 76 | #endif |
| 77 | |
| 78 | #endif /* __included_bfd_debug_h__ */ |
| 79 | |
| 80 | /* |
| 81 | * fd.io coding-style-patch-verification: ON |
| 82 | * |
| 83 | * Local Variables: |
| 84 | * eval: (c-set-style "gnu") |
| 85 | * End: |
| 86 | */ |