Commit 91734d35 authored by Brendan Gregg's avatar Brendan Gregg

some simplifications

parent 665c5b03
...@@ -17,7 +17,6 @@ from __future__ import print_function ...@@ -17,7 +17,6 @@ from __future__ import print_function
from bcc import BPF from bcc import BPF
from time import sleep, strftime from time import sleep, strftime
import argparse import argparse
import re
import signal import signal
# arguments # arguments
...@@ -63,24 +62,21 @@ struct key_t { ...@@ -63,24 +62,21 @@ struct key_t {
BPF_HASH(counts, struct key_t); BPF_HASH(counts, struct key_t);
int trace_count(struct pt_regs *ctx) { int trace_count(struct pt_regs *ctx) {
FILTER_START FILTER
struct key_t key = {}; struct key_t key = {};
u64 zero = 0, *val; u64 zero = 0, *val;
key.ip = ctx->ip; key.ip = ctx->ip;
val = counts.lookup_or_init(&key, &zero); val = counts.lookup_or_init(&key, &zero);
(*val)++; (*val)++;
FILTER_DONE
return 0; return 0;
} }
""" """
if args.pid: if args.pid:
bpf_text = bpf_text.replace('FILTER_START', bpf_text = bpf_text.replace('FILTER',
('u32 pid; pid = bpf_get_current_pid_tgid(); ' + ('u32 pid; pid = bpf_get_current_pid_tgid(); ' +
'if (pid == %s) {') % (args.pid)) 'if (pid != %s) { return 0; }') % (args.pid))
bpf_text = bpf_text.replace('FILTER_DONE', '}')
else: else:
bpf_text = bpf_text.replace('FILTER_START', '') bpf_text = bpf_text.replace('FILTER', '')
bpf_text = bpf_text.replace('FILTER_DONE', '')
if debug: if debug:
print(bpf_text) print(bpf_text)
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment