aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeng Tang <feng.tang@intel.com>2012-08-08 05:57:52 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-08-08 11:46:40 -0400
commit73994dc158a24df4af77d0a76c9702f120f7a6ad (patch)
tree26380804ed9dd1c8bc6e3d00459aaed01edd4d74
parent6a6daec2ae9f097703c1da4925367f1c198c9492 (diff)
perf script: Replace "struct thread" with "struct addr_location" as a 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>
-rw-r--r--tools/perf/builtin-script.c5
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c11
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c13
-rw-r--r--tools/perf/util/trace-event-scripting.c2
-rw-r--r--tools/perf/util/trace-event.h5
5 files changed, 20 insertions, 16 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6425612b4d99..30a9cb8c9927 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -396,9 +396,10 @@ static void print_sample_bts(union perf_event *event,
396 396
397static void process_event(union perf_event *event, struct perf_sample *sample, 397static void process_event(union perf_event *event, struct perf_sample *sample,
398 struct perf_evsel *evsel, struct machine *machine, 398 struct perf_evsel *evsel, struct machine *machine,
399 struct thread *thread) 399 struct addr_location *al)
400{ 400{
401 struct perf_event_attr *attr = &evsel->attr; 401 struct perf_event_attr *attr = &evsel->attr;
402 struct thread *thread = al->thread;
402 403
403 if (output[attr->type].fields == 0) 404 if (output[attr->type].fields == 0)
404 return; 405 return;
@@ -511,7 +512,7 @@ static int process_sample_event(struct perf_tool *tool __used,
511 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 512 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
512 return 0; 513 return 0;
513 514
514 scripting_ops->process_event(event, sample, evsel, machine, thread); 515 scripting_ops->process_event(event, sample, evsel, machine, &al);
515 516
516 evsel->hists.stats.total_period += sample->period; 517 evsel->hists.stats.total_period += sample->period;
517 return 0; 518 return 0;
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 52580d09d75c..d28001016fb5 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -261,7 +261,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
261 struct perf_sample *sample, 261 struct perf_sample *sample,
262 struct perf_evsel *evsel, 262 struct perf_evsel *evsel,
263 struct machine *machine __unused, 263 struct machine *machine __unused,
264 struct thread *thread) 264 struct addr_location *al)
265{ 265{
266 struct format_field *field; 266 struct format_field *field;
267 static char handler[256]; 267 static char handler[256];
@@ -272,6 +272,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
272 int cpu = sample->cpu; 272 int cpu = sample->cpu;
273 void *data = sample->raw_data; 273 void *data = sample->raw_data;
274 unsigned long long nsecs = sample->time; 274 unsigned long long nsecs = sample->time;
275 struct thread *thread = al->thread;
275 char *comm = thread->comm; 276 char *comm = thread->comm;
276 277
277 dSP; 278 dSP;
@@ -349,7 +350,7 @@ static void perl_process_event_generic(union perf_event *event,
349 struct perf_sample *sample, 350 struct perf_sample *sample,
350 struct perf_evsel *evsel, 351 struct perf_evsel *evsel,
351 struct machine *machine __unused, 352 struct machine *machine __unused,
352 struct thread *thread __unused) 353 struct addr_location *al __unused)
353{ 354{
354 dSP; 355 dSP;
355 356
@@ -375,10 +376,10 @@ static void perl_process_event(union perf_event *event,
375 struct perf_sample *sample, 376 struct perf_sample *sample,
376 struct perf_evsel *evsel, 377 struct perf_evsel *evsel,
377 struct machine *machine, 378 struct machine *machine,
378 struct thread *thread) 379 struct addr_location *al)
379{ 380{
380 perl_process_tracepoint(event, sample, evsel, machine, thread); 381 perl_process_tracepoint(event, sample, evsel, machine, al);
381 perl_process_event_generic(event, sample, evsel, machine, thread); 382 perl_process_event_generic(event, sample, evsel, machine, al);
382} 383}
383 384
384static void run_start_sub(void) 385static void run_start_sub(void)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index b9010d878b4b..24711b3536d3 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -225,7 +225,7 @@ static void python_process_tracepoint(union perf_event *perf_event __unused,
225 struct perf_sample *sample, 225 struct perf_sample *sample,
226 struct perf_evsel *evsel, 226 struct perf_evsel *evsel,
227 struct machine *machine __unused, 227 struct machine *machine __unused,
228 struct thread *thread) 228 struct addr_location *al)
229{ 229{
230 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; 230 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
231 static char handler_name[256]; 231 static char handler_name[256];
@@ -238,6 +238,7 @@ static void python_process_tracepoint(union perf_event *perf_event __unused,
238 int cpu = sample->cpu; 238 int cpu = sample->cpu;
239 void *data = sample->raw_data; 239 void *data = sample->raw_data;
240 unsigned long long nsecs = sample->time; 240 unsigned long long nsecs = sample->time;
241 struct thread *thread = al->thread;
241 char *comm = thread->comm; 242 char *comm = thread->comm;
242 243
243 t = PyTuple_New(MAX_FIELDS); 244 t = PyTuple_New(MAX_FIELDS);
@@ -342,7 +343,7 @@ static void python_process_general_event(union perf_event *perf_event __unused,
342 struct perf_sample *sample, 343 struct perf_sample *sample,
343 struct perf_evsel *evsel, 344 struct perf_evsel *evsel,
344 struct machine *machine __unused, 345 struct machine *machine __unused,
345 struct thread *thread __unused) 346 struct addr_location *al __unused)
346{ 347{
347 PyObject *handler, *retval, *t; 348 PyObject *handler, *retval, *t;
348 static char handler_name[64]; 349 static char handler_name[64];
@@ -361,7 +362,7 @@ static void python_process_general_event(union perf_event *perf_event __unused,
361 goto exit; 362 goto exit;
362 } 363 }
363 364
364 /* Pass 3 parameters: event_attr, perf_sample, raw data */ 365 /* Pass 4 parameters: event_attr, perf_sample, raw data, thread name */
365 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)&evsel->attr, sizeof(evsel->attr))); 366 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)&evsel->attr, sizeof(evsel->attr)));
366 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, sizeof(*sample))); 367 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, sizeof(*sample)));
367 PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, sample->raw_size)); 368 PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, sample->raw_size));
@@ -380,17 +381,17 @@ static void python_process_event(union perf_event *perf_event,
380 struct perf_sample *sample, 381 struct perf_sample *sample,
381 struct perf_evsel *evsel, 382 struct perf_evsel *evsel,
382 struct machine *machine, 383 struct machine *machine,
383 struct thread *thread) 384 struct addr_location *al)
384{ 385{
385 switch (evsel->attr.type) { 386 switch (evsel->attr.type) {
386 case PERF_TYPE_TRACEPOINT: 387 case PERF_TYPE_TRACEPOINT:
387 python_process_tracepoint(perf_event, sample, evsel, 388 python_process_tracepoint(perf_event, sample, evsel,
388 machine, thread); 389 machine, al);
389 break; 390 break;
390 /* Reserve for future process_hw/sw/raw APIs */ 391 /* Reserve for future process_hw/sw/raw APIs */
391 default: 392 default:
392 python_process_general_event(perf_event, sample, evsel, 393 python_process_general_event(perf_event, sample, evsel,
393 machine, thread); 394 machine, al);
394 } 395 }
395} 396}
396 397
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index aceb8eea15fc..302ff262494c 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -39,7 +39,7 @@ static void process_event_unsupported(union perf_event *event __unused,
39 struct perf_sample *sample __unused, 39 struct perf_sample *sample __unused,
40 struct perf_evsel *evsel __unused, 40 struct perf_evsel *evsel __unused,
41 struct machine *machine __unused, 41 struct machine *machine __unused,
42 struct thread *thread __unused) 42 struct addr_location *al __unused)
43{ 43{
44} 44}
45 45
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index cee16350cd86..7575dfd26e58 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -9,7 +9,6 @@ struct machine;
9struct perf_sample; 9struct perf_sample;
10union perf_event; 10union perf_event;
11struct perf_tool; 11struct perf_tool;
12struct thread;
13 12
14extern int header_page_size_size; 13extern int header_page_size_size;
15extern int header_page_ts_size; 14extern int header_page_ts_size;
@@ -76,6 +75,8 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
76void tracing_data_put(struct tracing_data *tdata); 75void tracing_data_put(struct tracing_data *tdata);
77 76
78 77
78struct addr_location;
79
79struct scripting_ops { 80struct scripting_ops {
80 const char *name; 81 const char *name;
81 int (*start_script) (const char *script, int argc, const char **argv); 82 int (*start_script) (const char *script, int argc, const char **argv);
@@ -84,7 +85,7 @@ struct scripting_ops {
84 struct perf_sample *sample, 85 struct perf_sample *sample,
85 struct perf_evsel *evsel, 86 struct perf_evsel *evsel,
86 struct machine *machine, 87 struct machine *machine,
87 struct thread *thread); 88 struct addr_location *al);
88 int (*generate_script) (struct pevent *pevent, const char *outfile); 89 int (*generate_script) (struct pevent *pevent, const char *outfile);
89}; 90};
90 91