Skip to contentSkip to conversation

perf trace beauty: A fix and some improvements for newfstatat,mprotect

PATCH In review Changbin Du 2 participants 9 messages Apr 18, 2024 – Apr 19, 2024 perf events

lore
Share & tools
lore
#0 lore raw

cover perf trace beauty: A fix and some improvements for newfstatat,mprotect

Changbin Du (4):
perf trace beauty: Fix statx flags printing
perf trace beauty: Beautify newfstatat flags
perf trace beauty: Always show param if show_zero is set perf trace beauty: Always show mprotect prot even though PROT_NONE

 tools/perf/builtin-trace.c      | 15 ++++++++-------
 tools/perf/trace/beauty/statx.c |  3 ++-
 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 perf trace beauty: Fix statx flags printing

Missed a string specifier '%s' in format string.

---
 tools/perf/trace/beauty/statx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/statx.c +1 -1
index dc5943a6352d..c61f2be53bda 100644
@@ -21,7 +21,7 @@ size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_
 		return scnprintf(bf, size, "%s%s", show_prefix ? "AT_STATX_" : "", "SYNC_AS_STAT");
 #define	P_FLAG(n) \
 	if (flags & AT_##n) { \
-		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
+		printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
 		flags &= ~AT_##n; \
 	}
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/4] perf trace beauty: Fix statx flags printing

Quoted 1 line · Changbin Du

Missed a string specifier '%s' in format string.

Humm, what branch should this be applied to? I ask because:

⬢[acme@toolbox perf-tools-next]$ git log --oneline tools/perf/trace/beauty/statx.c
f122b3d6d179455e perf beauty: Introduce scrape script for the 'statx' syscall 'mask' argument 3d6cfbaf279ddec9 perf beauty: Introduce scrape script for various fs syscalls 'flags' arguments a672af9139a843eb tools headers: Remove almost unused copy of uapi/stat.h, add few conditional defines 6652830c87be8446 perf beauty: Use the system linux/fcntl.h instead of a copy from the kernel 690811f0128eb603 tools headers uapi: Sync linux/stat.h with the kernel sources to pick STATX_MNT_ID_UNIQUE 49c75d30b0078d30 tools headers uapi: Sync linux/stat.h with the kernel sources
5d33cbfedb51f732 perf beauty: Add support to STATX_MNT_ID in the 'statx' syscall 'mask' argument c65c83ffe9045901 perf trace: Allow asking for not suppressing common string prefixes 794f594e0c3be619 perf beauty: Switch from GPL v2.0 to LGPL v2.1
fd5cead23f546973 (tag: perf-core-for-mingo-4.12-20170331) perf trace: Beautify statx syscall 'flag' and 'mask' arguments ⬢[acme@toolbox perf-tools-next]$

⬢[acme@toolbox perf-tools-next]$ tools/perf/trace/beauty/statx_mask.sh

static const char *statx_mask[] = {
	[ilog2(0x00000001) + 1] = "TYPE",
	[ilog2(0x00000002) + 1] = "MODE",
	[ilog2(0x00000004) + 1] = "NLINK",
	[ilog2(0x00000008) + 1] = "UID",
	[ilog2(0x00000010) + 1] = "GID",
	[ilog2(0x00000020) + 1] = "ATIME",
	[ilog2(0x00000040) + 1] = "MTIME",
	[ilog2(0x00000080) + 1] = "CTIME",
	[ilog2(0x00000100) + 1] = "INO",
	[ilog2(0x00000200) + 1] = "SIZE",
	[ilog2(0x00000400) + 1] = "BLOCKS",
	[ilog2(0x00000800) + 1] = "BTIME",
	[ilog2(0x00001000) + 1] = "MNT_ID",
	[ilog2(0x00002000) + 1] = "DIOALIGN",
	[ilog2(0x00004000) + 1] = "MNT_ID_UNIQUE",
};

⬢[acme@toolbox perf-tools-next]$

Can you please try with what is in
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git,
branch perf-tools-next?

- Arnaldo

Quoted 20 lines
---
 tools/perf/trace/beauty/statx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/statx.c +1 -1
