Skip to content

Commit b257fac

Browse files
Sbermacmel
authored andcommitted
perf trace: Pretty print buffer data
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. We can't really all 'buf' args to SCA_BUF as we're collecting so far just on the sys_enter path, so we would be printing the previous 'read' arg buffer contents, not what the kernel puts there. So instead of: static int syscall_fmt__cmp(const void *name, const void *fmtp) @@ -1987,8 +1989,6 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, struct tep_format_field - else if (strstr(field->type, "char *") && strstr(field->name, "buf")) - arg->scnprintf = SCA_BUF; Do: static const struct syscall_fmt syscall_fmts[] = { + { .name = "write", .errpid = true, + .arg = { [1] = { .scnprintf = SCA_BUF /* buf */, from_user = true, }, }, }, Signed-off-by: Howard Chu <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cb32035 commit b257fac

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tools/perf/builtin-trace.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "syscalltbl.h"
6666
#include "rb_resort.h"
6767
#include "../perf.h"
68+
#include "trace_augment.h"
6869

6970
#include <errno.h>
7071
#include <inttypes.h>
@@ -864,6 +865,10 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
864865
{ .scnprintf = SCA_FILENAME, \
865866
.from_user = true, }
866867

868+
static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg);
869+
870+
#define SCA_BUF syscall_arg__scnprintf_buf
871+
867872
static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size,
868873
struct syscall_arg *arg)
869874
{
@@ -1387,6 +1392,8 @@ static const struct syscall_fmt syscall_fmts[] = {
13871392
.arg = { [2] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, },
13881393
{ .name = "waitid", .errpid = true,
13891394
.arg = { [3] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, },
1395+
{ .name = "write", .errpid = true,
1396+
.arg = { [1] = { .scnprintf = SCA_BUF /* buf */, .from_user = true, }, }, },
13901397
};
13911398

13921399
static int syscall_fmt__cmp(const void *name, const void *fmtp)
@@ -1758,6 +1765,32 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
17581765
return 0;
17591766
}
17601767

1768+
#define MAX_CONTROL_CHAR 31
1769+
#define MAX_ASCII 127
1770+
1771+
static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg)
1772+
{
1773+
struct augmented_arg *augmented_arg = arg->augmented.args;
1774+
unsigned char *orig = (unsigned char *)augmented_arg->value;
1775+
size_t printed = 0;
1776+
int consumed;
1777+
1778+
if (augmented_arg == NULL)
1779+
return 0;
1780+
1781+
for (int j = 0; j < augmented_arg->size; ++j) {
1782+
bool control_char = orig[j] <= MAX_CONTROL_CHAR || orig[j] >= MAX_ASCII;
1783+
/* print control characters (0~31 and 127), and non-ascii characters in \(digits) */
1784+
printed += scnprintf(bf + printed, size - printed, control_char ? "\\%d" : "%c", (int)orig[j]);
1785+
}
1786+
1787+
consumed = sizeof(*augmented_arg) + augmented_arg->size;
1788+
arg->augmented.args = ((void *)arg->augmented.args) + consumed;
1789+
arg->augmented.size -= consumed;
1790+
1791+
return printed;
1792+
}
1793+
17611794
static bool trace__filter_duration(struct trace *trace, double t)
17621795
{
17631796
return t < (trace->duration_filter * NSEC_PER_MSEC);

tools/perf/util/trace_augment.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef TRACE_AUGMENT_H
2+
#define TRACE_AUGMENT_H
3+
4+
#define TRACE_AUG_MAX_BUF 32 /* for buffer augmentation in perf trace */
5+
6+
#endif

0 commit comments

Comments
 (0)