blob: bad1a22982ba7a55ade6e48e44d80f54b4b2beb2 [file] [log] [blame]
Brendan Gregg239e8632016-07-25 15:02:32 -07001#!/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)
Yonghong Song83b49ad2018-04-24 10:15:24 -070017b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
Brendan Gregg239e8632016-07-25 15:02:32 -070018
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))