index dc5943a6352d..c61f2be53bda 100644
@@ -21,7 +21,7 @@ size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_
 		return scnprintf(bf, size, "%s%s", show_prefix ? "AT_STATX_" : "", "SYNC_AS_STAT");
 #define	P_FLAG(n) \
 	if (flags & AT_##n) { \
-		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
+		printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
 		flags &= ~AT_##n; \
 	}
 
Signature · 1 line
2.34.1
author
#3 lore raw

Re: [PATCH 1/4] perf trace beauty: Fix statx flags printing

Quoted 36 lines · Arnaldo Carvalho de Melo
Quoted 1 line · Changbin Du

Missed a string specifier '%s' in format string.

Humm, what branch should this be applied to? I ask because:

⬢[acme@toolbox perf-tools-next]$ git log --oneline tools/perf/trace/beauty/statx.c
f122b3d6d179455e perf beauty: Introduce scrape script for the 'statx' syscall 'mask' argument 3d6cfbaf279ddec9 perf beauty: Introduce scrape script for various fs syscalls 'flags' arguments a672af9139a843eb tools headers: Remove almost unused copy of uapi/stat.h, add few conditional defines 6652830c87be8446 perf beauty: Use the system linux/fcntl.h instead of a copy from the kernel 690811f0128eb603 tools headers uapi: Sync linux/stat.h with the kernel sources to pick STATX_MNT_ID_UNIQUE 49c75d30b0078d30 tools headers uapi: Sync linux/stat.h with the kernel sources
5d33cbfedb51f732 perf beauty: Add support to STATX_MNT_ID in the 'statx' syscall 'mask' argument c65c83ffe9045901 perf trace: Allow asking for not suppressing common string prefixes 794f594e0c3be619 perf beauty: Switch from GPL v2.0 to LGPL v2.1
fd5cead23f546973 (tag: perf-core-for-mingo-4.12-20170331) perf trace: Beautify statx syscall 'flag' and 'mask' arguments ⬢[acme@toolbox perf-tools-next]$

⬢[acme@toolbox perf-tools-next]$ tools/perf/trace/beauty/statx_mask.sh

static const char *statx_mask[] = {
	[ilog2(0x00000001) + 1] = "TYPE",
	[ilog2(0x00000002) + 1] = "MODE",
	[ilog2(0x00000004) + 1] = "NLINK",
	[ilog2(0x00000008) + 1] = "UID",
	[ilog2(0x00000010) + 1] = "GID",
	[ilog2(0x00000020) + 1] = "ATIME",
	[ilog2(0x00000040) + 1] = "MTIME",
	[ilog2(0x00000080) + 1] = "CTIME",
	[ilog2(0x00000100) + 1] = "INO",
	[ilog2(0x00000200) + 1] = "SIZE",
	[ilog2(0x00000400) + 1] = "BLOCKS",
	[ilog2(0x00000800) + 1] = "BTIME",
	[ilog2(0x00001000) + 1] = "MNT_ID",
	[ilog2(0x00002000) + 1] = "DIOALIGN",
	[ilog2(0x00004000) + 1] = "MNT_ID_UNIQUE",
};
Quoted 6 lines

⬢[acme@toolbox perf-tools-next]$

Can you please try with what is in
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git,
branch perf-tools-next?

No problem, let me rebase on perf-tools-next. This patchset was created on mainline.

Quoted 23 lines

- Arnaldo

Quoted 20 lines
---
 tools/perf/trace/beauty/statx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/statx.c +1 -1
index dc5943a6352d..c61f2be53bda 100644
@@ -21,7 +21,7 @@ size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_
 		return scnprintf(bf, size, "%s%s", show_prefix ? "AT_STATX_" : "", "SYNC_AS_STAT");
 #define	P_FLAG(n) \
 	if (flags & AT_##n) { \
-		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
+		printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
 		flags &= ~AT_##n; \
 	}
 
Signature · 1 line
2.34.1
Signature · 2 lines
Cheers,
Changbin Du
author
#4 lore raw

Re: [PATCH 1/4] perf trace beauty: Fix statx flags printing

In reply to Arnaldo Carvalho de Melo

Hi, Arnaldo,

Quoted 36 lines · Arnaldo Carvalho de Melo
Quoted 1 line · Changbin Du

