From: Howard Chu <howardchu95@gmail.com>
To: acme@kernel.org
Cc: adrian.hunter@intel.com, irogers@google.com, jolsa@kernel.org,
kan.liang@linux.intel.com, namhyung@kernel.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH v3 5/8] perf trace: Pretty print buffer data
Date: Sun, 25 Aug 2024 00:33:19 +0800 [thread overview]
Message-ID: <20240824163322.60796-6-howardchu95@gmail.com> (raw)
In-Reply-To: <20240824163322.60796-1-howardchu95@gmail.com>
Define TRACE_AUG_MAX_BUF in trace_augment.h data, which is the maximum
buffer size we can augment. BPF will include this header too.
Print buffer in a way that's different than just printing a string, we
print all the control characters in \digits (such as \0 for null, and
\10 for newline, LF).
For character that has a bigger value than 127, we print the digits
instead of the character itself as well.
Committer notes:
Simplified the buffer scnprintf to avoid using multiple buffers as
discussed in the patch review thread.
Signed-off-by: Howard Chu <howardchu95@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240815013626.935097-8-howardchu95@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 33 +++++++++++++++++++++++++++++++++
tools/perf/util/trace_augment.h | 6 ++++++
2 files changed, 39 insertions(+)
create mode 100644 tools/perf/util/trace_augment.h
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 048bcb92624c..470d74e3f875 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -65,6 +65,7 @@
#include "syscalltbl.h"
#include "rb_resort.h"
#include "../perf.h"
+#include "trace_augment.h"
#include <errno.h>
#include <inttypes.h>
@@ -852,6 +853,10 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
#define SCA_FILENAME syscall_arg__scnprintf_filename
+static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg);
+
+#define SCA_BUF syscall_arg__scnprintf_buf
+
static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size,
struct syscall_arg *arg)
{
@@ -1745,6 +1750,32 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
return 0;
}
+#define MAX_CONTROL_CHAR 31
+#define MAX_ASCII 127
+
+static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg)
+{
+ struct augmented_arg *augmented_arg = arg->augmented.args;
+ unsigned char *orig = (unsigned char *)augmented_arg->value;
+ size_t printed = 0;
+ int consumed;
+
+ if (augmented_arg == NULL)
+ return 0;
+
+ for (int j = 0; j < augmented_arg->size; ++j) {
+ bool control_char = orig[j] <= MAX_CONTROL_CHAR || orig[j] >= MAX_ASCII;
+ /* print control characters (0~31 and 127), and non-ascii characters in \(digits) */
+ printed += scnprintf(bf + printed, size - printed, control_char ? "\\%d" : "%c", (int)orig[j]);
+ }
+
+ consumed = sizeof(*augmented_arg) + augmented_arg->size;
+ arg->augmented.args = ((void *)arg->augmented.args) + consumed;
+ arg->augmented.size -= consumed;
+
+ return printed;
+}
+
static bool trace__filter_duration(struct trace *trace, double t)
{
return t < (trace->duration_filter * NSEC_PER_MSEC);
@@ -1956,6 +1987,8 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, struct tep_format_field
((len >= 4 && strcmp(field->name + len - 4, "name") == 0) ||
strstr(field->name, "path") != NULL))
arg->scnprintf = SCA_FILENAME;
+ else if (strstr(field->type, "char *") && strstr(field->name, "buf"))
+ arg->scnprintf = SCA_BUF;
else if ((field->flags & TEP_FIELD_IS_POINTER) || strstr(field->name, "addr"))
arg->scnprintf = SCA_PTR;
else if (strcmp(field->type, "pid_t") == 0)
diff --git a/tools/perf/util/trace_augment.h b/tools/perf/util/trace_augment.h
new file mode 100644
index 000000000000..57a3e5045937
--- /dev/null
+++ b/tools/perf/util/trace_augment.h
@@ -0,0 +1,6 @@
+#ifndef TRACE_AUGMENT_H
+#define TRACE_AUGMENT_H
+
+#define TRACE_AUG_MAX_BUF 32 /* for buffer augmentation in perf trace */
+
+#endif
--
2.45.2
next prev parent reply other threads:[~2024-08-24 16:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-24 16:33 [PATCH v3 0/8] perf trace: Enhanced augmentation for pointer arguments Howard Chu
2024-08-24 16:33 ` [PATCH v3 1/8] perf trace: Fix perf trace -p <PID> Howard Chu
2024-08-24 16:33 ` [PATCH v3 2/8] perf trace: Add trace__bpf_sys_enter_beauty_map() to prepare for fetching data in BPF Howard Chu
2024-09-09 19:45 ` Arnaldo Carvalho de Melo
2024-09-09 20:14 ` Arnaldo Carvalho de Melo
2024-09-10 4:59 ` Howard Chu
2024-08-24 16:33 ` [PATCH v3 3/8] perf trace: Pass the richer 'struct syscall_arg' pointer to trace__btf_scnprintf() Howard Chu
2024-08-24 16:33 ` [PATCH v3 4/8] perf trace: Pretty print struct data Howard Chu
2024-08-28 21:04 ` Arnaldo Carvalho de Melo
2024-08-30 0:16 ` Howard Chu
2024-09-09 14:40 ` Arnaldo Carvalho de Melo
2024-09-09 14:46 ` Arnaldo Carvalho de Melo
2024-08-24 16:33 ` Howard Chu [this message]
2024-09-09 16:33 ` [PATCH v3 5/8] perf trace: Pretty print buffer data Arnaldo Carvalho de Melo
2024-09-09 16:45 ` Arnaldo Carvalho de Melo
2024-09-09 16:50 ` Arnaldo Carvalho de Melo
2024-09-09 17:17 ` Howard Chu
2024-09-09 19:19 ` Arnaldo Carvalho de Melo
2024-09-09 17:14 ` Howard Chu
2024-08-24 16:33 ` [PATCH v3 6/8] perf trace: Collect augmented data using BPF Howard Chu
2024-09-04 19:52 ` Arnaldo Carvalho de Melo
2024-09-04 21:11 ` Howard Chu
2024-09-11 14:23 ` Arnaldo Carvalho de Melo
2024-08-24 16:33 ` [PATCH v3 7/8] perf trace: Add --force-btf for debugging Howard Chu
2024-08-24 16:33 ` [PATCH v3 8/8] perf trace: Add general tests for augmented syscalls Howard Chu
2024-09-09 22:11 ` Arnaldo Carvalho de Melo
2024-09-10 5:00 ` Howard Chu
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=20240824163322.60796-6-howardchu95@gmail.com \
--to=howardchu95@gmail.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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).