Skip to content

Commit

Permalink
tools: filter using PID intead of TID
Browse files Browse the repository at this point in the history
Signed-off-by: Hengqi Chen <[email protected]>
  • Loading branch information
chenhengqi authored and yonghong-song committed May 14, 2021
1 parent 0eef179 commit 89c96a8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 32 deletions.
30 changes: 20 additions & 10 deletions tools/btrfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@
// time operation
int trace_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
Expand All @@ -86,7 +89,10 @@
// I do by checking file->f_op.
int trace_read_entry(struct pt_regs *ctx, struct kiocb *iocb)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
Expand All @@ -96,7 +102,7 @@
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
Expand All @@ -105,8 +111,10 @@
int trace_open_entry(struct pt_regs *ctx, struct inode *inode,
struct file *file)
{
u32 pid;
pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
Expand All @@ -115,17 +123,19 @@
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
static int trace_return(struct pt_regs *ctx, const char *op)
{
u64 *tsp;
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
tsp = start.lookup(&tid);
if (tsp == 0) {
return 0; // missed start or filtered
}
Expand All @@ -136,7 +146,7 @@
__builtin_memcpy(&key.op, op, sizeof(key.op));
dist.increment(key);
start.delete(&pid);
start.delete(&tid);
return 0;
}
Expand Down
22 changes: 15 additions & 7 deletions tools/ext4dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@
// time operation
int trace_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
Expand All @@ -86,15 +89,17 @@
static int trace_return(struct pt_regs *ctx, const char *op)
{
u64 *tsp;
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
tsp = start.lookup(&tid);
if (tsp == 0) {
return 0; // missed start or filtered
}
u64 delta = bpf_ktime_get_ns() - *tsp;
start.delete(&pid);
start.delete(&tid);
// Skip entries with backwards time: temp workaround for #728
if ((s64) delta < 0)
Expand Down Expand Up @@ -164,7 +169,10 @@
ext4_trace_read_code = """
int trace_read_entry(struct pt_regs *ctx, struct kiocb *iocb)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
Expand All @@ -174,7 +182,7 @@
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}""" % ext4_file_ops_addr

Expand Down
15 changes: 10 additions & 5 deletions tools/nfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,26 @@
// time operation
int trace_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
static int trace_return(struct pt_regs *ctx, const char *op)
{
u64 *tsp;
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
tsp = start.lookup(&tid);
if (tsp == 0) {
return 0; // missed start or filtered
}
Expand All @@ -93,7 +98,7 @@
__builtin_memcpy(&key.op, op, sizeof(key.op));
dist.increment(key);
start.delete(&pid);
start.delete(&tid);
return 0;
}
Expand Down
15 changes: 10 additions & 5 deletions tools/xfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,26 @@
// time operation
int trace_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
static int trace_return(struct pt_regs *ctx, const char *op)
{
u64 *tsp;
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
tsp = start.lookup(&tid);
if (tsp == 0) {
return 0; // missed start or filtered
}
Expand All @@ -95,7 +100,7 @@
__builtin_memcpy(&key.op, op, sizeof(key.op));
dist.increment(key);
start.delete(&pid);
start.delete(&tid);
return 0;
}
Expand Down
15 changes: 10 additions & 5 deletions tools/zfsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,26 @@
// time operation
int trace_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
if (FILTER_PID)
return 0;
u64 ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
start.update(&tid, &ts);
return 0;
}
static int trace_return(struct pt_regs *ctx, const char *op)
{
u64 *tsp;
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = (u32)pid_tgid;
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
tsp = start.lookup(&tid);
if (tsp == 0) {
return 0; // missed start or filtered
}
Expand All @@ -95,7 +100,7 @@
__builtin_memcpy(&key.op, op, sizeof(key.op));
dist.increment(key);
start.delete(&pid);
start.delete(&tid);
return 0;
}
Expand Down

0 comments on commit 89c96a8

Please sign in to comment.