Missed a string specifier '%s' in format string.

Humm, what branch should this be applied to? I ask because:

⬢[acme@toolbox perf-tools-next]$ git log --oneline tools/perf/trace/beauty/statx.c
f122b3d6d179455e perf beauty: Introduce scrape script for the 'statx' syscall 'mask' argument 3d6cfbaf279ddec9 perf beauty: Introduce scrape script for various fs syscalls 'flags' arguments a672af9139a843eb tools headers: Remove almost unused copy of uapi/stat.h, add few conditional defines 6652830c87be8446 perf beauty: Use the system linux/fcntl.h instead of a copy from the kernel 690811f0128eb603 tools headers uapi: Sync linux/stat.h with the kernel sources to pick STATX_MNT_ID_UNIQUE 49c75d30b0078d30 tools headers uapi: Sync linux/stat.h with the kernel sources
5d33cbfedb51f732 perf beauty: Add support to STATX_MNT_ID in the 'statx' syscall 'mask' argument c65c83ffe9045901 perf trace: Allow asking for not suppressing common string prefixes 794f594e0c3be619 perf beauty: Switch from GPL v2.0 to LGPL v2.1
fd5cead23f546973 (tag: perf-core-for-mingo-4.12-20170331) perf trace: Beautify statx syscall 'flag' and 'mask' arguments ⬢[acme@toolbox perf-tools-next]$

⬢[acme@toolbox perf-tools-next]$ tools/perf/trace/beauty/statx_mask.sh

static const char *statx_mask[] = {
	[ilog2(0x00000001) + 1] = "TYPE",
	[ilog2(0x00000002) + 1] = "MODE",
	[ilog2(0x00000004) + 1] = "NLINK",
	[ilog2(0x00000008) + 1] = "UID",
	[ilog2(0x00000010) + 1] = "GID",
	[ilog2(0x00000020) + 1] = "ATIME",
	[ilog2(0x00000040) + 1] = "MTIME",
	[ilog2(0x00000080) + 1] = "CTIME",
	[ilog2(0x00000100) + 1] = "INO",
	[ilog2(0x00000200) + 1] = "SIZE",
	[ilog2(0x00000400) + 1] = "BLOCKS",
	[ilog2(0x00000800) + 1] = "BTIME",
	[ilog2(0x00001000) + 1] = "MNT_ID",
	[ilog2(0x00002000) + 1] = "DIOALIGN",
	[ilog2(0x00004000) + 1] = "MNT_ID_UNIQUE",
};
Quoted 8 lines

⬢[acme@toolbox perf-tools-next]$

Can you please try with what is in
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git,
branch perf-tools-next?

- Arnaldo

This code has been refactored and the old bug is gone. Could you just pick up the last two changes?

perf trace beauty: Always show param if show_zero is set perf trace beauty: Always show mprotect prot even though PROT_NONE

Signature · 2 lines
Cheers,
Changbin Du
#5 lore raw

PATCH 2/4 perf trace beauty: Beautify newfstatat flags

In reply to Changbin Du

Beautify the flags argument of newfstatat() using the same scnprintf of statx().

---
 tools/perf/builtin-trace.c      | 3 ++-
 tools/perf/trace/beauty/statx.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +2 -1
