[PATCH] perf trace beautify: Beautify flags of mount(2) and umount(2).

From: Benjamin Peterson
Date: Tue Aug 28 2018 - 00:01:29 EST


Example output of perf trace -e mount,umount2:

6243.930 ( 0.052 ms): mount/30976 mount(dev_name: 0x55dc541bb920, dir_name: 0x55dc541bc960, type: 0x55dc541b9c40, flags: BIND) = 0
7851.821 (26.015 ms): umount/30983 umount2(name: 0x558daa82cf50, flags: MNT_FORCE ) = 0

Signed-off-by: Benjamin Peterson <benjamin@xxxxxxxxxx>
---
tools/perf/builtin-trace.c | 5 ++
tools/perf/trace/beauty/mount_flags.c | 79 +++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 tools/perf/trace/beauty/mount_flags.c

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 22ab8e67c760..3cffb25d1928 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -603,6 +603,7 @@ static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size,
#include "trace/beauty/futex_val3.c"
#include "trace/beauty/mmap.c"
#include "trace/beauty/mode_t.c"
+#include "trace/beauty/mount_flags.c"
#include "trace/beauty/msg_flags.c"
#include "trace/beauty/open_flags.c"
#include "trace/beauty/perf_event_open.c"
@@ -722,6 +723,8 @@ static struct syscall_fmt {
.arg = { [0] = { .scnprintf = SCA_HEX, /* addr */ },
[2] = { .scnprintf = SCA_MMAP_PROT, /* prot */ },
[3] = { .scnprintf = SCA_MMAP_FLAGS, /* flags */ }, }, },
+ { .name = "mount",
+ .arg = { [3] = { .scnprintf = SCA_MOUNT_FLAGS, /* flags */ }, }, },
{ .name = "mprotect",
.arg = { [0] = { .scnprintf = SCA_HEX, /* start */ },
[2] = { .scnprintf = SCA_MMAP_PROT, /* prot */ }, }, },
@@ -830,6 +833,8 @@ static struct syscall_fmt {
.arg = { [2] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, },
{ .name = "tkill",
.arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, },
+ { .name = "umount2", .alias = "umount",
+ .arg = { [1] = { .scnprintf = SCA_UMOUNT_FLAGS, /* flags */ }, }, },
{ .name = "uname", .alias = "newuname", },
{ .name = "unlinkat",
.arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, },
diff --git a/tools/perf/trace/beauty/mount_flags.c b/tools/perf/trace/beauty/mount_flags.c
new file mode 100644
index 000000000000..86790b82c869
--- /dev/null
+++ b/tools/perf/trace/beauty/mount_flags.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <sys/mount.h>
+
+static size_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg)
+{
+ size_t printed = 0;
+ int flags = arg->val;
+
+ if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
+ flags &= ~MS_MGC_MSK;
+
+#define P_FLAG(n) \
+ if (flags & MS_##n) { \
+ printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
+ flags &= ~MS_##n; \
+ }
+
+ P_FLAG(RDONLY);
+ P_FLAG(NOSUID);
+ P_FLAG(NODEV);
+ P_FLAG(NOEXEC);
+ P_FLAG(SYNCHRONOUS);
+ P_FLAG(REMOUNT);
+ P_FLAG(MANDLOCK);
+ P_FLAG(DIRSYNC);
+ P_FLAG(NOATIME);
+ P_FLAG(NODIRATIME);
+ P_FLAG(BIND);
+ P_FLAG(MOVE);
+ P_FLAG(REC);
+ P_FLAG(SILENT);
+ P_FLAG(POSIXACL);
+ P_FLAG(UNBINDABLE);
+ P_FLAG(PRIVATE);
+ P_FLAG(SLAVE);
+ P_FLAG(SHARED);
+ P_FLAG(RELATIME);
+ P_FLAG(KERNMOUNT);
+ P_FLAG(I_VERSION);
+ P_FLAG(STRICTATIME);
+ P_FLAG(LAZYTIME);
+ P_FLAG(ACTIVE);
+ P_FLAG(NOUSER);
+
+#undef P_FLAG
+
+ if (flags)
+ printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
+
+ return printed;
+}
+
+#define SCA_MOUNT_FLAGS syscall_arg__scnprintf_mount_flags
+
+static size_t syscall_arg__scnprintf_umount_flags(char *bf, size_t size, struct syscall_arg *arg)
+{
+ size_t printed = 0;
+ int flags = arg->val;
+
+#define P_FLAG(n) \
+ if (flags & n) { \
+ printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
+ flags &= ~n; \
+ }
+
+ P_FLAG(MNT_FORCE);
+ P_FLAG(MNT_DETACH);
+ P_FLAG(MNT_EXPIRE);
+ P_FLAG(UMOUNT_NOFOLLOW);
+
+#undef P_FLAG
+
+ if (flags)
+ printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
+
+ return printed;
+}
+
+#define SCA_UMOUNT_FLAGS syscall_arg__scnprintf_umount_flags
--
2.17.1