From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Sven Schnelle <svens@linux.ibm.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>, Guo Ren <guoren@kernel.org>,
Donglin Peng <dolinux.peng@gmail.com>,
Zheng Yejian <zhengyejian@huaweicloud.com>,
bpf@vger.kernel.org
Subject: Re: [PATCH v2 1/4] ftrace: Add print_function_args()
Date: Mon, 23 Dec 2024 16:36:00 -0500 [thread overview]
Message-ID: <20241223163600.7162a557@gandalf.local.home> (raw)
In-Reply-To: <20241223201541.898496620@goodmis.org>
On Mon, 23 Dec 2024 15:13:48 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> +#ifdef CONFIG_FUNCTION_TRACE_ARGS
> +void print_function_args(struct trace_seq *s, unsigned long *args,
> + unsigned long func)
> +{
> + const struct btf_param *param;
> + const struct btf_type *t;
> + const char *param_name;
> + char name[KSYM_NAME_LEN];
> + unsigned long arg;
> + struct btf *btf;
> + s32 tid, nr = 0;
> + int i;
> +
> + trace_seq_printf(s, "(");
> +
> + if (!args)
> + goto out;
> + if (lookup_symbol_name(func, name))
> + goto out;
> +
> + btf = bpf_get_btf_vmlinux();
> + if (IS_ERR_OR_NULL(btf))
> + goto out;
> +
> + t = btf_find_func_proto(name, &btf);
> + if (IS_ERR_OR_NULL(t))
> + goto out;
> +
> + param = btf_get_func_param(t, &nr);
> + if (!param)
> + goto out_put;
> +
> + for (i = 0; i < nr; i++) {
> + /* This only prints what the arch allows (6 args by default) */
> + if (i == FTRACE_REGS_MAX_ARGS) {
> + trace_seq_puts(s, "...");
> + break;
> + }
> +
> + arg = args[i];
> +
> + param_name = btf_name_by_offset(btf, param[i].name_off);
> + if (param_name)
> + trace_seq_printf(s, "%s=", param_name);
> + t = btf_type_skip_modifiers(btf, param[i].type, &tid);
> +
> + switch (t ? BTF_INFO_KIND(t->info) : BTF_KIND_UNKN) {
> + case BTF_KIND_UNKN:
> + trace_seq_putc(s, '?');
> + /* Still print unknown type values */
> + fallthrough;
> + case BTF_KIND_PTR:
> + trace_seq_printf(s, "0x%lx", arg);
> + break;
> + case BTF_KIND_INT:
> + trace_seq_printf(s, "%ld", arg);
> + break;
> + case BTF_KIND_ENUM:
> + trace_seq_printf(s, "%ld", arg);
> + break;
> + default:
> + /* This does not handle complex arguments */
> + trace_seq_printf(s, "0x%lx (%s)", arg, btf_type_str(t));
This will need to take into account the size of the type. STRUCTs show up,
and most of the time they are simply the size of the architecture's word.
But I hit this:
timespec64_add_safe(lhs=0x6c2 (STRUCT), rhs=0x39c4153f (STRUCT))
Where it definitely isn't correct, as we have:
struct timespec64 {
time64_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
struct timespec64 timespec64_add_safe(const struct timespec64 lhs,
const struct timespec64 rhs)
> + break;
> + }
> + if (i < nr - 1)
> + trace_seq_printf(s, ", ");
> + }
> +out_put:
> + btf_put(btf);
> +out:
> + trace_seq_printf(s, ")");
> +}
> +#endif
> +
I updated to this (separating the args array from the BTF parameters):
@@ -684,6 +683,91 @@ int trace_print_lat_context(struct trace_iterator *iter)
return !trace_seq_has_overflowed(s);
}
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, unsigned long *args,
+ unsigned long func)
+{
+ const struct btf_param *param;
+ const struct btf_type *t;
+ const char *param_name;
+ char name[KSYM_NAME_LEN];
+ unsigned long arg;
+ struct btf *btf;
+ s32 tid, nr = 0;
+ int a, p, x;
+
+ trace_seq_printf(s, "(");
+
+ if (!args)
+ goto out;
+ if (lookup_symbol_name(func, name))
+ goto out;
+
+ btf = bpf_get_btf_vmlinux();
+ if (IS_ERR_OR_NULL(btf))
+ goto out;
+
+ t = btf_find_func_proto(name, &btf);
+ if (IS_ERR_OR_NULL(t))
+ goto out;
+
+ param = btf_get_func_param(t, &nr);
+ if (!param)
+ goto out_put;
+
+ for (a = 0, p = 0; p < nr; a++, p++) {
+ if (p)
+ trace_seq_puts(s, ", ");
+
+ /* This only prints what the arch allows (6 args by default) */
+ if (a == FTRACE_REGS_MAX_ARGS) {
+ trace_seq_puts(s, "...");
+ break;
+ }
+
+ arg = args[a];
+
+ param_name = btf_name_by_offset(btf, param[p].name_off);
+ if (param_name)
+ trace_seq_printf(s, "%s=", param_name);
+ t = btf_type_skip_modifiers(btf, param[p].type, &tid);
+
+ switch (t ? BTF_INFO_KIND(t->info) : BTF_KIND_UNKN) {
+ case BTF_KIND_UNKN:
+ trace_seq_putc(s, '?');
+ /* Still print unknown type values */
+ fallthrough;
+ case BTF_KIND_PTR:
+ trace_seq_printf(s, "0x%lx", arg);
+ break;
+ case BTF_KIND_INT:
+ trace_seq_printf(s, "%ld", arg);
+ break;
+ case BTF_KIND_ENUM:
+ trace_seq_printf(s, "%ld", arg);
+ break;
+ default:
+ /* This does not handle complex arguments */
+ trace_seq_printf(s, "(%s)[0x%lx", btf_type_str(t), arg);
+ for (x = sizeof(long); x < t->size; x += sizeof(long)) {
+ trace_seq_putc(s, ':');
+ if (++a == FTRACE_REGS_MAX_ARGS) {
+ trace_seq_puts(s, "...]");
+ goto out_put;
+ }
+ trace_seq_printf(s, "0x%lx", args[a]);
+ }
+ trace_seq_putc(s, ']');
+ break;
+ }
+ }
+out_put:
+ btf_put(btf);
+out:
+ trace_seq_printf(s, ")");
+}
+#endif
+
/**
* ftrace_find_event - find a registered event
* @type: the type of event to look for
And now I get this as output:
less-912 [006] ...1. 240.085082: timespec64_add_safe(lhs=(STRUCT)[0xef:0x10c8f152], rhs=(STRUCT)[0x4:0x0]) <-__se_sys_poll
less-914 [006] ...1. 241.241416: timespec64_add_safe(lhs=(STRUCT)[0xf0:0x1a1af859], rhs=(STRUCT)[0x4:0x0]) <-__se_sys_poll
less-916 [006] ...1. 242.653586: timespec64_add_safe(lhs=(STRUCT)[0xf1:0x32ac56c9], rhs=(STRUCT)[0x4:0x0]) <-__se_sys_poll
wpa_supplicant-488 [004] ...1. 246.771910: timespec64_add_safe(lhs=(STRUCT)[0xf5:0x39ba39d3], rhs=(STRUCT)[0x9:0x3b9ac618]) <-__se_sys_pselect6
wpa_supplicant-488 [004] ...1. 256.783841: timespec64_add_safe(lhs=(STRUCT)[0xff:0x3a714d62], rhs=(STRUCT)[0xa:0x0]) <-__se_sys_pselect6
NetworkManager-485 [006] ...1. 257.008653: timespec64_add_safe(lhs=(STRUCT)[0x100:0xc3ce7d5], rhs=(STRUCT)[0x0:0x16358818]) <-__se_sys_ppoll
NetworkManager-485 [006] ...1. 257.008676: timespec64_add_safe(lhs=(STRUCT)[0x100:0xc3d477e], rhs=(STRUCT)[0x0:0x16352288]) <-__se_sys_ppoll
NetworkManager-485 [006] ...1. 257.383973: timespec64_add_safe(lhs=(STRUCT)[0x100:0x229be0b6], rhs=(STRUCT)[0x11:0x11c46e70]) <-__se_sys_ppoll
Which looks much more reasonable.
-- Steve
next prev parent reply other threads:[~2024-12-23 21:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-23 20:13 [PATCH v2 0/4] ftrace: Add function arguments to function tracers Steven Rostedt
2024-12-23 20:13 ` [PATCH v2 1/4] ftrace: Add print_function_args() Steven Rostedt
2024-12-23 21:36 ` Steven Rostedt [this message]
2024-12-25 13:15 ` Masami Hiramatsu
2024-12-25 21:59 ` Steven Rostedt
[not found] ` <CAErzpms4g8=3486Uv-PPxiA0GSkNQQm1Ez67eo-H3LtAhTAJCA@mail.gmail.com>
2025-01-08 4:52 ` Masami Hiramatsu
2025-01-08 11:19 ` Alan Maguire
2025-01-08 15:24 ` Steven Rostedt
2025-01-08 15:39 ` Alan Maguire
2024-12-23 20:13 ` [PATCH v2 2/4] ftrace: Add support for function argument to graph tracer Steven Rostedt
2024-12-25 15:41 ` Masami Hiramatsu
2024-12-25 22:02 ` Steven Rostedt
2024-12-23 20:13 ` [PATCH v2 3/4] ftrace: Have funcgraph-args take affect during tracing Steven Rostedt
2024-12-25 14:23 ` Masami Hiramatsu
2024-12-23 20:13 ` [PATCH v2 4/4] ftrace: Add arguments to function tracer Steven Rostedt
2024-12-25 14:21 ` Masami Hiramatsu
2024-12-25 21:40 ` [PATCH v2 0/4] ftrace: Add function arguments to function tracers Jiri Olsa
2024-12-25 21:56 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241223163600.7162a557@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=aou@eecs.berkeley.edu \
--cc=bpf@vger.kernel.org \
--cc=dolinux.peng@gmail.com \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=svens@linux.ibm.com \
--cc=zhengyejian@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).