Brendan Gregg | e845c52 | 2015-09-07 14:51:53 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) PLUMgrid, Inc. |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License") |
| 4 | |
| 5 | # This is an example of tracing an event and printing custom fields. |
| 6 | # run in project examples directory with: |
| 7 | # sudo ./trace_fields.py" |
| 8 | |
| 9 | from bcc import BPF |
| 10 | |
| 11 | prog = """ |
| 12 | int hello(void *ctx) { |
| 13 | bpf_trace_printk("Hello, World!\\n"); |
| 14 | return 0; |
| 15 | } |
| 16 | """ |
| 17 | b = BPF(text=prog) |
| 18 | b.attach_kprobe(event="sys_clone", fn_name="hello") |
| 19 | print "PID MESSAGE" |
| 20 | b.trace_print(fmt="{1} {5}") |