* [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output
@ 2026-12-02 12:16 Marek Pazur
2026-12-02 12:16 ` [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing " Marek Pazur
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Marek Pazur @ 2026-12-02 12:16 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Jiri Olsa, Ian Rogers, Adrian Hunter, Howard Chu,
linux-perf-users, linux-kernel
Currently, perf trace prints augmented buf arguments without delimiters
or backslash escaping. When buffer payloads contain commas, quotes,
or escape-like sequences, the output becomes ambiguous to parse
reliably in automated tests. Additionally, the buffer augmentation
shell test passes captured perf trace output directly into printf's
format string, causing non-printable decimal escapes (such as "\10")
to be misinterpreted and corrupt failure logs.
This series addresses both issues:
- Patch 1 fixes printf format-string expansion in the buffer
augmentation shell test by passing trace output via "%s".
- Patch 2 encloses augmented buf output in double quotes and escapes
'"' and '\' and updates the buffer augmentation shell tests
accordingly.
Marek Pazur (2):
perf test trace_btf_general: Use %s format specifier when printing
test output
perf trace: Quote and escape augmented buffer contents
tools/perf/builtin-trace.c | 14 ++++++++++++--
tools/perf/tests/shell/trace_btf_general.sh | 8 ++++----
2 files changed, 16 insertions(+), 6 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing test output
2026-12-02 12:16 [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output Marek Pazur
@ 2026-12-02 12:16 ` Marek Pazur
2026-12-02 12:16 ` [PATCH 2/2] perf trace: Quote and escape augmented buffer contents Marek Pazur
2026-12-02 12:19 ` [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Marek Pazur @ 2026-12-02 12:16 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Jiri Olsa, Ian Rogers, Adrian Hunter, Howard Chu,
linux-perf-users, linux-kernel
The shell tests insert the captured perf trace output directly into
the printf format string as follows:
printf "Buffer augmentation test failed, output: \n$output\n"
As a result, printf interprets any possible escape sequences
and conversion specifications within the payload. Because perf trace
prints non-printable characters in decimal while printf parses
backslash escapes as octal, a newline character printed by perf
as "\10" (decimal 10) is interpreted by printf as a backspace
(octal 10), corrupting the failure message:
Buffer augmentation test failed, output:
buffer content
echo/129407 write(1, buffer conten, 15, 0) = 15
instead of:
echo/129407 write(1, buffer content\10, 15, 0) = 15
Pass the output as an argument to a "%s" conversion specifier instead
across all failure messages in the test.
Signed-off-by: Marek Pazur <mpazur@redhat.com>
---
tools/perf/tests/shell/trace_btf_general.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests/shell/trace_btf_general.sh
index d1fa7c846478..0941459a7137 100755
--- a/tools/perf/tests/shell/trace_btf_general.sh
+++ b/tools/perf/tests/shell/trace_btf_general.sh
@@ -22,42 +22,42 @@ check_vmlinux() {
return 2
fi
return 0
}
trace_test_string() {
echo "Testing perf trace's string augmentation"
output="$(perf trace --sort-events -e renameat* -- mv ${file1} ${file2} 2>&1)"
if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$"
then
- printf "String augmentation test failed, output:\n$output\n"
+ printf "String augmentation test failed, output:\n%s\n" "$output"
err=1
fi
}
trace_test_buffer() {
echo "Testing perf trace's buffer augmentation"
# echo will insert a newline (\10) at the end of the buffer
output="$(perf trace --sort-events -e write -- echo "${buffer}" 2>&1)"
if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$"
then
- printf "Buffer augmentation test failed, output:\n$output\n"
+ printf "Buffer augmentation test failed, output:\n%s\n" "$output"
err=1
fi
}
trace_test_struct_btf() {
echo "Testing perf trace's struct augmentation"
output="$(perf trace --sort-events -e clock_nanosleep --force-btf -- sleep 1 2>&1)"
if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,.*\}, 0x[0-9a-f]+\) += +[0-9]+$"
then
- printf "BTF struct augmentation test failed, output:\n$output\n"
+ printf "BTF struct augmentation test failed, output:\n%s\n" "$output"
err=1
fi
}
cleanup() {
rm -rf ${file1} ${file2} ${perf_config_tmp}
}
trap_cleanup() {
echo "Unexpected signal in ${FUNCNAME[1]}"
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] perf trace: Quote and escape augmented buffer contents
2026-12-02 12:16 [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output Marek Pazur
2026-12-02 12:16 ` [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing " Marek Pazur
@ 2026-12-02 12:16 ` Marek Pazur
2026-12-02 12:19 ` [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Marek Pazur @ 2026-12-02 12:16 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Jiri Olsa, Ian Rogers, Adrian Hunter, Howard Chu,
linux-perf-users, linux-kernel
When using perf trace, syscall_arg__scnprintf_buf() pretty-prints
augmented buf arguments without delimiters. Since the payload can
contain arbitrary characters (such as commas, quotes or brackets),
the resulting trace output is ambiguous to parse reliably in automated
tests. Additionally, literal backslashes and escape sequences are not
differentiated.
Before:
write(fd: 1, buf: 123, fake_argument: 456, count: 23)
write(fd: 1, buf: 98171 write(fd: 13, buf: write(f, count: 33)
write(fd: 1, buf: \0, count: 1) // buf = {0}
write(fd: 1, buf: \0, count: 2) // buf = {'\\', '0'}
write(fd: 1, buf: "Hello world!", count: 14)
The quotes were present in the original submission (v2 used "\"%s\""),
but got removed during the review process [1].
Enclose the buf contents in double quotes and backslash-escape '"'
and '\', matching strace's formatting style:
write(fd: 1, buf: "123, fake_argument: 456", count: 23)
write(fd: 1, buf: "98171 write(fd: 13, buf: write(f", count: 33)
write(fd: 1, buf: "\0", count: 1) // buf = {0}
write(fd: 1, buf: "\\0", count: 2) // buf = {'\\', '0'}
write(fd: 1, buf: "\"Hello world!\"", count: 14)
Update the buffer augmentation shell tests to account for the new format.
[1] https://lore.kernel.org/all/ZsiaBnd5KrkGbZ9w@x1/
Signed-off-by: Marek Pazur <mpazur@redhat.com>
---
tools/perf/builtin-trace.c | 14 ++++++++++++--
tools/perf/tests/shell/trace_btf_general.sh | 2 +-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c08f2c3a8128..3b61bc895aa3 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1964,26 +1964,36 @@ static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_a
struct augmented_arg *augmented_arg = arg->augmented.args;
size_t printed = 0;
unsigned char *orig;
int consumed;
if (!syscall_arg__augmented_args_valid(arg, 0))
return 0;
orig = (unsigned char *)augmented_arg->value;
+ printed += scnprintf(bf + printed, size - printed, "\"");
+
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]);
+ bool escaped = orig[j] == '"' || orig[j] == '\\';
+ /*
+ * Print control characters (0~31 and 127), and non-ascii
+ * characters in \(digits). Escape '"' and '\'.
+ */
+ printed += scnprintf(bf + printed, size - printed,
+ control_char ? "\\%d" : escaped ? "\\%c" : "%c",
+ (int)orig[j]);
}
+ printed += scnprintf(bf + printed, size - printed, "\"");
+
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);
diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests/shell/trace_btf_general.sh
index 0941459a7137..7784e93645d1 100755
--- a/tools/perf/tests/shell/trace_btf_general.sh
+++ b/tools/perf/tests/shell/trace_btf_general.sh
@@ -31,21 +31,21 @@ trace_test_string() {
then
printf "String augmentation test failed, output:\n%s\n" "$output"
err=1
fi
}
trace_test_buffer() {
echo "Testing perf trace's buffer augmentation"
# echo will insert a newline (\10) at the end of the buffer
output="$(perf trace --sort-events -e write -- echo "${buffer}" 2>&1)"
- if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$"
+ if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, \"${buffer}.*\", [0-9]+\) += +[0-9]+$"
then
printf "Buffer augmentation test failed, output:\n%s\n" "$output"
err=1
fi
}
trace_test_struct_btf() {
echo "Testing perf trace's struct augmentation"
output="$(perf trace --sort-events -e clock_nanosleep --force-btf -- sleep 1 2>&1)"
if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,.*\}, 0x[0-9a-f]+\) += +[0-9]+$"
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output
2026-12-02 12:16 [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output Marek Pazur
2026-12-02 12:16 ` [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing " Marek Pazur
2026-12-02 12:16 ` [PATCH 2/2] perf trace: Quote and escape augmented buffer contents Marek Pazur
@ 2026-12-02 12:19 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 12:19 UTC (permalink / raw)
To: Marek Pazur; +Cc: linux-perf-users
Sashiko has reviewed this 2-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202121622.30071-1-mpazur@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 12:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:16 [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output Marek Pazur
2026-12-02 12:16 ` [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing " Marek Pazur
2026-12-02 12:16 ` [PATCH 2/2] perf trace: Quote and escape augmented buffer contents Marek Pazur
2026-12-02 12:19 ` [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.