perf trace: Beautify mode_t arguments

When reading the syscall tracepoint /format file, look for arguments of type
"mode_t" and attach a beautifier:

  [root@jouet ~]# cat ~/bin/tp_with_fields_of_type
  #!/bin/bash
  grep -w $1 /sys/kernel/tracing/events/syscalls/*/format | sed -r 's%.*sys_enter_(.*)/format.*%\1%g' | paste -d, -s
  # tp_with_fields_of_type umode_t
  chmod,creat,fchmodat,fchmod,mkdirat,mkdir,mknodat,mknod,mq_open,openat,open
  #

Testing it:

  #define S_ISUID 0004000
  #define S_ISGID 0002000
  #define S_ISVTX 0001000
  #define S_IRWXU 0000700
  #define S_IRUSR 0000400
  #define S_IWUSR 0000200
  #define S_IXUSR 0000100

  #define S_IRWXG 0000070
  #define S_IRGRP 0000040
  #define S_IWGRP 0000020
  #define S_IXGRP 0000010

  #define S_IRWXO 0000007
  #define S_IROTH 0000004
  #define S_IWOTH 0000002
  #define S_IXOTH 0000001

  # for mode in 4000 2000 1000 700 400 200 100 70 40 20 10 7 4 2 1 ; do \
      echo -n $mode '->' ; trace --no-inherit -e chmod,fchmodat,fchmod chmod $mode x; \
    done
  4000 -> 0.338 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: ISUID) = 0
  2000 -> 0.438 ( 0.015 ms): fchmodat(dfd: CWD, filename: x, mode: ISGID) = 0
  1000 -> 0.677 ( 0.040 ms): fchmodat(dfd: CWD, filename: x, mode: ISVTX) = 0
   700 -> 0.394 ( 0.013 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXU) = 0
   400 -> 0.337 ( 0.010 ms): fchmodat(dfd: CWD, filename: x, mode: IRUSR) = 0
   200 -> 0.259 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IWUSR) = 0
   100 -> 0.249 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXUSR) = 0
    70 -> 0.266 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXG) = 0
    40 -> 0.329 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IRGRP) = 0
    20 -> 0.250 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IWGRP) = 0
    10 -> 0.259 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXGRP) = 0
     7 -> 0.249 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXO) = 0
     4 -> 0.278 ( 0.011 ms): fchmodat(dfd: CWD, filename: x, mode: IROTH) = 0
     2 -> 0.276 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IWOTH) = 0
     1 -> 0.250 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXOTH) = 0
  #
  # trace --no-inherit -e chmod,fchmodat,fchmod chmod 7777 x
     0.258 ( 0.011 ms): fchmodat(dfd: CWD, filename: x, mode: IALLUGO) = 0
  # trace --no-inherit -e chmod,fchmodat,fchmod chmod 7770 x
     0.258 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: ISUID|ISGID|ISVTX|IRWXU|IRWXG) = 0
  # trace --no-inherit -e chmod,fchmodat,fchmod chmod 777 x
     0.293 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXUGO
  #

Now lets see if check by using the tracepoint for that specific syscall,
instead of raw_syscalls:sys_enter as 'trace' does for its strace fu:

  # trace --no-inherit --ev syscalls:sys_enter_fchmodat -e fchmodat chmod 666 x
     0.255 (         ): syscalls:sys_enter_fchmodat:dfd: 0xffffffffffffff9c, filename: 0x55db32a3f0f0, mode: 0x000001b6)
     0.268 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: IRUGO|IWUGO                     ) = 0
  #

Perfect, 0x1bc == 0666.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-18e8zfgbkj83xo87yoom43kd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2 files changed