shorten hello world example
authorBrendan Gregg <brendan.d.gregg@gmail.com>
Mon, 7 Sep 2015 21:51:53 +0000 (14:51 -0700)
committerBrendan Gregg <brendan.d.gregg@gmail.com>
Mon, 7 Sep 2015 21:51:53 +0000 (14:51 -0700)
examples/hello_world.py
examples/trace_fields.py [new file with mode: 0755]

index 77b2c2b..3f21be4 100755 (executable)
@@ -4,15 +4,10 @@
 
 # run in project examples directory with:
 # sudo ./hello_world.py"
+# see trace_fields.py for a longer example
 
 from bcc import BPF
 
-prog = """
-int hello(void *ctx) {
-  bpf_trace_printk("Hello, World!\\n");
-  return 0;
-}
-"""
-b = BPF(text=prog)
+b = BPF(text='void hello(void *ctx) { bpf_trace_printk("Hello, World!\\n"); }')
 b.attach_kprobe(event="sys_clone", fn_name="hello")
-b.trace_print(fmt="{1} {5}")
+b.trace_print()
diff --git a/examples/trace_fields.py b/examples/trace_fields.py
new file mode 100755 (executable)
index 0000000..173f21f
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# Copyright (c) PLUMgrid, Inc.
+# Licensed under the Apache License, Version 2.0 (the "License")
+
+# This is an example of tracing an event and printing custom fields.
+# run in project examples directory with:
+# sudo ./trace_fields.py"
+
+from bcc import BPF
+
+prog = """
+int hello(void *ctx) {
+  bpf_trace_printk("Hello, World!\\n");
+  return 0;
+}
+"""
+b = BPF(text=prog)
+b.attach_kprobe(event="sys_clone", fn_name="hello")
+print "PID MESSAGE"
+b.trace_print(fmt="{1} {5}")