linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: "Jiri Olsa" <jolsa@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Clark Williams" <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	"Arnaldo Carvalho de Melo" <acme@redhat.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Luis Cláudio Gonçalves" <lclaudio@redhat.com>
Subject: [PATCH 24/69] perf trace: Allow choosing how to augment the tracepoint arguments
Date: Fri, 11 Oct 2019 17:05:14 -0300	[thread overview]
Message-ID: <20191011200559.7156-25-acme@kernel.org> (raw)
In-Reply-To: <20191011200559.7156-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

So far we used the libtraceevent printing routines when showing
tracepoint arguments, but since 'perf trace' has a lot of beautifiers
for syscall arguments, and since some of those can be used to augment
tracepoint arguments, add a routine to make use of those beautifiers
and allow the user to choose which one to use.

The default now is to use the same beautifiers used for the strace-like
sys_enter+sys_exit lines, but the user can choose the libtraceevent ones
by either using the:

    perf trace --libtraceevent_print

command line option, or by setting:

  # cat ~/.perfconfig
  [trace]
	tracepoint_beautifiers = libtraceevent

For instance, here are some examples:

  # perf trace -e sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
       0.000 sched:sched_wakeup(comm: "perf", pid: 5273 (perf), prio: 120, success: 1, target_cpu: 6)
       0.621 nanosleep(rqtp: 0x7ffdd06d1140, rmtp: NULL) ...
       0.628 sched:sched_switch(prev_comm: "sleep", prev_pid: 5273 (sleep), prev_prio: 120, prev_state: 1, next_comm: "swapper/6", next_pid: 0, next_prio: 120)
    1000.879 sched:sched_wakeup(comm: "sleep", pid: 5273 (sleep), prio: 120, success: 1, target_cpu: 6)
       0.621  ... [continued]: nanosleep())          = 0
    1001.026 exit_group(error_code: 0)               = ?
    1001.216 sched:sched_process_exit(comm: "sleep", pid: 5273 (sleep), prio: 120)
  #

And then using libtraceevent, as before:

  # perf trace --libtraceevent_print -e sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
       0.000 sched:sched_wakeup(comm=perf pid=5288 prio=120 target_cpu=001)
       0.739 nanosleep(rqtp: 0x7ffeba6c2f40, rmtp: NULL) ...
       0.747 sched:sched_switch(prev_comm=sleep prev_pid=5288 prev_prio=120 prev_state=S ==> next_comm=swapper/1 next_pid=0 next_prio=120)
    1000.902 sched:sched_wakeup(comm=sleep pid=5288 prio=120 target_cpu=001)
       0.739  ... [continued]: nanosleep())          = 0
    1001.012 exit_group(error_code: 0)               = ?
  #

The new default allocates an array of 'struct syscall_arg_fmt' for the
tracepoint arguments and, just like with syscall arguments, tries to
find suitable syscall_arg__scnprintf_NAME() routines to augment those
tracepoint arguments based on their type (as in the tracefs "format"
file), or even in their name + type, for instance arguntents with names
ending in "fd" with type "int" get the fd scnprintf beautifier attached,
etc.

Soon this will take advantage of the kernel BTF information to augment
enumerations based on the tracefs "format" type info.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-o8qdluotkcb3b1x2gjqrejcl@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt |  5 ++
 tools/perf/Documentation/perf-trace.txt  |  5 ++
 tools/perf/builtin-trace.c               | 83 +++++++++++++++++++++++-
 3 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index c599623a1f3d..c4dd23c4b478 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -561,6 +561,11 @@ trace.*::
 	trace.show_zeros::
 		Do not suppress syscall arguments that are equal to zero.
 
+	trace.tracepoint_beautifiers::
+		Use "libtraceevent" to use that library to augment the tracepoint arguments,
+		"libbeauty", the default, to use the same argument beautifiers used in the
+		strace-like sys_enter+sys_exit lines.
+
 llvm.*::
 	llvm.clang-path::
 		Path to clang. If omit, search it from $PATH.
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index 25b74fdb36fa..ba16cd5b680f 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -219,6 +219,11 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
 	may happen, for instance, when a thread gets migrated to a different CPU
 	while processing a syscall.
 
