linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] New example for syscalls tracing
Date: Mon, 11 Oct 2021 15:08:43 +0300	[thread overview]
Message-ID: <20211011120843.1704006-1-tz.stoyanov@gmail.com> (raw)

New trace-cruncher example script dumps all system calls of given
process and its children.

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

diff --git a/examples/trace_syscalls.py b/examples/trace_syscalls.py
new file mode 100755
index 0000000..4cec54f
--- /dev/null
+++ b/examples/trace_syscalls.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: CC-BY-4.0
+
+Copyright (C) 2021, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
+"""
+
+import sys
+import tracecruncher.ftracepy as ft
+
+args = len(sys.argv)
+if args < 2:
+    print('Usage: ', sys.argv[0],
+          ' [PROCESS ID 1] ... [PROCESS ID n]; print all system calls of given processes')
+    sys.exit(1)
+
+# Create new Ftrace instance to work in.
+inst = ft.create_instance(tracing_on=False)
+
+# Enable all static events from system calls.
+ft.enable_events(instance=inst, systems=['syscalls'], events=[['all']])
+
+# Filter system calls only for the desired PIDs
+for i in range(1, args):
+   ft.set_event_pid(instance=inst, pid=int(sys.argv[i]))
+# Also, track system calls for the children
+ft.enable_option(instance=inst, option="event-fork")
+
+# Enable tracing
+ft.tracing_ON(instance=inst)
+
+# Read and print traced events, until <ctrl-c> is pressed.
+ft.read_trace(instance=inst)
-- 
2.31.1


                 reply	other threads:[~2021-10-11 12:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011120843.1704006-1-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).