FD.io VPP  v19.08-27-gf4dcae4
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_EVT_POLL_DBG (0)
41 #define SESSION_SM (0)
42 
43 #if SESSION_DEBUG
44 
45 #define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
46 
47 #define DEC_SESSION_ETD(_s, _e, _size) \
48  struct \
49  { \
50  u32 data[_size]; \
51  } * ed; \
52  transport_connection_t *_tc = session_get_transport (_s); \
53  ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
54  _e, _tc->elog_track)
55 
56 #define DEC_SESSION_ED(_e, _size) \
57  struct \
58  { \
59  u32 data[_size]; \
60  } * ed; \
61  ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
62 
63 #if SESSION_SM
64 #define SESSION_EVT_FREE_HANDLER(_s) \
65 { \
66  ELOG_TYPE_DECLARE (_e) = \
67  { \
68  .format = "free: idx %u", \
69  .format_args = "i4", \
70  }; \
71  DEC_SESSION_ETD(_s, _e, 1); \
72  ed->data[0] = _s->session_index; \
73 }
74 #else
75 #define SESSION_EVT_FREE_HANDLER(_s)
76 #endif
77 
78 #if SESSION_DEQ_EVTS
79 #define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) \
80 { \
81  ELOG_TYPE_DECLARE (_e) = \
82  { \
83  .format = "deq: now %u max %d evt %u ts %d", \
84  .format_args = "i4i4i4i4", \
85  }; \
86  DEC_SESSION_ETD(_s, _e, 4); \
87  ed->data[0] = _now; \
88  ed->data[1] = _max; \
89  ed->data[2] = _has_evt; \
90  ed->data[3] = _ts * 1000000.0; \
91 }
92 
93 #define SESSION_EVT_ENQ_HANDLER(_s, _len) \
94 { \
95  ELOG_TYPE_DECLARE (_e) = \
96  { \
97  .format = "enq: length %d", \
98  .format_args = "i4", \
99  }; \
100  DEC_SESSION_ETD(_s, _e, 1); \
101  ed->data[0] = _len; \
102 }
103 
104 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \
105 { \
106  ELOG_TYPE_DECLARE (_e) = \
107  { \
108  .format = "deq-node: %s", \
109  .format_args = "t4", \
110  .n_enum_strings = 2, \
111  .enum_strings = { \
112  "start", \
113  "end", \
114  }, \
115  }; \
116  DEC_SESSION_ED(_e, 1); \
117  ed->data[0] = _node_evt; \
118 }
119 #else
120 #define SESSION_EVT_DEQ_HANDLER(_s, _body)
121 #define SESSION_EVT_ENQ_HANDLER(_s, _body)
122 #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
123 #endif /* SESSION_DEQ_NODE_EVTS */
124 
125 #if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1
126 #define SESSION_EVT_POLL_GAP(_wrk) \
127 { \
128  ELOG_TYPE_DECLARE (_e) = \
129  { \
130  .format = "nixon-gap: %d us", \
131  .format_args = "i4", \
132  }; \
133  DEC_SESSION_ED(_e, 1); \
134  ed->data[0] = (u32) ((now - _wrk->last_event_poll)*1000000.0); \
135 }
136 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) \
137 { \
138  if (PREDICT_TRUE (smm->last_event_poll != 0.0)) \
139  if (now > smm->last_event_poll + 500e-6) \
140  SESSION_EVT_POLL_GAP(smm, _ti); \
141  _wrk->last_event_poll = now; \
142 }
143 
144 #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) \
145 { \
146  f64 diff = vlib_time_now (vlib_get_main ()) - _wrk->last_event_poll; \
147  if (diff > 5e-2) \
148  { \
149  ELOG_TYPE_DECLARE (_e) = \
150  { \
151  .format = "dispatch time: %d us", \
152  .format_args = "i4", \
153  }; \
154  DEC_SESSION_ED(_e, 1); \
155  ed->data[0] = diff *1000000.0; \
156  } \
157 }
158 
159 #else
160 #define SESSION_EVT_POLL_GAP(_wrk)
161 #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk)
162 #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk)
163 #endif /* SESSION_EVT_POLL_DBG */
164 
165 #define SESSION_EVT_DISPATCH_START_HANDLER(_wrk) \
166 { \
167  if (SESSION_DEQ_EVTS > 1) \
168  SESSION_EVT_DEQ_NODE_HANDLER (0); \
169  SESSION_EVT_POLL_GAP_TRACK_HANDLER (wrk); \
170 }
171 
172 #define SESSION_EVT_DISPATCH_END_HANDLER(_wrk, _ntx) \
173 { \
174  if (SESSION_DEQ_EVTS > 1 || _ntx) \
175  SESSION_EVT_DEQ_NODE_HANDLER (1); \
176  SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk); \
177 }
178 
179 #define CONCAT_HELPER(_a, _b) _a##_b
180 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
181 #define SESSION_EVT(_evt, _args...) CC(_evt, _HANDLER)(_args)
182 
183 #else
184 #define SESSION_EVT(_evt, _args...)
185 #define SESSION_DBG(_fmt, _args...)
186 #endif /* SESSION_DEBUG */
187 
188 #endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
189 /*
190  * fd.io coding-style-patch-verification: ON
191  *
192  * Local Variables:
193  * eval: (c-set-style "gnu")
194  * End:
195  */
#define foreach_session_dbg_evt
Definition: session_debug.h:21
enum _session_evt_dbg session_evt_dbg_e