You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
607 B
29 lines
607 B
#!/usr/bin/env python
|
|
#
|
|
# This is a Hello World example that formats output as fields.
|
|
|
|
from bcc import BPF
|
|
|
|
# define BPF program
|
|
prog = """
|
|
int hello(void *ctx) {
|
|
bpf_trace_printk("Hello, World!\\n");
|
|
return 0;
|
|
}
|
|
"""
|
|
|
|
# load BPF program
|
|
b = BPF(text=prog)
|
|
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
|
|
|
|
# header
|
|
print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "MESSAGE"))
|
|
|
|
# format output
|
|
while 1:
|
|
try:
|
|
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
|
|
except ValueError:
|
|
continue
|
|
print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
|