diff mbox series

[v3,3/3] trace-cruncher: Example for event probes API

Message ID 20220127070111.27529-4-tz.stoyanov@gmail.com (mailing list archive)
State New, archived
Headers show
Series trace-cruncher: Add support for event probes | expand

Commit Message

Tzvetomir Stoyanov (VMware) Jan. 27, 2022, 7:01 a.m. UTC
trace-cruncher APIs should have examples, to demonstrate their usage
in a real use case. Added an example for newly introduced event
probes API.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 examples/eprobe.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 examples/eprobe.py
diff mbox series

Patch

diff --git a/examples/eprobe.py b/examples/eprobe.py
new file mode 100755
index 0000000..85b0685
--- /dev/null
+++ b/examples/eprobe.py
@@ -0,0 +1,29 @@ 
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: CC-BY-4.0
+
+Copyright 2022 VMware Inc, Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
+"""
+
+import sys
+
+import tracecruncher.ftracepy as ft
+import tracecruncher.ft_utils as tc
+
+open_probe = ft.eprobe(event='sopen_in', target_system='syscalls',
+                       target_event='sys_enter_openat', fetchargs='file=+0($filename):ustring')
+
+tep = tc.local_tep()
+
+def callback(event, record):
+    print(tep.info(event, record))
+
+if __name__ == "__main__":
+    if len(sys.argv) < 2:
+        print('Usage: ', sys.argv[0], ' [PROCESS]')
+        sys.exit(1)
+
+    inst = ft.create_instance(tracing_on=False)
+    open_probe.enable(instance=inst)
+    ft.trace_process(instance=inst, argv=sys.argv[1:])