aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
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
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')
-rw-r--r--tools/perf/util/trace-event-parse.c6
-rw-r--r--tools/perf/util/trace-event-perl.c46
-rw-r--r--tools/perf/util/trace-event-perl.h9
-rw-r--r--tools/perf/util/trace-event.h3
4 files changed, 60 insertions, 4 deletions
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 1f16495e5597..0302405aa2ca 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -1982,7 +1982,7 @@ int trace_parse_common_pid(void *data)
1982 "common_pid"); 1982 "common_pid");
1983} 1983}
1984 1984
1985static int parse_common_pc(void *data) 1985int parse_common_pc(void *data)
1986{ 1986{
1987 static int pc_offset; 1987 static int pc_offset;
1988 static int pc_size; 1988 static int pc_size;
@@ -1991,7 +1991,7 @@ static int parse_common_pc(void *data)
1991 "common_preempt_count"); 1991 "common_preempt_count");
1992} 1992}
1993 1993
1994static int parse_common_flags(void *data) 1994int parse_common_flags(void *data)
1995{ 1995{
1996 static int flags_offset; 1996 static int flags_offset;
1997 static int flags_size; 1997 static int flags_size;
@@ -2000,7 +2000,7 @@ static int parse_common_flags(void *data)
2000 "common_flags"); 2000 "common_flags");
2001} 2001}
2002 2002
2003static int parse_common_lock_depth(void *data) 2003int parse_common_lock_depth(void *data)
2004{ 2004{
2005 static int ld_offset; 2005 static int ld_offset;
2006 static int ld_size; 2006 static int ld_size;
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);
diff --git a/tools/perf/util/trace-event-perl.h b/tools/perf/util/trace-event-perl.h
index 6c94fa93013d..666a864f5dda 100644
--- a/tools/perf/util/trace-event-perl.h
+++ b/tools/perf/util/trace-event-perl.h
@@ -29,6 +29,11 @@ typedef int INTERP;
29#define perl_run(a) (0) 29#define perl_run(a) (0)
30#define perl_destruct(a) (0) 30#define perl_destruct(a) (0)
31#define perl_free(a) (0) 31#define perl_free(a) (0)
32#define pTHX void
33#define CV void
34#define dXSUB_SYS
35#define pTHX_
36static inline void newXS(const char *a, void *b, const char *c) {}
32#else 37#else
33#include <EXTERN.h> 38#include <EXTERN.h>
34#include <perl.h> 39#include <perl.h>
@@ -39,4 +44,8 @@ struct scripting_context {
39 void *event_data; 44 void *event_data;
40}; 45};
41 46
47int get_common_pc(struct scripting_context *context);
48int get_common_flags(struct scripting_context *context);
49int get_common_lock_depth(struct scripting_context *context);
50
42#endif /* __PERF_TRACE_EVENT_PERL_H */ 51#endif /* __PERF_TRACE_EVENT_PERL_H */
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index b1e58d3d947d..81698d5e6503 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -246,6 +246,9 @@ extern int latency_format;
246int parse_header_page(char *buf, unsigned long size); 246int parse_header_page(char *buf, unsigned long size);
247int trace_parse_common_type(void *data); 247int trace_parse_common_type(void *data);
248int trace_parse_common_pid(void *data); 248int trace_parse_common_pid(void *data);
249int parse_common_pc(void *data);
250int parse_common_flags(void *data);
251int parse_common_lock_depth(void *data);
249struct event *trace_find_event(int id); 252struct event *trace_find_event(int id);
250struct event *trace_find_next_event(struct event *event); 253struct event *trace_find_next_event(struct event *event);
251unsigned long long read_size(void *ptr, int size); 254unsigned long long read_size(void *ptr, int size);