Skip to content

Commit

Permalink
refactor a little, remove extra bpf_get_current_pid_tgid()
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Sep 14, 2016
1 parent 9a3a0f0 commit 0f00a2f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/killsnoop.py
Expand Up @@ -49,7 +49,7 @@
struct data_t {
u64 pid;
u64 tpid;
int tpid;
int sig;
int ret;
char comm[TASK_COMM_LEN];
Expand All @@ -60,12 +60,11 @@
int kprobe__sys_kill(struct pt_regs *ctx, int tpid, int sig)
{
struct val_t val = {};
u32 pid = bpf_get_current_pid_tgid();
FILTER
struct val_t val = {.pid = pid};
if (bpf_get_current_comm(&val.comm, sizeof(val.comm)) == 0) {
val.pid = bpf_get_current_pid_tgid();
val.tpid = tpid;
val.sig = sig;
infotmp.update(&pid, &val);
Expand Down Expand Up @@ -114,7 +113,7 @@
class Data(ct.Structure):
_fields_ = [
("pid", ct.c_ulonglong),
("tpid", ct.c_ulonglong),
("tpid", ct.c_int),
("sig", ct.c_int),
("ret", ct.c_int),
("comm", ct.c_char * TASK_COMM_LEN)
Expand All @@ -128,7 +127,8 @@ class Data(ct.Structure):
def print_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(Data)).contents

if (args.failed and (event.ret >= 0)): return
if (args.failed and (event.ret >= 0)):
return

print("%-9s %-6d %-16s %-4d %-6d %d" % (strftime("%H:%M:%S"),
event.pid, event.comm, event.sig, event.tpid, event.ret))
Expand Down

0 comments on commit 0f00a2f

Please sign in to comment.