FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
session_debug.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 #ifndef SRC_VNET_SESSION_SESSION_DEBUG_H_
16 #define SRC_VNET_SESSION_SESSION_DEBUG_H_
17 
18 #include <vnet/session/transport.h>
19 #include <vlib/vlib.h>
20 
21 #define foreach_session_dbg_evt \
22  _(ENQ, "enqueue") \
23  _(DEQ, "dequeue") \
24  _(DEQ_NODE, "dequeue") \
25  _(POLL_GAP_TRACK, "poll gap track") \
26  _(POLL_DISPATCH_TIME, "dispatch time")\
27  _(DISPATCH_START, "dispatch start") \
28  _(DISPATCH_END, "dispatch end") \
29  _(FREE, "session free") \
30 
31 typedef enum _session_evt_dbg
32 {
33 #define _(sym, str) SESSION_EVT_##sym,
35 #undef _
37 
38 #define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0)
39 #define SESSION_DEQ_EVTS (0)
40 #define SESSION_DISPATCH_DBG (0)
41 #define SESSION_EVT_POLL_DBG (0)
42 #define SESSION_SM (0)
43 
44 #if SESSION_DEBUG
45 
46 #define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
47 
48 #define DEC_SESSION_ETD(_s, _e, _size) \
49  struct \
50  { \
51  u32 data[_size]; \
52  } * ed; \
53  transport_connection_t *_tc = session_get_transport (_s); \
54  ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
55  _e, _tc->elog_track)
56 
57 #define DEC_SESSION_ED(_e, _size) \
58  struct \
59  { \
60  u32 data[_size]; \
61  } * ed; \
62  ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
63 
64 #if SESSION_SM
65 #define SESSION_EVT_FREE_HANDLER(_s) \
66 { \
67  ELOG_TYPE_DECLARE (_e) = \
68  { \
69  .format = "free: idx %u", \
70  .format_args = "i4", \
71  }; \
72  DEC_SESSION_ETD(_s, _e, 1); \
73  ed->data[0] = _s->session_index; \
74 }
75 #else
76 #define SESSION_EVT_FREE_HANDLER(_s)
77 #endif
78 
79 #if SESSION_DEQ_EVTS
80 #define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) \
81 { \
82  ELOG_TYPE_DECLARE (_e) = \
83  { \
84  .format = "deq: now %u max %d evt %u ts %d", \
85  .format_args = "i4i4i4i4", \
86  }; \
87  DEC_SESSION_ETD(_s, _e, 4); \
88  ed->data[0] = _now; \
89  ed->data[1] = _max; \
90  ed->data[2] = _has_evt; \
91  ed->data[3] = _ts * 1000000.0; \
92 }
93 
94 #define SESSION_EVT_ENQ_HANDLER(_s, _len) \
95 { \
96  ELOG_TYPE_DECLARE (_e) = \
97  { \
98  .format = "enq: length %d", \
99  .format_args = "i4", \
100  }; \
101  DEC_SESSION_ETD(_s, _e, 1); \
102  ed->data[0] = _len; \
103 }
104 #else
105 #define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts)
106 #define SESSION_EVT_ENQ_HANDLER(_s, _body)
107 #endif /* SESSION_DEQ_NODE_EVTS */
108 
109 #if SESSION_DISPATCH_DBG
110 #define SESSION_EVT_DEQ_NODE_HANDLER(_wrk, _node_evt, _ntx) \
111 { \
112  ELOG_TYPE_DECLARE (_e) = \
113  { \
114  .format = "dispatch: %s pkts %u re-entry: %u dispatch %u", \
115  .format_args = "t4i4i4i4", \
116  .n_enum_strings = 2, \
117  .enum_strings = { \
118  "start", \
119  "end", \
120  }, \
121  }; \
122  DEC_SESSION_ED(_e, 4); \
123  ed->data[0] = _node_evt; \
124  ed->data[1] = _ntx; \
125  ed->data[2] = (_wrk->last_vlib_time - _wrk->last_event_poll) \
126  * 1000000.0; \
127  ed->data[3] = (vlib_time_now (_wrk->vm) - _wrk->last_vlib_time) \
128  * 1000000.0; \
129 }
130 #else
131 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt, _ntx)
132 #endif /* SESSION_DISPATCH_DBG */
133 
134 #if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
135 #define SESSION_EVT_POLL_GAP(_wrk) \
136 { \
137  ELOG_TYPE_DECLARE (_e) = \
138  { \
139  .format = "nixon-gap: %d us", \
140  .format_args = "i4", \
141  }; \
142  DEC_SESSION_ED(_e, 1); \
143  ed->data[0] = (u32) ((_wrk->last_vlib_time - _wrk->last_event_poll) \
144  *1000000.0); \
145 }
146 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) \
147 { \
148  if (PREDICT_TRUE (_wrk->last_event_poll != 0.0)) \
149  if (_wrk->last_vlib_time > _wrk->last_event_poll + 500e-6) \
150  SESSION_EVT_POLL_GAP(_wrk); \
151  _wrk->last_event_poll = _wrk->last_vlib_time; \
152 }
153 
154 #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) \
155 { \
156  f64 diff = vlib_time_now (vlib_get_main ()) - _wrk->last_event_poll; \
157  if (diff > 5e-2) \
158  { \
159  ELOG_TYPE_DECLARE (_e) = \
160  { \
161  .format = "dispatch time: %d us", \
162  .format_args = "i4", \
163  }; \
164  DEC_SESSION_ED(_e, 1); \
165  ed->data[0] = diff *1000000.0; \
166  } \
167 }
168 
169 #else
170 #define SESSION_EVT_POLL_GAP(_wrk)
171 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk)
172 #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk)
173 #endif /* SESSION_EVT_POLL_DBG */
174 
175 #define SESSION_EVT_DISPATCH_START_HANDLER(_wrk) \
176 { \
177  if (SESSION_DEQ_EVTS > 1) \
178  SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 0, 0); \
179  SESSION_EVT_POLL_GAP_TRACK_HANDLER (wrk); \
180 }
181 
182 #define SESSION_EVT_DISPATCH_END_HANDLER(_wrk, _ntx) \
183 { \
184  if (_ntx) \
185  SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 1, _ntx); \
186  SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk); \
187  _wrk->last_event_poll = vlib_time_now (_wrk->vm); \
188 }
189 
190 #define CONCAT_HELPER(_a, _b) _a##_b
191 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
192 #define SESSION_EVT(_evt, _args...) CC(_evt, _HANDLER)(_args)
193 
194 #else
195 #define SESSION_EVT(_evt, _args...)
196 #define SESSION_DBG(_fmt, _args...)
197 #endif /* SESSION_DEBUG */
198 
199 #endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "gnu")
205  * End:
206  */
#define foreach_session_dbg_evt
Definition: session_debug.h:21
enum _session_evt_dbg session_evt_dbg_e