index 90eaff8c0f6e..19e81a467d6a 100644
@@ -1050,7 +1050,8 @@ static const struct syscall_fmt syscall_fmts[] = {
 	{ .name	    = "name_to_handle_at",
 	  .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, },
 	{ .name	    = "newfstatat",
-	  .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, },
+	  .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ },
+		   [3] = { .scnprintf = SCA_STATX_FLAGS, /* flags */ }, }, },
 	{ .name	    = "open",
 	  .arg = { [1] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, },
 	{ .name	    = "open_by_handle_at",
tools/perf/trace/beauty/statx.c +1 -0
index c61f2be53bda..dd83a2a95d89 100644
@@ -30,6 +30,7 @@ size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_
 	P_FLAG(SYMLINK_FOLLOW);
 	P_FLAG(NO_AUTOMOUNT);
 	P_FLAG(EMPTY_PATH);
+	P_FLAG(STATX_SYNC_AS_STAT);
 	P_FLAG(STATX_FORCE_SYNC);
 	P_FLAG(STATX_DONT_SYNC);
 
Signature · 1 line
2.34.1
#6 lore raw

PATCH 3/4 perf trace beauty: Always show param if show_zero is set

In reply to Changbin Du

For some parameters, it is best to also display them when they are 0, e.g. flags.

---
 tools/perf/builtin-trace.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-trace.c +5 -5
index 19e81a467d6a..349550b02f79 100644
@@ -2086,9 +2086,9 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
 			    !trace->show_zeros &&
 			    !(sc->arg_fmt &&
 			      (sc->arg_fmt[arg.idx].show_zero ||
-			       sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAY ||
-			       sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAYS) &&
-			      sc->arg_fmt[arg.idx].parm))
+			        ((sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAY ||
+			          sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAYS) &&
+			         sc->arg_fmt[arg.idx].parm))))
 				continue;
 
 			printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : "");
@@ -2790,8 +2790,8 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
 		 */
 		if (val == 0 &&
 		    !trace->show_zeros &&
-		    !((arg->show_zero ||
-		       arg->scnprintf == SCA_STRARRAY ||
+		    !arg->show_zero &&
+		    !((arg->scnprintf == SCA_STRARRAY ||
 		       arg->scnprintf == SCA_STRARRAYS) &&
 		      arg->parm))
 			continue;
Signature · 1 line
2.34.1
#7 lore raw

PATCH 4/4 perf trace beauty: Always show mprotect prot even though PROT_NONE

In reply to Changbin Du

Do not omit the flags even though it is PROT_NONE.

---
 tools/perf/builtin-trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-trace.c +1 -1
index 349550b02f79..7f936f1b5519 100644
@@ -1042,7 +1042,7 @@ static const struct syscall_fmt syscall_fmts[] = {
 		   [4] = { .scnprintf = SCA_MOVE_MOUNT_FLAGS, /* flags */ }, }, },
 	{ .name	    = "mprotect",
 	  .arg = { [0] = { .scnprintf = SCA_HEX,	/* start */ },
-		   [2] = { .scnprintf = SCA_MMAP_PROT,	/* prot */ }, }, },
+		   [2] = { .scnprintf = SCA_MMAP_PROT, .show_zero = true, /* prot */ }, }, },
 	{ .name	    = "mq_unlink",
 	  .arg = { [0] = { .scnprintf = SCA_FILENAME, /* u_name */ }, }, },
 	{ .name	    = "mremap",	    .hexret = true,
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH 4/4] perf trace beauty: Always show mprotect prot even though PROT_NONE

Quoted 12 lines · Changbin Du

Do not omit the flags even though it is PROT_NONE.

---
 tools/perf/builtin-trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-trace.c +0 -0
index 349550b02f79..7f936f1b5519 100644

tools/perf/builtin-trace.c static const struct syscall_fmt syscall_fmts[] = { · line 1045

Quoted 5 lines
tools/perf/builtin-trace.c +1 -1
@@ -1042,7 +1042,7 @@ static const struct syscall_fmt syscall_fmts[] = {
 		   [4] = { .scnprintf = SCA_MOVE_MOUNT_FLAGS, /* flags */ }, }, },
 	{ .name	    = "mprotect",
 	  .arg = { [0] = { .scnprintf = SCA_HEX,	/* start */ },
-		   [2] = { .scnprintf = SCA_MMAP_PROT,	/* prot */ }, }, },
+		   [2] = { .scnprintf = SCA_MMAP_PROT, .show_zero = true, /* prot */ }, }, },

So since syscall_arg__scnprintf_mmap_prot() special cases 0 to print NONE for prot... Ok, I'll expand a bit the commit log message _and_ the syscall_fmts entry for mprotect.

- Arnaldo

Quoted 5 lines
tools/perf/builtin-trace.c +0 -0
 	{ .name	    = "mq_unlink",
 	  .arg = { [0] = { .scnprintf = SCA_FILENAME, /* u_name */ }, }, },
 	{ .name	    = "mremap",	    .hexret = true,
Signature · 1 line
2.34.1