From: Tom Zanussi <tzanussi@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, fweisbec@gmail.com, rostedt@goodmis.org,
lizf@cn.fujitsu.com, hch@infradead.org
Subject: [RFC][PATCH 4/9] perf trace: Add trace scripting ops
Date: Tue, 6 Oct 2009 01:09:53 -0500 [thread overview]
Message-ID: <1254809398-8078-5-git-send-email-tzanussi@gmail.com> (raw)
In-Reply-To: <1254809398-8078-1-git-send-email-tzanussi@gmail.com>
Support any number of scripting languages for trace stream processing
by adding a set of functions, trace_scripting_operations, that can be
implemented to support a given language.
- start_script() - initialize e.g. create and initialize the interpreter
- stop_script() - clean up e.g. destroy the interpreter
- process_event() - send each event and its data to the interpreter
Support for a given language should also modify setup_scripting() to
replace the do-nothing default_scripting_ops with the
language-specific scripting ops for that language.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
---
tools/perf/builtin-trace.c | 53 +++++++++++++++++++++++++++++++++++++++-
tools/perf/util/trace-event.h | 7 +++++
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 5d4c84d..a654a5a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -27,6 +27,37 @@ static struct thread *last_match;
static struct perf_header *header;
static u64 sample_type;
+static char const *script_name;
+
+static int default_start_script(const char *script __attribute((unused)))
+{
+ return 0;
+}
+
+static int default_stop_script(void)
+{
+ return 0;
+}
+
+static struct trace_scripting_operations default_scripting_ops = {
+ .start_script = default_start_script,
+ .stop_script = default_stop_script,
+ .process_event = print_event,
+};
+
+static struct trace_scripting_operations *scripting_ops;
+
+static int setup_scripting(const char *script __attribute((unused)))
+{
+ scripting_ops = &default_scripting_ops;
+
+ return 0;
+}
+
+static int cleanup_scripting(void)
+{
+ return scripting_ops->stop_script();
+}
static int
process_comm_event(event_t *event, unsigned long offset, unsigned long head)
@@ -105,7 +136,8 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
* field, although it should be the same than this perf
* event pid
*/
- print_event(cpu, raw->data, raw->size, timestamp, thread->comm);
+ scripting_ops->process_event(cpu, raw->data, raw->size,
+ timestamp, thread->comm);
}
total += period;
@@ -239,11 +271,15 @@ static const struct option options[] = {
"dump raw trace in ASCII"),
OPT_BOOLEAN('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
+ OPT_STRING('s', "script", &script_name, "file",
+ "script file name"),
OPT_END()
};
int cmd_trace(int argc, const char **argv, const char *prefix __used)
{
+ int err;
+
symbol__init();
page_size = getpagesize();
@@ -259,5 +295,18 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
setup_pager();
- return __cmd_trace();
+ err = setup_scripting(script_name);
+ if (err)
+ goto out;
+
+ if (script_name) {
+ err = scripting_ops->start_script(script_name);
+ goto out;
+ }
+
+ err = __cmd_trace();
+
+ cleanup_scripting();
+out:
+ return err;
}
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 5f59a39..449c23d 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -246,4 +246,11 @@ void *raw_field_ptr(struct event *event, const char *name, void *data);
void read_tracing_data(struct perf_event_attr *pattrs, int nb_events);
+struct trace_scripting_operations {
+ int (*start_script) (const char *);
+ int (*stop_script) (void);
+ void (*process_event) (int cpu, void *data, int size,
+ unsigned long long nsecs, char *comm);
+};
+
#endif /* __PERF_TRACE_EVENTS_H */
--
1.6.4.GIT
next prev parent reply other threads:[~2009-10-06 6:10 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-06 6:09 [RFC][PATCH 0/9] perf trace: support for general-purpose scripting Tom Zanussi
2009-10-06 6:09 ` [RFC][PATCH 1/9] tracing/events: Add 'signed' field to format files Tom Zanussi
2009-10-06 13:06 ` [tip:perf/core] " tip-bot for Tom Zanussi
2009-10-06 15:05 ` Frederic Weisbecker
2009-10-07 4:30 ` Tom Zanussi
2009-10-07 1:06 ` [RFC][PATCH 1/9] " Steven Rostedt
2009-10-07 5:04 ` Tom Zanussi
2009-10-07 13:07 ` Steven Rostedt
2009-10-11 9:00 ` Ingo Molnar
2009-10-06 6:09 ` [RFC][PATCH 2/9] perf trace: Add subsystem string to struct event Tom Zanussi
2009-10-06 13:06 ` [tip:perf/core] " tip-bot for Tom Zanussi
2009-10-06 6:09 ` [RFC][PATCH 3/9] perf trace: Add string/dynamic cases to format_flags Tom Zanussi
2009-10-06 13:07 ` [tip:perf/core] " tip-bot for Tom Zanussi
2009-10-06 6:09 ` Tom Zanussi [this message]
2009-10-06 6:09 ` [RFC][PATCH 5/9] perf trace: Add Perl scripting support Tom Zanussi
2009-10-06 13:00 ` Ingo Molnar
2009-10-07 4:09 ` Tom Zanussi
2009-10-07 14:13 ` Christoph Hellwig
2009-10-08 4:01 ` Tom Zanussi
2009-10-11 8:58 ` Ingo Molnar
2009-10-11 12:16 ` Frederic Weisbecker
2009-10-12 6:03 ` Ingo Molnar
2009-10-06 6:09 ` [RFC][PATCH 6/9] perf trace: Add scripting op for generating empty event handling scripts Tom Zanussi
2009-10-06 6:09 ` [RFC][PATCH 7/9] perf trace: Add FIELD_IS_FLAG/SYMBOLIC cases to format_flags Tom Zanussi
2009-10-06 6:09 ` [RFC][PATCH 8/9] perf trace: Add perf trace scripting support modules for Perl Tom Zanussi
2009-10-06 12:39 ` Ingo Molnar
2009-10-07 4:02 ` Tom Zanussi
2009-10-06 12:45 ` Ingo Molnar
2009-10-07 4:05 ` Tom Zanussi
2009-10-06 6:09 ` [RFC][PATCH 9/9] perf trace: Add throwaway timestamp sorting Tom Zanussi
2009-10-06 9:09 ` [RFC][PATCH 0/9] perf trace: support for general-purpose scripting Ingo Molnar
2009-10-06 13:25 ` Peter Zijlstra
2009-10-06 13:53 ` Ingo Molnar
2009-10-07 4:01 ` Tom Zanussi
2009-10-06 9:40 ` Frédéric Weisbecker
2009-10-06 12:54 ` Ingo Molnar
2009-10-06 13:09 ` Ingo Molnar
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=1254809398-8078-5-git-send-email-tzanussi@gmail.com \
--to=tzanussi@gmail.com \
--cc=fweisbec@gmail.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=mingo@elte.hu \
--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
all inboxes | Powered by JetHome®