Commit ec615afd authored by Junli Ou's avatar Junli Ou Committed by 4ast

funccount: filter bcc function count (#645)

parent 23f6b958
...@@ -19,6 +19,7 @@ from bcc import BPF ...@@ -19,6 +19,7 @@ from bcc import BPF
from time import sleep, strftime from time import sleep, strftime
import argparse import argparse
import signal import signal
import os
# arguments # arguments
examples = """examples: examples = """examples:
...@@ -76,12 +77,12 @@ int trace_count(struct pt_regs *ctx) { ...@@ -76,12 +77,12 @@ int trace_count(struct pt_regs *ctx) {
return 0; return 0;
} }
""" """
filter_text = "u32 pid; pid = bpf_get_current_pid_tgid(); "
if args.pid: if args.pid:
bpf_text = bpf_text.replace('FILTER', filter_text += "if (pid != %s) { return 0; }" % args.pid
('u32 pid; pid = bpf_get_current_pid_tgid(); ' +
'if (pid != %s) { return 0; }') % (args.pid))
else: else:
bpf_text = bpf_text.replace('FILTER', '') filter_text += "if (pid == %s) { return 0; }" % os.getpid()
bpf_text = bpf_text.replace('FILTER', filter_text)
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