Skip to content

Commit

Permalink
perf script: Replace "struct thread" with "struct addr_location" as a…
Browse files Browse the repository at this point in the history
… parameter for "process_event()"

Both perl and python script start processing events other than trace
points, and it's useful to pass the resolved symbol and the dso info to
the event handler in script for better analysis and statistics.

Struct thread is already a member of struct addr_location, using
addr_location will keep the thread info, while providing additional
symbol and dso info if exist, so that the script itself doesn't need to
bother to do the symbol resolving and dso searching work.

Tested-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Feng Tang <feng.tang@intel.com>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1344419875-21665-3-git-send-email-feng.tang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Feng Tang authored and Arnaldo Carvalho de Melo committed Aug 8, 2012
1 parent 6a6daec commit 73994dc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
5 changes: 3 additions & 2 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,10 @@ static void print_sample_bts(union perf_event *event,

static void process_event(union perf_event *event, struct perf_sample *sample,
struct perf_evsel *evsel, struct machine *machine,
struct thread *thread)
struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
struct thread *thread = al->thread;

if (output[attr->type].fields == 0)
return;
Expand Down Expand Up @@ -511,7 +512,7 @@ static int process_sample_event(struct perf_tool *tool __used,
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
return 0;

scripting_ops->process_event(event, sample, evsel, machine, thread);
scripting_ops->process_event(event, sample, evsel, machine, &al);

evsel->hists.stats.total_period += sample->period;
return 0;
Expand Down
11 changes: 6 additions & 5 deletions tools/perf/util/scripting-engines/trace-event-perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
struct thread *thread)
struct addr_location *al)
{
struct format_field *field;
static char handler[256];
Expand All @@ -272,6 +272,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
int cpu = sample->cpu;
void *data = sample->raw_data;
unsigned long long nsecs = sample->time;
struct thread *thread = al->thread;
char *comm = thread->comm;

dSP;
Expand Down Expand Up @@ -349,7 +350,7 @@ static void perl_process_event_generic(union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
struct thread *thread __unused)
struct addr_location *al __unused)
{
dSP;

Expand All @@ -375,10 +376,10 @@ static void perl_process_event(union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
struct thread *thread)
struct addr_location *al)
{
perl_process_tracepoint(event, sample, evsel, machine, thread);
perl_process_event_generic(event, sample, evsel, machine, thread);
perl_process_tracepoint(event, sample, evsel, machine, al);
perl_process_event_generic(event, sample, evsel, machine, al);
}

static void run_start_sub(void)
Expand Down
13 changes: 7 additions & 6 deletions tools/perf/util/scripting-engines/trace-event-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void python_process_tracepoint(union perf_event *perf_event __unused,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
struct thread *thread)
struct addr_location *al)
{
PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
static char handler_name[256];
Expand All @@ -238,6 +238,7 @@ static void python_process_tracepoint(union perf_event *perf_event __unused,
int cpu = sample->cpu;
void *data = sample->raw_data;
unsigned long long nsecs = sample->time;
struct thread *thread = al->thread;
char *comm = thread->comm;

t = PyTuple_New(MAX_FIELDS);
Expand Down Expand Up @@ -342,7 +343,7 @@ static void python_process_general_event(union perf_event *perf_event __unused,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
struct thread *thread __unused)
struct addr_location *al __unused)
{
PyObject *handler, *retval, *t;
static char handler_name[64];
Expand All @@ -361,7 +362,7 @@ static void python_process_general_event(union perf_event *perf_event __unused,
goto exit;
}

/* Pass 3 parameters: event_attr, perf_sample, raw data */
/* Pass 4 parameters: event_attr, perf_sample, raw data, thread name */
PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)&evsel->attr, sizeof(evsel->attr)));
PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, sizeof(*sample)));
PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, sample->raw_size));
Expand All @@ -380,17 +381,17 @@ static void python_process_event(union perf_event *perf_event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
struct thread *thread)
struct addr_location *al)
{
switch (evsel->attr.type) {
case PERF_TYPE_TRACEPOINT:
python_process_tracepoint(perf_event, sample, evsel,
machine, thread);
machine, al);
break;
/* Reserve for future process_hw/sw/raw APIs */
default:
python_process_general_event(perf_event, sample, evsel,
machine, thread);
machine, al);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/trace-event-scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void process_event_unsupported(union perf_event *event __unused,
struct perf_sample *sample __unused,
struct perf_evsel *evsel __unused,
struct machine *machine __unused,
struct thread *thread __unused)
struct addr_location *al __unused)
{
}

Expand Down
5 changes: 3 additions & 2 deletions tools/perf/util/trace-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct machine;
struct perf_sample;
union perf_event;
struct perf_tool;
struct thread;

extern int header_page_size_size;
extern int header_page_ts_size;
Expand Down Expand Up @@ -76,6 +75,8 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
void tracing_data_put(struct tracing_data *tdata);


struct addr_location;

struct scripting_ops {
const char *name;
int (*start_script) (const char *script, int argc, const char **argv);
Expand All @@ -84,7 +85,7 @@ struct scripting_ops {
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
struct thread *thread);
struct addr_location *al);
int (*generate_script) (struct pevent *pevent, const char *outfile);
};

Expand Down

0 comments on commit 73994dc

Please sign in to comment.