+--libtraceevent_print::
+	Use libtraceevent to print tracepoint arguments. By default 'perf trace' uses
+	the same beautifiers used in the strace-like enter+exit lines to augment the
+	tracepoint arguments.
+
 --map-dump::
 	Dump BPF maps setup by events passed via -e, for instance the augmented_raw_syscalls
 	living in tools/perf/examples/bpf/augmented_raw_syscalls.c. For now this
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 297aeaa9f69d..8303d83cb93c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -175,6 +175,7 @@ struct trace {
 	bool			print_sample;
 	bool			show_tool_stats;
 	bool			trace_syscalls;
+	bool			libtraceevent_print;
 	bool			kernel_syscallchains;
 	s16			args_alignment;
 	bool			show_tstamp;
@@ -2397,6 +2398,71 @@ static void bpf_output__fprintf(struct trace *trace,
 	++trace->nr_events_printed;
 }
 
+static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample,
+				       struct thread *thread, void *augmented_args, int augmented_args_size)
+{
+	char bf[2048];
+	size_t size = sizeof(bf);
+	struct tep_format_field *field = evsel->tp_format->format.fields;
+	struct syscall_arg_fmt *arg = evsel->priv;
+	size_t printed = 0;
+	unsigned long val;
+	u8 bit = 1;
+	struct syscall_arg syscall_arg = {
+		.augmented = {
+			.size = augmented_args_size,
+			.args = augmented_args,
+		},
+		.idx	= 0,
+		.mask	= 0,
+		.trace  = trace,
+		.thread = thread,
+		.show_string_prefix = trace->show_string_prefix,
+	};
+
+	for (; field && arg; field = field->next, ++syscall_arg.idx, bit <<= 1, ++arg) {
+		if (syscall_arg.mask & bit)
+			continue;
+
+		syscall_arg.fmt = arg;
+		if (field->flags & TEP_FIELD_IS_ARRAY)
+			val = (uintptr_t)(sample->raw_data + field->offset);
+		else
+			val = format_field__intval(field, sample, evsel->needs_swap);
+		/*
+		 * Some syscall args need some mask, most don't and
+		 * return val untouched.
+		 */
+		val = syscall_arg_fmt__mask_val(arg, &syscall_arg, val);
+
+		/*
+		 * Suppress this argument if its value is zero and
+		 * and we don't have a string associated in an
+		 * strarray for it.
+		 */
+		if (val == 0 &&
+		    !trace->show_zeros &&
+		    !((arg->show_zero ||
+		       arg->scnprintf == SCA_STRARRAY ||
+		       arg->scnprintf == SCA_STRARRAYS) &&
+		      arg->parm))
+			continue;
+
+		printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : "");
+
+		/*
+		 * XXX Perhaps we should have a show_tp_arg_names,
+		 * leaving show_arg_names just for syscalls?
+		 */
+		if (1 || trace->show_arg_names)
+			printed += scnprintf(bf + printed, size - printed, "%s: ", field->name);
+
+		printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val);
+	}
+
+	return printed + fprintf(trace->output, "%s", bf);
+}
+
 static int trace__event_handler(struct trace *trace, struct evsel *evsel,
 				union perf_event *event __maybe_unused,
 				struct perf_sample *sample)
@@ -2457,9 +2523,13 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
 	} else if (evsel->tp_format) {
 		if (strncmp(evsel->tp_format->name, "sys_enter_", 10) ||
 		    trace__fprintf_sys_enter(trace, evsel, sample)) {
-			event_format__fprintf(evsel->tp_format, sample->cpu,
-					      sample->raw_data, sample->raw_size,
-					      trace->output);
+			if (trace->libtraceevent_print) {
+				event_format__fprintf(evsel->tp_format, sample->cpu,
+						      sample->raw_data, sample->raw_size,
+						      trace->output);
+			} else {
+				trace__fprintf_tp_fields(trace, evsel, sample, thread, NULL, 0);
+			}
 			++trace->nr_events_printed;
 
 			if (evsel->max_events != ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) {
@@ -4150,6 +4220,11 @@ static int trace__config(const char *var, const char *value, void *arg)
 		int args_alignment = 0;
 		if (perf_config_int(&args_alignment, var, value) == 0)
 			trace->args_alignment = args_alignment;
+	} else if (!strcmp(var, "trace.tracepoint_beautifiers")) {
+		if (strcasecmp(value, "libtraceevent") == 0)
+			trace->libtraceevent_print = true;
+		else if (strcasecmp(value, "libbeauty") == 0)
+			trace->libtraceevent_print = false;
 	}
 out:
 	return err;
@@ -4239,6 +4314,8 @@ int cmd_trace(int argc, const char **argv)
 	OPT_CALLBACK(0, "call-graph", &trace.opts,
 		     "record_mode[,record_size]", record_callchain_help,
 		     &record_parse_callchain_opt),
+	OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print,
+		    "Use libtraceevent to print the tracepoint arguments."),
 	OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
 		    "Show the kernel callchains on the syscall exit path"),
 	OPT_ULONG(0, "max-events", &trace.max_events,
-- 
2.21.0


  parent reply	other threads:[~2019-10-11 20:08 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 20:04 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 01/69] perf env: Add routine to read the env->cpuid from the running machine Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 02/69] perf top: Initialize perf_env->cpuid, needed by the per arch annotation init routine Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 03/69] perf evlist: Adopt __set_tracepoint_handlers method from perf_session Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 04/69] perf trace: Make evlist__set_evsel_handler() affect just entries without a handler Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 05/69] perf trace: Separate 'struct syscall_fmt' definition from syscall_fmts variable Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 06/69] perf trace: Generalize the syscall_fmt find routines Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 07/69] perf trace: Postpone parsing .perfconfig trace.add_events to after --verbose is processed Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 08/69] perf trace augmented_syscalls: Do not show syscalls when none was asked for Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 09/69] perf scripts python: exported-sql-viewer.py: Add LookupModel() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 10/69] perf scripts python: exported-sql-viewer.py: Add HBoxLayout and VBoxLayout Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 11/69] perf scripts python: exported-sql-viewer.py: Add global time range calculations Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 12/69] perf scripts python: exported-sql-viewer.py: Tidy up Call tree call_time Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 13/69] perf scripts python: exported-sql-viewer.py: Add ability for Call tree to open at a specified task and time Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 14/69] perf scripts python: exported-sql-viewer.py: Add Time chart by CPU Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 15/69] perf tools: Make usage of test_attr__* optional for perf-sys.h Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 16/69] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 17/69] perf script: Allow --time with --reltime Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 18/69] perf trace: Factor out the initialization of syscal_arg_fmt->scnprintf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 19/69] perf trace: Allocate an array of beautifiers for tracepoint args Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 20/69] perf trace: Move some scnprintf methods from syscall to syscall_arg_fmt Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 21/69] perf trace: Add the syscall_arg_fmt pointer to syscall_arg Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 22/69] perf trace: Add array of chars scnprintf beautifier Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 23/69] perf trace: Enclose all events argument lists with () Arnaldo Carvalho de Melo
