From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 1/3] trace-cmd: Move kernel_stack event handler to "function" plugin.
Date: Fri, 26 Jul 2019 15:43:06 +0300 [thread overview]
Message-ID: <20190726124308.18735-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20190726124308.18735-1-tz.stoyanov@gmail.com>
The "kernel_stack" event handler does not depend on any trace-cmd
context, it can be used aside from the application. The code is
moved to libtraceevent "function" plugin.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-ftrace.c | 52 ------------------------------------
plugins/plugin_function.c | 41 ++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 52 deletions(-)
diff --git a/lib/trace-cmd/trace-ftrace.c b/lib/trace-cmd/trace-ftrace.c
index ed68099..22e5213 100644
--- a/lib/trace-cmd/trace-ftrace.c
+++ b/lib/trace-cmd/trace-ftrace.c
@@ -31,17 +31,6 @@ struct tep_plugin_option trace_ftrace_options[] = {
static struct tep_plugin_option *fgraph_tail = &trace_ftrace_options[0];
static struct tep_plugin_option *fgraph_depth = &trace_ftrace_options[1];
-static void find_long_size(struct tracecmd_ftrace *finfo)
-{
- finfo->long_size = tracecmd_long_size(finfo->handle);
-}
-
-#define long_size_check(handle) \
- do { \
- if (!finfo->long_size) \
- find_long_size(finfo); \
- } while (0)
-
static int find_ret_event(struct tracecmd_ftrace *finfo, struct tep_handle *pevent)
{
struct tep_event *event;
@@ -361,44 +350,6 @@ fgraph_ret_handler(struct trace_seq *s, struct tep_record *record,
return 0;
}
-static int
-trace_stack_handler(struct trace_seq *s, struct tep_record *record,
- struct tep_event *event, void *context)
-{
- struct tracecmd_ftrace *finfo = context;
- struct tep_format_field *field;
- unsigned long long addr;
- const char *func;
- void *data = record->data;
-
- field = tep_find_any_field(event, "caller");
- if (!field) {
- trace_seq_printf(s, "<CANT FIND FIELD %s>", "caller");
- return 0;
- }
-
- trace_seq_puts(s, "<stack trace>\n");
-
- long_size_check(finfo);
-
- for (data += field->offset; data < record->data + record->size;
- data += finfo->long_size) {
- addr = tep_read_number(event->tep, data, finfo->long_size);
-
- if ((finfo->long_size == 8 && addr == (unsigned long long)-1) ||
- ((int)addr == -1))
- break;
-
- func = tep_find_function(event->tep, addr);
- if (func)
- trace_seq_printf(s, "=> %s (%llx)\n", func, addr);
- else
- trace_seq_printf(s, "=> %llx\n", addr);
- }
-
- return 0;
-}
-
/**
* tracecmd_ftrace_load_options - load the ftrace options
*
@@ -430,9 +381,6 @@ int tracecmd_ftrace_overrides(struct tracecmd_input *handle,
tep_register_event_handler(pevent, -1, "ftrace", "funcgraph_exit",
fgraph_ret_handler, finfo);
- tep_register_event_handler(pevent, -1, "ftrace", "kernel_stack",
- trace_stack_handler, finfo);
-
trace_util_add_options("ftrace", trace_ftrace_options);
/* Store the func ret id and event for later use */
diff --git a/plugins/plugin_function.c b/plugins/plugin_function.c
index 91beb74..21ee531 100644
--- a/plugins/plugin_function.c
+++ b/plugins/plugin_function.c
@@ -169,11 +169,52 @@ static int function_handler(struct trace_seq *s, struct tep_record *record,
return 0;
}
+static int
+trace_stack_handler(struct trace_seq *s, struct tep_record *record,
+ struct tep_event *event, void *context)
+{
+ struct tep_format_field *field;
+ unsigned long long addr;
+ const char *func;
+ int long_size;
+ void *data = record->data;
+
+ field = tep_find_any_field(event, "caller");
+ if (!field) {
+ trace_seq_printf(s, "<CANT FIND FIELD %s>", "caller");
+ return 0;
+ }
+
+ trace_seq_puts(s, "<stack trace >\n");
+
+ long_size = tep_get_long_size(event->tep);
+
+ for (data += field->offset; data < record->data + record->size;
+ data += long_size) {
+ addr = tep_read_number(event->tep, data, long_size);
+
+ if ((long_size == 8 && addr == (unsigned long long)-1) ||
+ ((int)addr == -1))
+ break;
+
+ func = tep_find_function(event->tep, addr);
+ if (func)
+ trace_seq_printf(s, "=> %s (%llx)\n", func, addr);
+ else
+ trace_seq_printf(s, "=> %llx\n", addr);
+ }
+
+ return 0;
+}
+
int TEP_PLUGIN_LOADER(struct tep_handle *tep)
{
tep_register_event_handler(tep, -1, "ftrace", "function",
function_handler, NULL);
+ tep_register_event_handler(tep, -1, "ftrace", "kernel_stack",
+ trace_stack_handler, NULL);
+
trace_util_add_options("ftrace", plugin_options);
return 0;
--
2.21.0
next prev parent reply other threads:[~2019-07-26 12:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-26 12:43 [PATCH 0/3] Remove redundant trace-cmd plugin handling logic Tzvetomir Stoyanov (VMware)
2019-07-26 12:43 ` Tzvetomir Stoyanov (VMware) [this message]
2019-07-26 12:43 ` [PATCH 2/3] trace-cmd: Move plugin options from trace-cmd to libtraceevent Tzvetomir Stoyanov (VMware)
2019-07-29 17:01 ` Steven Rostedt
2019-07-26 12:43 ` [PATCH 3/3] trace-cmd: Remove trace-cmd plugin handling routines Tzvetomir Stoyanov (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=20190726124308.18735-2-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).