4c74927df68555e424245cba2ec0e25e5b7edcb4
[linux-2.6-block.git] / net / tipc / trace.h
1 /*
2  * net/tipc/trace.h: TIPC tracepoints
3  *
4  * Copyright (c) 2018, Ericsson AB
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the names of the copyright holders nor the names of its
16  *    contributors may be used to endorse or promote products derived from
17  *    this software without specific prior written permission.
18  *
19  * Alternatively, this software may be distributed under the terms of the
20  * GNU General Public License ("GPL") version 2 as published by the Free
21  * Software Foundation.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #undef TRACE_SYSTEM
37 #define TRACE_SYSTEM tipc
38
39 #if !defined(_TIPC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
40 #define _TIPC_TRACE_H
41
42 #include <linux/tracepoint.h>
43 #include "core.h"
44 #include "link.h"
45 #include "socket.h"
46 #include "node.h"
47
48 #define SKB_LMIN        (100)
49 #define SKB_LMAX        (SKB_LMIN * 2)
50 #define LIST_LMIN       (SKB_LMIN * 3)
51 #define LIST_LMAX       (SKB_LMIN * 11)
52 #define SK_LMIN         (SKB_LMIN * 2)
53 #define SK_LMAX         (SKB_LMIN * 11)
54 #define LINK_LMIN       (SKB_LMIN)
55 #define LINK_LMAX       (SKB_LMIN * 16)
56 #define NODE_LMIN       (SKB_LMIN)
57 #define NODE_LMAX       (SKB_LMIN * 11)
58
59 #ifndef __TIPC_TRACE_ENUM
60 #define __TIPC_TRACE_ENUM
61 enum {
62         TIPC_DUMP_NONE          = 0,
63
64         TIPC_DUMP_TRANSMQ       = 1,
65         TIPC_DUMP_BACKLOGQ      = (1 << 1),
66         TIPC_DUMP_DEFERDQ       = (1 << 2),
67         TIPC_DUMP_INPUTQ        = (1 << 3),
68         TIPC_DUMP_WAKEUP        = (1 << 4),
69
70         TIPC_DUMP_SK_SNDQ       = (1 << 8),
71         TIPC_DUMP_SK_RCVQ       = (1 << 9),
72         TIPC_DUMP_SK_BKLGQ      = (1 << 10),
73         TIPC_DUMP_ALL           = 0xffffu
74 };
75 #endif
76
77 int tipc_skb_dump(struct sk_buff *skb, bool more, char *buf);
78 int tipc_list_dump(struct sk_buff_head *list, bool more, char *buf);
79 int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf);
80 int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf);
81 int tipc_node_dump(struct tipc_node *n, bool more, char *buf);
82
83 DECLARE_EVENT_CLASS(tipc_skb_class,
84
85         TP_PROTO(struct sk_buff *skb, bool more, const char *header),
86
87         TP_ARGS(skb, more, header),
88
89         TP_STRUCT__entry(
90                 __string(header, header)
91                 __dynamic_array(char, buf, (more) ? SKB_LMAX : SKB_LMIN)
92         ),
93
94         TP_fast_assign(
95                 __assign_str(header, header);
96                 tipc_skb_dump(skb, more, __get_str(buf));
97         ),
98
99         TP_printk("%s\n%s", __get_str(header), __get_str(buf))
100 )
101
102 #define DEFINE_SKB_EVENT(name) \
103 DEFINE_EVENT(tipc_skb_class, name, \
104         TP_PROTO(struct sk_buff *skb, bool more, const char *header), \
105         TP_ARGS(skb, more, header))
106 DEFINE_SKB_EVENT(tipc_skb_dump);
107
108 DECLARE_EVENT_CLASS(tipc_list_class,
109
110         TP_PROTO(struct sk_buff_head *list, bool more, const char *header),
111
112         TP_ARGS(list, more, header),
113
114         TP_STRUCT__entry(
115                 __string(header, header)
116                 __dynamic_array(char, buf, (more) ? LIST_LMAX : LIST_LMIN)
117         ),
118
119         TP_fast_assign(
120                 __assign_str(header, header);
121                 tipc_list_dump(list, more, __get_str(buf));
122         ),
123
124         TP_printk("%s\n%s", __get_str(header), __get_str(buf))
125 );
126
127 #define DEFINE_LIST_EVENT(name) \
128 DEFINE_EVENT(tipc_list_class, name, \
129         TP_PROTO(struct sk_buff_head *list, bool more, const char *header), \
130         TP_ARGS(list, more, header))
131 DEFINE_LIST_EVENT(tipc_list_dump);
132
133 DECLARE_EVENT_CLASS(tipc_sk_class,
134
135         TP_PROTO(struct sock *sk, struct sk_buff *skb, u16 dqueues,
136                  const char *header),
137
138         TP_ARGS(sk, skb, dqueues, header),
139
140         TP_STRUCT__entry(
141                 __string(header, header)
142                 __field(u32, portid)
143                 __dynamic_array(char, buf, (dqueues) ? SK_LMAX : SK_LMIN)
144                 __dynamic_array(char, skb_buf, (skb) ? SKB_LMIN : 1)
145         ),
146
147         TP_fast_assign(
148                 __assign_str(header, header);
149                 __entry->portid = tipc_sock_get_portid(sk);
150                 tipc_sk_dump(sk, dqueues, __get_str(buf));
151                 if (skb)
152                         tipc_skb_dump(skb, false, __get_str(skb_buf));
153                 else
154                         *(__get_str(skb_buf)) = '\0';
155         ),
156
157         TP_printk("<%u> %s\n%s%s", __entry->portid, __get_str(header),
158                   __get_str(skb_buf), __get_str(buf))
159 );
160
161 #define DEFINE_SK_EVENT(name) \
162 DEFINE_EVENT(tipc_sk_class, name, \
163         TP_PROTO(struct sock *sk, struct sk_buff *skb, u16 dqueues, \
164                  const char *header), \
165         TP_ARGS(sk, skb, dqueues, header))
166 DEFINE_SK_EVENT(tipc_sk_dump);
167
168 DECLARE_EVENT_CLASS(tipc_link_class,
169
170         TP_PROTO(struct tipc_link *l, u16 dqueues, const char *header),
171
172         TP_ARGS(l, dqueues, header),
173
174         TP_STRUCT__entry(
175                 __string(header, header)
176                 __array(char, name, TIPC_MAX_LINK_NAME)
177                 __dynamic_array(char, buf, (dqueues) ? LINK_LMAX : LINK_LMIN)
178         ),
179
180         TP_fast_assign(
181                 __assign_str(header, header);
182                 tipc_link_name_ext(l, __entry->name);
183                 tipc_link_dump(l, dqueues, __get_str(buf));
184         ),
185
186         TP_printk("<%s> %s\n%s", __entry->name, __get_str(header),
187                   __get_str(buf))
188 );
189
190 #define DEFINE_LINK_EVENT(name) \
191 DEFINE_EVENT(tipc_link_class, name, \
192         TP_PROTO(struct tipc_link *l, u16 dqueues, const char *header), \
193         TP_ARGS(l, dqueues, header))
194 DEFINE_LINK_EVENT(tipc_link_dump);
195
196 DECLARE_EVENT_CLASS(tipc_node_class,
197
198         TP_PROTO(struct tipc_node *n, bool more, const char *header),
199
200         TP_ARGS(n, more, header),
201
202         TP_STRUCT__entry(
203                 __string(header, header)
204                 __field(u32, addr)
205                 __dynamic_array(char, buf, (more) ? NODE_LMAX : NODE_LMIN)
206         ),
207
208         TP_fast_assign(
209                 __assign_str(header, header);
210                 __entry->addr = tipc_node_get_addr(n);
211                 tipc_node_dump(n, more, __get_str(buf));
212         ),
213
214         TP_printk("<%x> %s\n%s", __entry->addr, __get_str(header),
215                   __get_str(buf))
216 );
217
218 #define DEFINE_NODE_EVENT(name) \
219 DEFINE_EVENT(tipc_node_class, name, \
220         TP_PROTO(struct tipc_node *n, bool more, const char *header), \
221         TP_ARGS(n, more, header))
222 DEFINE_NODE_EVENT(tipc_node_dump);
223
224 #endif /* _TIPC_TRACE_H */
225
226 /* This part must be outside protection */
227 #undef TRACE_INCLUDE_PATH
228 #define TRACE_INCLUDE_PATH .
229 #undef TRACE_INCLUDE_FILE
230 #define TRACE_INCLUDE_FILE trace
231 #include <trace/define_trace.h>