2019-10-11 20:05 ` Arnaldo Carvalho de Melo [this message]
2019-10-11 20:05 ` [PATCH 25/69] tools arch x86: Grab a copy of the file containing the MSR numbers Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 26/69] perf beauty: Make strarray's offset be u64 Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 27/69] perf trace beauty: Add a x86 MSR cmd id->str table generator Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 28/69] perf beauty: Hook up the x86 MSR " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 29/69] perf trace: Allow associating scnprintf routines with well known arg names Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 30/69] perf trace beauty: Add the glue for the autogenerated MSR arrays Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 31/69] perf trace: Associate the "msr" tracepoint arg name with x86_MSR__scnprintf() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 32/69] perf evlist: Factor out asprintf routine to build a tracepoint pid filter Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 33/69] perf evlist: Introduce append_tp_filter() method Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 34/69] perf evlist: Introduce append_tp_filter_pid() and append_tp_filter_pids() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 35/69] perf trace: Introduce --filter for tracepoint events Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 36/69] perf trace: Add a strtoul() method to 'struct syscall_arg_fmt' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 37/69] perf trace: Introduce a strtoul() method for 'struct strarrays' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 38/69] perf trace: Expand strings in filters to integers Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 39/69] perf beauty: Introduce strtoul() for x86 MSRs Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 40/69] perf tools: Avoid 'sample_reg_masks' being const + weak Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 41/69] MAINTAINERS: Add entry for perf tool arm64 pmu-events files Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 42/69] libperf: Add perf_mmap__init() function Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 43/69] libperf: Add 'struct perf_mmap_param' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 44/69] libperf: Adopt perf_mmap__mmap_len() function from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 45/69] libperf: Adopt perf_mmap__mmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 46/69] libperf: Adopt perf_mmap__get() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 47/69] libperf: Adopt perf_mmap__unmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 48/69] libperf: Adopt perf_mmap__put() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 49/69] perf tools: Use perf_mmap way to detect aux mmap Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 50/69] libperf: Adopt perf_mmap__consume() function from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 51/69] libperf: Adopt perf_mmap__read_init() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 52/69] libperf: Adopt perf_mmap__read_done() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 53/69] libperf: Adopt perf_mmap__read_event() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 54/69] libperf: Adopt perf_evlist__mmap()/munmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 55/69] libperf: Introduce perf_evlist__mmap_ops() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 56/69] libperf: Introduce perf_evlist_mmap_ops::idx callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 57/69] libperf: Add perf_evlist_mmap_ops::get callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 58/69] libperf: Introduce perf_evlist_mmap_ops::mmap callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 59/69] perf tools: Introduce perf_evlist__mmap_cb_idx() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 60/69] perf evlist: Introduce perf_evlist__mmap_cb_get() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 61/69] perf evlist: Introduce perf_evlist__mmap_cb_mmap() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 62/69] perf evlist: Switch to libperf's mmap interface Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 63/69] libperf: Centralize map refcnt setting Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 64/69] libperf: Move the pollfd allocation from tools/perf to libperf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 65/69] libperf: Introduce perf_evlist__exit() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 66/69] libperf: Introduce perf_evlist__purge() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 67/69] libperf: Adopt perf_evlist__filter_pollfd() from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 68/69] perf tools: Propagate CFLAGS to libperf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 69/69] perf diff: Report noisy for cycles diff Arnaldo Carvalho de Melo
2019-10-15  5:25 ` [GIT PULL] perf/core improvements and fixes Ingo Molnar

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=20191011200559.7156-25-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=lclaudio@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.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).