Skip to content

Commit d331a73

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Provide debug messages as trace events
A private debug logging infrastructure is currently provided via $debug_fs/batman_adv/*/log when CONFIG_BATMAN_ADV_DEBUG is enabled. This is not well integrated in the rest of the tracing infrastructure of the kernel. Other components (like mac80211 or ath10k) allow to gather the debug messages using generic trace events which are better integrated. This makes it possible to interact with them using the existing userspace tools. The tracepoint batadv:batadv_dbg will now be available when CONFIG_BATMAN_ADV_DEBUG and CONFIG_BATMAN_ADV_TRACING is activated. The log level mask is still used for filtering as usual. A full system trace for offline parsing can be created (and read) using: $ batctl ll all $ trace-cmd record -e batadv:batadv_dbg $ trace-cmd report The same can also be done without recording to a file $ batctl ll all $ trace-cmd stream -e batadv:batadv_dbg The trace infrastructure is especially helpful when tracing processes: $ batctl ll all $ ./tools/perf/perf trace --event "batadv:*" batctl p 10.204.32.1 0.000 batadv:batadv_dbg:batman_adv bat0 Parsing outgoing ARP REQUEST 0.045 batadv:batadv_dbg:batman_adv bat0 ARP MSG = [src: a2:64:14:53:f8:22-10.204.32.185 dst: 00:00:00:00:00:00-10.204.32.1] 0.067 batadv:batadv_dbg:batman_adv bat0 Entry updated: 10.204.32.185 a2:64:14:53:f8:22 (vid: -1) 0.099 batadv:batadv_dbg:batman_adv bat0 batadv_dat_select_candidates(): IP=10.204.32.1 hash(IP)=48902 0.757 batadv:batadv_dbg:batman_adv bat0 dat_select_candidates() 0: selected fe:2c:91:68:29:2b addr=48977 dist=65460 1.178 batadv:batadv_dbg:batman_adv bat0 dat_select_candidates() 1: selected fe:81:ab:c5:e3:03 addr=49181 dist=65256 1.809 batadv:batadv_dbg:batman_adv bat0 dat_select_candidates() 2: selected 66:25:a7:48:37:fb addr=49328 dist=65109 1.828 batadv:batadv_dbg:batman_adv bat0 DHT_SEND for 10.204.32.1 Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent 00caf6a commit d331a73

5 files changed

Lines changed: 127 additions & 5 deletions

File tree

‎net/batman-adv/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,14 @@ config BATMAN_ADV_DEBUG
106106
say N here. This enables compilation of support for
107107
outputting debugging information to the kernel log. The
108108
output is controlled via the module parameter debug.
109+
110+
config BATMAN_ADV_TRACING
111+
bool "B.A.T.M.A.N. tracing support"
112+
depends on BATMAN_ADV
113+
depends on EVENT_TRACING
114+
help
115+
This is an option for use by developers; most people should
116+
say N here. Select this option to gather traces like the debug
117+
messages using the generic tracing infrastructure of the kernel.
118+
BATMAN_ADV_DEBUG must also be selected to get trace events for
119+
batadv_dbg.

‎net/batman-adv/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ batman-adv-y += routing.o
4242
batman-adv-y += send.o
4343
batman-adv-y += soft-interface.o
4444
batman-adv-y += sysfs.o
45+
batman-adv-$(CONFIG_BATMAN_ADV_TRACING) += trace.o
4546
batman-adv-y += tp_meter.o
4647
batman-adv-y += translation-table.o
4748
batman-adv-y += tvlv.o
49+
50+
CFLAGS_trace.o := -I$(src)

‎net/batman-adv/log.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <stdarg.h>
4242

4343
#include "debugfs.h"
44+
#include "trace.h"
4445

4546
#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
4647

@@ -100,13 +101,19 @@ static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
100101
*/
101102
int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
102103
{
104+
struct va_format vaf;
103105
va_list args;
104-
char tmp_log_buf[256];
105106

106107
va_start(args, fmt);
107-
vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
108-
batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
109-
jiffies_to_msecs(jiffies), tmp_log_buf);
108+
109+
vaf.fmt = fmt;
110+
vaf.va = &args;
111+
112+
batadv_fdebug_log(bat_priv->debug_log, "[%10u] %pV",
113+
jiffies_to_msecs(jiffies), &vaf);
114+
115+
trace_batadv_dbg(bat_priv, &vaf);
116+
110117
va_end(args);
111118

112119
return 0;
@@ -117,7 +124,8 @@ static int batadv_log_open(struct inode *inode, struct file *file)
117124
if (!try_module_get(THIS_MODULE))
118125
return -EBUSY;
119126

120-
batadv_debugfs_deprecated(file, "");
127+
batadv_debugfs_deprecated(file,
128+
"Use tracepoint batadv:batadv_dbg instead\n");
121129

122130
nonseekable_open(inode, file);
123131
file->private_data = inode->i_private;

‎net/batman-adv/trace.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
3+
*
4+
* Sven Eckelmann
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of version 2 of the GNU General Public
8+
* License as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include <linux/module.h>
20+
21+
#define CREATE_TRACE_POINTS
22+
#include "trace.h"

‎net/batman-adv/trace.h‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
3+
*
4+
* Sven Eckelmann
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of version 2 of the GNU General Public
8+
* License as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#if !defined(_NET_BATMAN_ADV_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
20+
#define _NET_BATMAN_ADV_TRACE_H_
21+
22+
#include "main.h"
23+
24+
#include <linux/tracepoint.h>
25+
26+
#undef TRACE_SYSTEM
27+
#define TRACE_SYSTEM batadv
28+
29+
/* provide dummy function when tracing is disabled */
30+
#if !defined(CONFIG_BATMAN_ADV_TRACING)
31+
32+
#undef TRACE_EVENT
33+
#define TRACE_EVENT(name, proto, ...) \
34+
static inline void trace_ ## name(proto) {}
35+
36+
#endif /* CONFIG_BATMAN_ADV_TRACING */
37+
38+
#define BATADV_MAX_MSG_LEN 256
39+
40+
TRACE_EVENT(batadv_dbg,
41+
42+
TP_PROTO(struct batadv_priv *bat_priv,
43+
struct va_format *vaf),
44+
45+
TP_ARGS(bat_priv, vaf),
46+
47+
TP_STRUCT__entry(
48+
__string(device, bat_priv->soft_iface->name)
49+
__string(driver, KBUILD_MODNAME)
50+
__dynamic_array(char, msg, BATADV_MAX_MSG_LEN)
51+
),
52+
53+
TP_fast_assign(
54+
__assign_str(device, bat_priv->soft_iface->name);
55+
__assign_str(driver, KBUILD_MODNAME);
56+
WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
57+
BATADV_MAX_MSG_LEN,
58+
vaf->fmt,
59+
*vaf->va) >= BATADV_MAX_MSG_LEN);
60+
),
61+
62+
TP_printk(
63+
"%s %s %s",
64+
__get_str(driver),
65+
__get_str(device),
66+
__get_str(msg)
67+
)
68+
);
69+
70+
#endif /* _NET_BATMAN_ADV_TRACE_H_ || TRACE_HEADER_MULTI_READ */
71+
72+
#undef TRACE_INCLUDE_PATH
73+
#define TRACE_INCLUDE_PATH .
74+
#undef TRACE_INCLUDE_FILE
75+
#define TRACE_INCLUDE_FILE trace
76+
77+
/* This part must be outside protection */
78+
#include <trace/define_trace.h>

0 commit comments

Comments
 (0)