From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 09/10] trace-cruncher: Add synthetic event example
Date: Mon, 24 Jan 2022 10:56:24 +0200 [thread overview]
Message-ID: <20220124085625.92297-10-y.karadz@gmail.com> (raw)
In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com>
This is a very basic example, demonsting the usage of the new APIs
for kernel synth. events.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
examples/synth.py | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100755 examples/synth.py
diff --git a/examples/synth.py b/examples/synth.py
new file mode 100755
index 0000000..ec9427b
--- /dev/null
+++ b/examples/synth.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: CC-BY-4.0
+
+Copyright 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import tracecruncher.ftracepy as ft
+
+# Define a synthetic event that combines 'sched_waking' and 'sched_switch'.
+# A synth. event will be recorded every time a 'start' event (sched_waking)
+# is followed by an 'end' event (sched_switch) and both events have the same
+# value of the fields 'pid' and 'next_pid' (belong to the same process).
+synth = ft.synth(name='synth_wakeup',
+ start_sys='sched', start_evt='sched_waking',
+ end_sys='sched', end_evt='sched_switch',
+ start_match='pid', end_match='next_pid',
+ match_name='pid')
+
+# Add to the synth. event two fields from the 'start' event. In the synth. event,
+# the field 'target_cpu' will be renamed to 'cpu'.
+synth.add_start_fields(fields=['target_cpu', 'prio'],
+ names=['cpu', None])
+
+# Add to the synth. event one field from the 'end' event.
+synth.add_end_fields(fields=['next_prio'])
+
+# Add to the synth. event a field that measures the time-difference between
+# the 'start' and 'end' events. Use 'hd' time resolution (nanoseconds).
+synth.add_delta_T(hd=True)
+
+# Register the synth. event on the system.
+synth.register()
+
+inst = ft.create_instance()
+
+# Apply a filter and enable the synth. event.
+synth.set_filter(instance=inst, filter='prio<100')
+synth.enable(instance=inst)
+
+# Print the stream of trace events. "Ctrl+c" to stop tracing.
+ft.read_trace(instance=inst)
--
2.32.0
next prev parent reply other threads:[~2022-01-24 8:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 8:56 [PATCH 00/10] trace-cruncher: Synthetic events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 01/10] trace-cruncher: Define Python type for synthetic events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 02/10] trace-cruncher: APIs for adding start/end fields to synth. event Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 03/10] trace-cruncher: APIs for adding arithmetic fields to synth. events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 04/10] trace-cruncher: APIs for registering/unregistering " Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 05/10] trace-cruncher: APIs for enabling " Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 06/10] trace-cryncher: Add static methods for manipulating filters Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 07/10] trace-cruncher: APIs for filtering synth. events Yordan Karadzhov (VMware)
2022-01-24 8:56 ` [PATCH 08/10] trace-cruncher: API to show descriptor of the synth. event Yordan Karadzhov (VMware)
2022-01-24 8:56 ` Yordan Karadzhov (VMware) [this message]
2022-01-24 8:56 ` [PATCH 10/10] trace-cruncher: Add synth. events tests Yordan Karadzhov (VMware)
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=20220124085625.92297-10-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.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).