blob: 63a7b5310b485e85d01467bbfcd4d76854de500d [file] [log] [blame]
Brendan Gregge845c522015-09-07 14:51:53 -07001#!/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 Cotofe966bb2018-05-10 20:45:45 +02009from __future__ import print_function
Brendan Gregge845c522015-09-07 14:51:53 -070010from bcc import BPF
11
12prog = """
13int hello(void *ctx) {
14 bpf_trace_printk("Hello, World!\\n");
15 return 0;
16}
17"""
18b = BPF(text=prog)
Yonghong Song83b49ad2018-04-24 10:15:24 -070019b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
Javier Honduvilla Cotofe966bb2018-05-10 20:45:45 +020020print("PID MESSAGE")
Brendan Gregge845c522015-09-07 14:51:53 -070021b.trace_print(fmt="{1} {5}")