From f92fef2647bfcf08442a0f8a3fa552eed0960da6 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Wed, 24 Jan 2018 20:51:46 -0800 Subject: [PATCH] add a probe alias $task in trace.py The $task refers to the current task. In my particular case, I need to trace the number of users for file system associated with the current task. With the probe alias $task, trace.py can easily trace this event ...... trace.py -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users' PID TID COMM FUNC - 176566 176566 python2.7 mntns_install users = 2 176566 176566 python2.7 mntns_install users = 2 ...... With $task probe alias, kernel tast_struct fields can be used in trace.py filter or output easily even if they cannot be accessed through input parameters. Signed-off-by: Yonghong Song --- tools/trace.py | 5 ++++- tools/trace_example.txt | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/trace.py b/tools/trace.py index 71688fb0d722..d22b5c4b5b3a 100755 --- a/tools/trace.py +++ b/tools/trace.py @@ -204,7 +204,8 @@ def _parse_action(self, action): "$gid": "(unsigned)(bpf_get_current_uid_gid() >> 32)", "$pid": "(unsigned)(bpf_get_current_pid_tgid() & 0xffffffff)", "$tgid": "(unsigned)(bpf_get_current_pid_tgid() >> 32)", - "$cpu": "bpf_get_smp_processor_id()" + "$cpu": "bpf_get_smp_processor_id()", + "$task" : "((struct task_struct *)bpf_get_current_task())" } def _generate_streq_function(self, string): @@ -606,6 +607,8 @@ class Tool(object): 'udpv6_sendmsg(struct sock *sk) (sk->sk_dport == 13568)' Trace udpv6 sendmsg calls only if socket's destination port is equal to 53 (DNS; 13568 in big endian order) +trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users' + Trace the number of users accessing the file system of the current task """ def __init__(self): diff --git a/tools/trace_example.txt b/tools/trace_example.txt index 10f9d9b83b1d..fd0a7bb887e3 100644 --- a/tools/trace_example.txt +++ b/tools/trace_example.txt @@ -296,4 +296,6 @@ trace -I 'net/sock.h' \\ 'udpv6_sendmsg(struct sock *sk) (sk->sk_dport == 13568)' Trace udpv6 sendmsg calls only if socket's destination port is equal to 53 (DNS; 13568 in big endian order) +trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users' + Trace the number of users accessing the file system of the current task "