1#!/usr/bin/env python 2# 3# This is a Hello World example that formats output as fields. 4 5from bcc import BPF 6 7# define BPF program 8prog = """ 9int hello(void *ctx) { 10 bpf_trace_printk("Hello, World!\\n"); 11 return 0; 12} 13""" 14 15# load BPF program 16b = BPF(text=prog) 17b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello") 18 19# header 20print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "MESSAGE")) 21 22# format output 23while 1: 24 try: 25 (task, pid, cpu, flags, ts, msg) = b.trace_fields() 26 except ValueError: 27 continue 28 print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg)) 29