2012-04-05 22:47:52 +00:00
|
|
|
#ifndef _PERF_UTIL_TRACE_EVENT_H
|
|
|
|
#define _PERF_UTIL_TRACE_EVENT_H
|
2009-08-17 14:18:05 +00:00
|
|
|
|
2009-08-28 01:09:58 +00:00
|
|
|
#include "parse-events.h"
|
2012-04-05 22:47:56 +00:00
|
|
|
#include "event-parse.h"
|
2012-04-05 22:47:52 +00:00
|
|
|
#include "session.h"
|
2011-11-28 09:56:39 +00:00
|
|
|
|
|
|
|
struct machine;
|
|
|
|
struct perf_sample;
|
|
|
|
union perf_event;
|
2012-06-27 16:08:42 +00:00
|
|
|
struct perf_tool;
|
2011-11-28 09:56:39 +00:00
|
|
|
struct thread;
|
2009-08-17 14:18:05 +00:00
|
|
|
|
2012-04-05 22:47:56 +00:00
|
|
|
extern int header_page_size_size;
|
|
|
|
extern int header_page_ts_size;
|
|
|
|
extern int header_page_data_offset;
|
|
|
|
|
|
|
|
extern bool latency_format;
|
|
|
|
extern struct pevent *perf_pevent;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RINGBUF_TYPE_PADDING = 29,
|
|
|
|
RINGBUF_TYPE_TIME_EXTEND = 30,
|
|
|
|
RINGBUF_TYPE_TIME_STAMP = 31,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef TS_SHIFT
|
|
|
|
#define TS_SHIFT 27
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int bigendian(void);
|
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
struct pevent *read_trace_init(int file_bigendian, int host_bigendian);
|
|
|
|
void print_trace_event(struct pevent *pevent, int cpu, void *data, int size);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
void print_event(struct pevent *pevent, int cpu, void *data, int size,
|
|
|
|
unsigned long long nsecs, char *comm);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size);
|
|
|
|
int parse_event_file(struct pevent *pevent,
|
|
|
|
char *buf, unsigned long size, char *sys);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
struct pevent_record *trace_peek_data(struct pevent *pevent, int cpu);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
|
|
|
unsigned long long
|
|
|
|
raw_field_value(struct event_format *event, const char *name, void *data);
|
|
|
|
void *raw_field_ptr(struct event_format *event, const char *name, void *data);
|
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size);
|
|
|
|
void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
ssize_t trace_report(int fd, struct pevent **pevent, bool repipe);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
int trace_parse_common_type(struct pevent *pevent, void *data);
|
|
|
|
int trace_parse_common_pid(struct pevent *pevent, void *data);
|
2012-04-05 22:47:56 +00:00
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
struct event_format *trace_find_next_event(struct pevent *pevent,
|
|
|
|
struct event_format *event);
|
|
|
|
unsigned long long read_size(struct pevent *pevent, void *ptr, int size);
|
2012-04-05 22:47:56 +00:00
|
|
|
unsigned long long eval_flag(const char *flag);
|
|
|
|
|
2012-06-27 16:08:42 +00:00
|
|
|
struct pevent_record *trace_read_data(struct pevent *pevent, int cpu);
|
2011-01-03 18:39:04 +00:00
|
|
|
int read_tracing_data(int fd, struct list_head *pattrs);
|
2011-10-20 13:59:43 +00:00
|
|
|
|
|
|
|
struct tracing_data {
|
|
|
|
/* size is only valid if temp is 'true' */
|
|
|
|
ssize_t size;
|
|
|
|
bool temp;
|
|
|
|
char temp_file[50];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tracing_data *tracing_data_get(struct list_head *pattrs,
|
|
|
|
int fd, bool temp);
|
|
|
|
void tracing_data_put(struct tracing_data *tdata);
|
|
|
|
|
2009-08-17 14:18:05 +00:00
|
|
|
|
perf trace: Add scripting ops
Adds an interface, scripting_ops, that when implemented for a
particular scripting language enables built-in support for trace
stream processing using that language.
The interface is designed to enable full-fledged language
interpreters to be embedded inside the perf executable and
thereby make the full capabilities of the supported languages
available for trace processing.
See below for details on the interface.
This patch also adds a couple command-line options to 'perf
trace':
The -s option option is used to specify the script to be run.
Script names that can be used with -s take the form:
[language spec:]scriptname[.ext]
Scripting languages register a set of 'language specs' that can
be used to specify scripts for the registered languages. The
specs can be used either as prefixes or extensions.
If [language spec:] is used, the script is taken as a script of
the matching language regardless of any extension it might have.
If [language spec:] is not used, [.ext] is used to look up the
language it corresponds to. Language specs are case
insensitive.
e.g. Perl scripts can be specified in the following ways:
Perl:scriptname
pl:scriptname.py # extension ignored
PL:scriptname
scriptname.pl
scriptname.perl
The -g [language spec] option gives users an easy starting point
for writing scripts in the specified language. Scripting
support for a particular language can implement a
generate_script() scripting op that outputs an empty (or
near-empty) set of handlers for all the events contained in a
given perf.data trace file - this option gives users a direct
way to access that.
Adding support for a scripting language
---------------------------------------
The main thing that needs to be done do add support for a new
language is to implement the scripting_ops interface:
It consists of the following four functions:
start_script()
stop_script()
process_event()
generate_script()
start_script() is called before any events are processed, and is
meant to give the scripting language support an opportunity to
set things up to receive events e.g. create and initialize an
instance of a language interpreter.
stop_script() is called after all events are processed, and is
meant to give the scripting language support an opportunity to
clean up e.g. destroy the interpreter instance, etc.
process_event() is called once for each event and takes as its
main parameter a pointer to the binary trace event record to be
processed. The implementation is responsible for picking out the
binary fields from the event record and sending them to the
script handler function associated with that event e.g. a
function derived from the event name it's meant to handle e.g.
'sched::sched_switch()'. The 'format' information for trace
events can be used to parse the binary data and map it into a
form usable by a given scripting language; see the Perl
implemention in subsequent patches for one possible way to
leverage the existing trace format parsing code in perf and map
that info into specific scripting language types.
generate_script() should generate a ready-to-run script for the
current set of events in the trace, preferably with bodies that
print out every field for each event. Again, look at the Perl
implementation for clues as to how that can be done. This is an
optional, but very useful op.
Support for a given language should also add a language-specific
setup function and call it from setup_scripting(). The
language-specific setup function associates the the scripting
ops for that language with one or more 'language specifiers'
(see below) using script_spec_register(). When a script name is
specified on the command line, the scripting ops associated with
the specified language are used to instantiate and use the
appropriate interpreter to process the trace stream.
In general, it should be relatively easy to add support for a
new language, especially if the language implementation supports
an interface allowing an interpreter to be 'embedded' inside
another program (in this case the containing program will be
'perf trace'). If so, it should be relatively straightforward to
translate trace events into invocations of user-defined script
functions where e.g. the function name corresponds to the event
type and the function parameters correspond to the event fields.
The event and field type information exported by the event
tracing infrastructure (via the event 'format' files) should be
enough to parse and send any piece of trace data to the user
script. The easiest way to see how this can be done would be to
look at the Perl implementation contained in
perf/util/trace-event-perl.c/.h.
There are a couple of other things that aren't covered by the
scripting_ops or setup interface and are technically optional,
but should be implemented if possible. One of these is support
for 'flag' and 'symbolic' fields e.g. being able to use more
human-readable values such as 'GFP_KERNEL' or
HI/BLOCK_IOPOLL/TASKLET in place of raw flag values. See the
Perl implementation to see how this can be done. The other thing
is support for 'calling back' into the perf executable to access
e.g. uncommon fields not passed by default into handler
functions, or any metadata the implementation might want to make
available to users via the language interface. Again, see the
Perl implementation for examples.
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-2-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-25 07:15:46 +00:00
|
|
|
struct scripting_ops {
|
|
|
|
const char *name;
|
2009-12-15 08:53:35 +00:00
|
|
|
int (*start_script) (const char *script, int argc, const char **argv);
|
perf trace: Add scripting ops
Adds an interface, scripting_ops, that when implemented for a
particular scripting language enables built-in support for trace
stream processing using that language.
The interface is designed to enable full-fledged language
interpreters to be embedded inside the perf executable and
thereby make the full capabilities of the supported languages
available for trace processing.
See below for details on the interface.
This patch also adds a couple command-line options to 'perf
trace':
The -s option option is used to specify the script to be run.
Script names that can be used with -s take the form:
[language spec:]scriptname[.ext]
Scripting languages register a set of 'language specs' that can
be used to specify scripts for the registered languages. The
specs can be used either as prefixes or extensions.
If [language spec:] is used, the script is taken as a script of
the matching language regardless of any extension it might have.
If [language spec:] is not used, [.ext] is used to look up the
language it corresponds to. Language specs are case
insensitive.
e.g. Perl scripts can be specified in the following ways:
Perl:scriptname
pl:scriptname.py # extension ignored
PL:scriptname
scriptname.pl
scriptname.perl
The -g [language spec] option gives users an easy starting point
for writing scripts in the specified language. Scripting
support for a particular language can implement a
generate_script() scripting op that outputs an empty (or
near-empty) set of handlers for all the events contained in a
given perf.data trace file - this option gives users a direct
way to access that.
Adding support for a scripting language
---------------------------------------
The main thing that needs to be done do add support for a new
language is to implement the scripting_ops interface:
It consists of the following four functions:
start_script()
stop_script()
process_event()
generate_script()
start_script() is called before any events are processed, and is
meant to give the scripting language support an opportunity to
set things up to receive events e.g. create and initialize an
instance of a language interpreter.
stop_script() is called after all events are processed, and is
meant to give the scripting language support an opportunity to
clean up e.g. destroy the interpreter instance, etc.
process_event() is called once for each event and takes as its
main parameter a pointer to the binary trace event record to be
processed. The implementation is responsible for picking out the
binary fields from the event record and sending them to the
script handler function associated with that event e.g. a
function derived from the event name it's meant to handle e.g.
'sched::sched_switch()'. The 'format' information for trace
events can be used to parse the binary data and map it into a
form usable by a given scripting language; see the Perl
implemention in subsequent patches for one possible way to
leverage the existing trace format parsing code in perf and map
that info into specific scripting language types.
generate_script() should generate a ready-to-run script for the
current set of events in the trace, preferably with bodies that
print out every field for each event. Again, look at the Perl
implementation for clues as to how that can be done. This is an
optional, but very useful op.
Support for a given language should also add a language-specific
setup function and call it from setup_scripting(). The
language-specific setup function associates the the scripting
ops for that language with one or more 'language specifiers'
(see below) using script_spec_register(). When a script name is
specified on the command line, the scripting ops associated with
the specified language are used to instantiate and use the
appropriate interpreter to process the trace stream.
In general, it should be relatively easy to add support for a
new language, especially if the language implementation supports
an interface allowing an interpreter to be 'embedded' inside
another program (in this case the containing program will be
'perf trace'). If so, it should be relatively straightforward to
translate trace events into invocations of user-defined script
functions where e.g. the function name corresponds to the event
type and the function parameters correspond to the event fields.
The event and field type information exported by the event
tracing infrastructure (via the event 'format' files) should be
enough to parse and send any piece of trace data to the user
script. The easiest way to see how this can be done would be to
look at the Perl implementation contained in
perf/util/trace-event-perl.c/.h.
There are a couple of other things that aren't covered by the
scripting_ops or setup interface and are technically optional,
but should be implemented if possible. One of these is support
for 'flag' and 'symbolic' fields e.g. being able to use more
human-readable values such as 'GFP_KERNEL' or
HI/BLOCK_IOPOLL/TASKLET in place of raw flag values. See the
Perl implementation to see how this can be done. The other thing
is support for 'calling back' into the perf executable to access
e.g. uncommon fields not passed by default into handler
functions, or any metadata the implementation might want to make
available to users via the language interface. Again, see the
Perl implementation for examples.
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-2-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-25 07:15:46 +00:00
|
|
|
int (*stop_script) (void);
|
2011-03-10 05:23:23 +00:00
|
|
|
void (*process_event) (union perf_event *event,
|
2012-06-27 16:08:42 +00:00
|
|
|
struct pevent *pevent,
|
2011-03-10 05:23:23 +00:00
|
|
|
struct perf_sample *sample,
|
2011-03-15 18:44:01 +00:00
|
|
|
struct perf_evsel *evsel,
|
2011-11-28 09:56:39 +00:00
|
|
|
struct machine *machine,
|
2011-03-10 05:23:23 +00:00
|
|
|
struct thread *thread);
|
2012-06-27 16:08:42 +00:00
|
|
|
int (*generate_script) (struct pevent *pevent, const char *outfile);
|
perf trace: Add scripting ops
Adds an interface, scripting_ops, that when implemented for a
particular scripting language enables built-in support for trace
stream processing using that language.
The interface is designed to enable full-fledged language
interpreters to be embedded inside the perf executable and
thereby make the full capabilities of the supported languages
available for trace processing.
See below for details on the interface.
This patch also adds a couple command-line options to 'perf
trace':
The -s option option is used to specify the script to be run.
Script names that can be used with -s take the form:
[language spec:]scriptname[.ext]
Scripting languages register a set of 'language specs' that can
be used to specify scripts for the registered languages. The
specs can be used either as prefixes or extensions.
If [language spec:] is used, the script is taken as a script of
the matching language regardless of any extension it might have.
If [language spec:] is not used, [.ext] is used to look up the
language it corresponds to. Language specs are case
insensitive.
e.g. Perl scripts can be specified in the following ways:
Perl:scriptname
pl:scriptname.py # extension ignored
PL:scriptname
scriptname.pl
scriptname.perl
The -g [language spec] option gives users an easy starting point
for writing scripts in the specified language. Scripting
support for a particular language can implement a
generate_script() scripting op that outputs an empty (or
near-empty) set of handlers for all the events contained in a
given perf.data trace file - this option gives users a direct
way to access that.
Adding support for a scripting language
---------------------------------------
The main thing that needs to be done do add support for a new
language is to implement the scripting_ops interface:
It consists of the following four functions:
start_script()
stop_script()
process_event()
generate_script()
start_script() is called before any events are processed, and is
meant to give the scripting language support an opportunity to
set things up to receive events e.g. create and initialize an
instance of a language interpreter.
stop_script() is called after all events are processed, and is
meant to give the scripting language support an opportunity to
clean up e.g. destroy the interpreter instance, etc.
process_event() is called once for each event and takes as its
main parameter a pointer to the binary trace event record to be
processed. The implementation is responsible for picking out the
binary fields from the event record and sending them to the
script handler function associated with that event e.g. a
function derived from the event name it's meant to handle e.g.
'sched::sched_switch()'. The 'format' information for trace
events can be used to parse the binary data and map it into a
form usable by a given scripting language; see the Perl
implemention in subsequent patches for one possible way to
leverage the existing trace format parsing code in perf and map
that info into specific scripting language types.
generate_script() should generate a ready-to-run script for the
current set of events in the trace, preferably with bodies that
print out every field for each event. Again, look at the Perl
implementation for clues as to how that can be done. This is an
optional, but very useful op.
Support for a given language should also add a language-specific
setup function and call it from setup_scripting(). The
language-specific setup function associates the the scripting
ops for that language with one or more 'language specifiers'
(see below) using script_spec_register(). When a script name is
specified on the command line, the scripting ops associated with
the specified language are used to instantiate and use the
appropriate interpreter to process the trace stream.
In general, it should be relatively easy to add support for a
new language, especially if the language implementation supports
an interface allowing an interpreter to be 'embedded' inside
another program (in this case the containing program will be
'perf trace'). If so, it should be relatively straightforward to
translate trace events into invocations of user-defined script
functions where e.g. the function name corresponds to the event
type and the function parameters correspond to the event fields.
The event and field type information exported by the event
tracing infrastructure (via the event 'format' files) should be
enough to parse and send any piece of trace data to the user
script. The easiest way to see how this can be done would be to
look at the Perl implementation contained in
perf/util/trace-event-perl.c/.h.
There are a couple of other things that aren't covered by the
scripting_ops or setup interface and are technically optional,
but should be implemented if possible. One of these is support
for 'flag' and 'symbolic' fields e.g. being able to use more
human-readable values such as 'GFP_KERNEL' or
HI/BLOCK_IOPOLL/TASKLET in place of raw flag values. See the
Perl implementation to see how this can be done. The other thing
is support for 'calling back' into the perf executable to access
e.g. uncommon fields not passed by default into handler
functions, or any metadata the implementation might want to make
available to users via the language interface. Again, see the
Perl implementation for examples.
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-2-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-25 07:15:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int script_spec_register(const char *spec, struct scripting_ops *ops);
|
|
|
|
|
2009-11-25 07:15:48 +00:00
|
|
|
void setup_perl_scripting(void);
|
2010-01-27 08:27:57 +00:00
|
|
|
void setup_python_scripting(void);
|
2009-11-25 07:15:48 +00:00
|
|
|
|
2010-01-27 08:27:54 +00:00
|
|
|
struct scripting_context {
|
2012-06-27 16:08:42 +00:00
|
|
|
struct pevent *pevent;
|
2010-01-27 08:27:54 +00:00
|
|
|
void *event_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
int common_pc(struct scripting_context *context);
|
|
|
|
int common_flags(struct scripting_context *context);
|
|
|
|
int common_lock_depth(struct scripting_context *context);
|
|
|
|
|
2012-04-05 22:47:52 +00:00
|
|
|
#endif /* _PERF_UTIL_TRACE_EVENT_H */
|