aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/trace-event-perl.c
diff options
context:
space:
mode:
authorTom Zanussi <tzanussi@gmail.com>2009-11-25 02:15:50 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-28 04:04:27 -0500
commitd1b93772be78486397693fc39d3ddea3fda90105 (patch)
treefc4387cf44de336e655d03ee488a83cadde22e04 /tools/perf/util/trace-event-perl.c
parentbcefe12eff5dca6fdfa94ed85e5bee66380d5cd9 (diff)
perf trace: Add interface to access perf data from Perl handlers
The Perl scripting support for perf trace allows most of a trace event's data to be accessed directly as handler arguments, but not all of it e.g. the less common fields aren't passed in. To give scripts access to the other fields and/or any other data or metadata in the main perf executable that might be useful, a way to access the C data in perf from Perl is needed; this patch uses the Perl XS facility to do it for the common_xxx event fields not passed to handler functions. Context.pm exports three functions to Perl scripts that access fields for the current event by calling back into perf: common_pc(), common_flags() and common_lock_depth(). Support for common_flags() field values was added to Core.pm and a script used to sanity check these and other basic scripting features, check-perf-trace.pl, was also added. Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Cc: fweisbec@gmail.com Cc: rostedt@goodmis.org Cc: anton@samba.org Cc: hch@infradead.org LKML-Reference: <1259133352-23685-6-git-send-email-tzanussi@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/trace-event-perl.c')
-rw-r--r--tools/perf/util/trace-event-perl.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/tools/perf/util/trace-event-perl.c b/tools/perf/util/trace-event-perl.c
index c56b08d704da..d179adebc547 100644
--- a/tools/perf/util/trace-event-perl.c
+++ b/tools/perf/util/trace-event-perl.c
@@ -30,6 +30,21 @@
30#include "trace-event.h" 30#include "trace-event.h"
31#include "trace-event-perl.h" 31#include "trace-event-perl.h"
32 32
33void xs_init(pTHX);
34
35void boot_Perf__Trace__Context(pTHX_ CV *cv);
36void boot_DynaLoader(pTHX_ CV *cv);
37
38void xs_init(pTHX)
39{
40 const char *file = __FILE__;
41 dXSUB_SYS;
42
43 newXS("Perf::Trace::Context::bootstrap", boot_Perf__Trace__Context,
44 file);
45 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
46}
47
33INTERP my_perl; 48INTERP my_perl;
34 49
35#define FTRACE_MAX_EVENT \ 50#define FTRACE_MAX_EVENT \
@@ -227,6 +242,33 @@ static inline struct event *find_cache_event(int type)
227 return event; 242 return event;
228} 243}
229 244
245int get_common_pc(struct scripting_context *context)
246{
247 int pc;
248
249 pc = parse_common_pc(context->event_data);
250
251 return pc;
252}
253
254int get_common_flags(struct scripting_context *context)
255{
256 int flags;
257
258 flags = parse_common_flags(context->event_data);
259
260 return flags;
261}
262
263int get_common_lock_depth(struct scripting_context *context)
264{
265 int lock_depth;
266
267 lock_depth = parse_common_lock_depth(context->event_data);
268
269 return lock_depth;
270}
271
230static void perl_process_event(int cpu, void *data, 272static void perl_process_event(int cpu, void *data,
231 int size __attribute((unused)), 273 int size __attribute((unused)),
232 unsigned long long nsecs, char *comm) 274 unsigned long long nsecs, char *comm)
@@ -290,6 +332,7 @@ static void perl_process_event(int cpu, void *data,
290 } 332 }
291 333
292 PUTBACK; 334 PUTBACK;
335
293 if (get_cv(handler, 0)) 336 if (get_cv(handler, 0))
294 call_pv(handler, G_SCALAR); 337 call_pv(handler, G_SCALAR);
295 else if (get_cv("main::trace_unhandled", 0)) { 338 else if (get_cv("main::trace_unhandled", 0)) {
@@ -328,7 +371,8 @@ static int perl_start_script(const char *script)
328 my_perl = perl_alloc(); 371 my_perl = perl_alloc();
329 perl_construct(my_perl); 372 perl_construct(my_perl);
330 373
331 if (perl_parse(my_perl, NULL, 2, (char **)command_line, (char **)NULL)) 374 if (perl_parse(my_perl, xs_init, 2, (char **)command_line,
375 (char **)NULL))
332 return -1; 376 return -1;
333 377
334 perl_run(my_perl); 378 perl_run(my_perl);