From: Yordan Karadzhov <y.karadz@gmail.com>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: rostedt@goodmis.org, linux-trace-devel@vger.kernel.org
Subject: Re: [RFC PATCH 4/4] trace-cruncher: Example script for uprobes high level API
Date: Fri, 1 Apr 2022 12:41:36 +0300 [thread overview]
Message-ID: <779a7856-5271-5ad5-4341-9ac374bd827a@gmail.com> (raw)
In-Reply-To: <20220331095533.75289-5-tz.stoyanov@gmail.com>
On 31.03.22 г. 12:55 ч., Tzvetomir Stoyanov (VMware) wrote:
> Proposed example illustrates how to use uprobes high level API to trace
> all functions for user program. It can be attached to already running
> program, or run the program and trace its execution.
>
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
> examples/user_trace.py | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
> create mode 100755 examples/user_trace.py
>
> diff --git a/examples/user_trace.py b/examples/user_trace.py
> new file mode 100755
> index 0000000..0d3adcd
> --- /dev/null
> +++ b/examples/user_trace.py
> @@ -0,0 +1,41 @@
> +#!/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
> +
> +if __name__ == "__main__":
> + if len(sys.argv) < 2:
> + print('Usage: ', sys.argv[0], ' [PROCESS]')
> + sys.exit(1)
> +
> + # Create new Ftrace instance to work in. The tracing in this new instance
> + # is not going to be enabled yet.
> + inst = ft.create_instance(tracing_on=False)
> +
> + # Create a user tracing context for given process, exclude the libraries
> + if sys.argv[1].isdigit():
> + utrace = ft.user_trace(pid=int(sys.argv[1]), follow_libs=False)
> + else:
> + utrace = ft.user_trace(name=sys.argv[1], follow_libs=False)
> +
> + # Trace execution of all available functions in the given process
> + utrace.add_function(fname = "*")
> +
> + # Add trace points on functions return as well
> + utrace.add_ret_function(fname = "*")
> +
> + # Start tracing in an instance
> + utrace.start(instance = inst)
> +
> + # Read the trace buffer during the trace until ctrl-c is pressed
> + ft.read_trace(instance=inst)
> +
> + # Disable the tracing
> + utrace.stop(instance = inst)
The "stop" must be performed by the 'destroy' method of utrace object.
And 'destroy' must be called automatically at exit.
Thanks!
Yordan
next prev parent reply other threads:[~2022-04-01 9:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 9:55 [RFC PATCH 0/4] trace-cruncher: ftrace uprobes support Tzvetomir Stoyanov (VMware)
2022-03-31 9:55 ` [RFC PATCH 1/4] trace-cruncher: Logic for resolving address to function name Tzvetomir Stoyanov (VMware)
2022-04-05 12:28 ` Yordan Karadzhov
2022-03-31 9:55 ` [RFC PATCH 2/4] trace-cruncher: ftrace uprobe raw API Tzvetomir Stoyanov (VMware)
2022-03-31 9:55 ` [RFC PATCH 3/4] trace-cruncher: High level wrappers for ftrace uprobes Tzvetomir Stoyanov (VMware)
2022-04-01 9:41 ` Yordan Karadzhov
2022-03-31 9:55 ` [RFC PATCH 4/4] trace-cruncher: Example script for uprobes high level API Tzvetomir Stoyanov (VMware)
2022-04-01 9:41 ` Yordan Karadzhov [this message]
2022-04-01 9:43 ` Yordan Karadzhov
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=779a7856-5271-5ad5-4341-9ac374bd827a@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tz.stoyanov@gmail.com \
/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).