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 | |
Javier Honduvilla Coto | fe966bb | 2018-05-10 20:45:45 +0200 | [diff] [blame] | 9 | from __future__ import print_function |
Brendan Gregg | e845c52 | 2015-09-07 14:51:53 -0700 | [diff] [blame] | 10 | from bcc import BPF |
| 11 | |
| 12 | prog = """ |
| 13 | int hello(void *ctx) { |
| 14 | bpf_trace_printk("Hello, World!\\n"); |
| 15 | return 0; |
| 16 | } |
| 17 | """ |
| 18 | b = BPF(text=prog) |
Yonghong Song | 83b49ad | 2018-04-24 10:15:24 -0700 | [diff] [blame] | 19 | b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello") |
Javier Honduvilla Coto | fe966bb | 2018-05-10 20:45:45 +0200 | [diff] [blame] | 20 | print("PID MESSAGE") |
Brendan Gregg | e845c52 | 2015-09-07 14:51:53 -0700 | [diff] [blame] | 21 | b.trace_print(fmt="{1} {5}") |