aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2012-08-21 05:27:00 -0400
committerIngo Molnar <mingo@kernel.org>2012-08-21 05:27:00 -0400
commitbcada3d4b8c96b8792c2306f363992ca5ab9da42 (patch)
treee420679a5db6ea4e1694eef57f9abb6acac8d4d3 /tools/perf/builtin-script.c
parent26198c21d1b286a084fe5d514a30bc7e6c712a34 (diff)
parent000078bc3ee69efb1124b8478c7527389a826074 (diff)
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: * Fix include order for bison/flex-generated C files, from Ben Hutchings * Build fixes and documentation corrections from David Ahern * Group parsing support, from Jiri Olsa * UI/gtk refactorings and improvements from Namhyung Kim * NULL deref fix for perf script, from Namhyung Kim * Assorted cleanups from Robert Richter * Let O= makes handle relative paths, from Steven Rostedt * perf script python fixes, from Feng Tang. * Improve 'perf lock' error message when the needed tracepoints are not present, from David Ahern. * Initial bash completion support, from Frederic Weisbecker * Allow building without libelf, from Namhyung Kim. * Support DWARF CFI based unwind to have callchains when %bp based unwinding is not possible, from Jiri Olsa. * Symbol resolution fixes, while fixing support PPC64 files with an .opt ELF section was the end goal, several fixes for code that handles all architectures and cleanups are included, from Cody Schafer. * Add a description for the JIT interface, from Andi Kleen. * Assorted fixes for Documentation and build in 32 bit, from Robert Richter * Add support for non-tracepoint events in perf script python, from Feng Tang * Cache the libtraceevent event_format associated to each evsel early, so that we avoid relookups, i.e. calling pevent_find_event repeatedly when processing tracepoint events. [ This is to reduce the surface contact with libtraceevents and make clear what is that the perf tools needs from that lib: so far parsing the common and per event fields. ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c82
1 files changed, 26 insertions, 56 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab70b2b1..2d6e3b226aad 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -28,11 +28,6 @@ static bool system_wide;
28static const char *cpu_list; 28static const char *cpu_list;
29static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 29static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
30 30
31struct perf_script {
32 struct perf_tool tool;
33 struct perf_session *session;
34};
35
36enum perf_output_field { 31enum perf_output_field {
37 PERF_OUTPUT_COMM = 1U << 0, 32 PERF_OUTPUT_COMM = 1U << 0,
38 PERF_OUTPUT_TID = 1U << 1, 33 PERF_OUTPUT_TID = 1U << 1,
@@ -262,14 +257,11 @@ static int perf_session__check_output_opt(struct perf_session *session)
262 return 0; 257 return 0;
263} 258}
264 259
265static void print_sample_start(struct pevent *pevent, 260static void print_sample_start(struct perf_sample *sample,
266 struct perf_sample *sample,
267 struct thread *thread, 261 struct thread *thread,
268 struct perf_evsel *evsel) 262 struct perf_evsel *evsel)
269{ 263{
270 int type;
271 struct perf_event_attr *attr = &evsel->attr; 264 struct perf_event_attr *attr = &evsel->attr;
272 struct event_format *event;
273 const char *evname = NULL; 265 const char *evname = NULL;
274 unsigned long secs; 266 unsigned long secs;
275 unsigned long usecs; 267 unsigned long usecs;
@@ -307,20 +299,7 @@ static void print_sample_start(struct pevent *pevent,
307 } 299 }
308 300
309 if (PRINT_FIELD(EVNAME)) { 301 if (PRINT_FIELD(EVNAME)) {
310 if (attr->type == PERF_TYPE_TRACEPOINT) { 302 evname = perf_evsel__name(evsel);
311 /*
312 * XXX Do we really need this here?
313 * perf_evlist__set_tracepoint_names should have done
314 * this already
315 */
316 type = trace_parse_common_type(pevent,
317 sample->raw_data);
318 event = pevent_find_event(pevent, type);
319 if (event)
320 evname = event->name;
321 } else
322 evname = perf_evsel__name(evsel);
323
324 printf("%s: ", evname ? evname : "[unknown]"); 303 printf("%s: ", evname ? evname : "[unknown]");
325 } 304 }
326} 305}
@@ -401,7 +380,7 @@ static void print_sample_bts(union perf_event *event,
401 printf(" "); 380 printf(" ");
402 else 381 else
403 printf("\n"); 382 printf("\n");
404 perf_event__print_ip(event, sample, machine, 383 perf_evsel__print_ip(evsel, event, sample, machine,
405 PRINT_FIELD(SYM), PRINT_FIELD(DSO), 384 PRINT_FIELD(SYM), PRINT_FIELD(DSO),
406 PRINT_FIELD(SYMOFFSET)); 385 PRINT_FIELD(SYMOFFSET));
407 } 386 }
@@ -415,19 +394,17 @@ static void print_sample_bts(union perf_event *event,
415 printf("\n"); 394 printf("\n");
416} 395}
417 396
418static void process_event(union perf_event *event __unused, 397static void process_event(union perf_event *event, struct perf_sample *sample,
419 struct pevent *pevent, 398 struct perf_evsel *evsel, struct machine *machine,
420 struct perf_sample *sample, 399 struct addr_location *al)
421 struct perf_evsel *evsel,
422 struct machine *machine,
423 struct thread *thread)
424{ 400{
425 struct perf_event_attr *attr = &evsel->attr; 401 struct perf_event_attr *attr = &evsel->attr;
402 struct thread *thread = al->thread;
426 403
427 if (output[attr->type].fields == 0) 404 if (output[attr->type].fields == 0)
428 return; 405 return;
429 406
430 print_sample_start(pevent, sample, thread, evsel); 407 print_sample_start(sample, thread, evsel);
431 408
432 if (is_bts_event(attr)) { 409 if (is_bts_event(attr)) {
433 print_sample_bts(event, sample, evsel, machine, thread); 410 print_sample_bts(event, sample, evsel, machine, thread);
@@ -435,9 +412,8 @@ static void process_event(union perf_event *event __unused,
435 } 412 }
436 413
437 if (PRINT_FIELD(TRACE)) 414 if (PRINT_FIELD(TRACE))
438 print_trace_event(pevent, sample->cpu, sample->raw_data, 415 event_format__print(evsel->tp_format, sample->cpu,
439 sample->raw_size); 416 sample->raw_data, sample->raw_size);
440
441 if (PRINT_FIELD(ADDR)) 417 if (PRINT_FIELD(ADDR))
442 print_sample_addr(event, sample, machine, thread, attr); 418 print_sample_addr(event, sample, machine, thread, attr);
443 419
@@ -446,7 +422,7 @@ static void process_event(union perf_event *event __unused,
446 printf(" "); 422 printf(" ");
447 else 423 else
448 printf("\n"); 424 printf("\n");
449 perf_event__print_ip(event, sample, machine, 425 perf_evsel__print_ip(evsel, event, sample, machine,
450 PRINT_FIELD(SYM), PRINT_FIELD(DSO), 426 PRINT_FIELD(SYM), PRINT_FIELD(DSO),
451 PRINT_FIELD(SYMOFFSET)); 427 PRINT_FIELD(SYMOFFSET));
452 } 428 }
@@ -505,7 +481,6 @@ static int process_sample_event(struct perf_tool *tool __used,
505 struct machine *machine) 481 struct machine *machine)
506{ 482{
507 struct addr_location al; 483 struct addr_location al;
508 struct perf_script *scr = container_of(tool, struct perf_script, tool);
509 struct thread *thread = machine__findnew_thread(machine, event->ip.tid); 484 struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
510 485
511 if (thread == NULL) { 486 if (thread == NULL) {
@@ -537,27 +512,24 @@ static int process_sample_event(struct perf_tool *tool __used,
537 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 512 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
538 return 0; 513 return 0;
539 514
540 scripting_ops->process_event(event, scr->session->pevent, 515 scripting_ops->process_event(event, sample, evsel, machine, &al);
541 sample, evsel, machine, thread);
542 516
543 evsel->hists.stats.total_period += sample->period; 517 evsel->hists.stats.total_period += sample->period;
544 return 0; 518 return 0;
545} 519}
546 520
547static struct perf_script perf_script = { 521static struct perf_tool perf_script = {
548 .tool = { 522 .sample = process_sample_event,
549 .sample = process_sample_event, 523 .mmap = perf_event__process_mmap,
550 .mmap = perf_event__process_mmap, 524 .comm = perf_event__process_comm,
551 .comm = perf_event__process_comm, 525 .exit = perf_event__process_task,
552 .exit = perf_event__process_task, 526 .fork = perf_event__process_task,
553 .fork = perf_event__process_task, 527 .attr = perf_event__process_attr,
554 .attr = perf_event__process_attr, 528 .event_type = perf_event__process_event_type,
555 .event_type = perf_event__process_event_type, 529 .tracing_data = perf_event__process_tracing_data,
556 .tracing_data = perf_event__process_tracing_data, 530 .build_id = perf_event__process_build_id,
557 .build_id = perf_event__process_build_id, 531 .ordered_samples = true,
558 .ordered_samples = true, 532 .ordering_requires_timestamps = true,
559 .ordering_requires_timestamps = true,
560 },
561}; 533};
562 534
563extern volatile int session_done; 535extern volatile int session_done;
@@ -573,7 +545,7 @@ static int __cmd_script(struct perf_session *session)
573 545
574 signal(SIGINT, sig_handler); 546 signal(SIGINT, sig_handler);
575 547
576 ret = perf_session__process_events(session, &perf_script.tool); 548 ret = perf_session__process_events(session, &perf_script);
577 549
578 if (debug_mode) 550 if (debug_mode)
579 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); 551 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
@@ -1356,12 +1328,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
1356 setup_pager(); 1328 setup_pager();
1357 1329
1358 session = perf_session__new(input_name, O_RDONLY, 0, false, 1330 session = perf_session__new(input_name, O_RDONLY, 0, false,
1359 &perf_script.tool); 1331 &perf_script);
1360 if (session == NULL) 1332 if (session == NULL)
1361 return -ENOMEM; 1333 return -ENOMEM;
1362 1334
1363 perf_script.session = session;
1364
1365 if (cpu_list) { 1335 if (cpu_list) {
1366 if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap)) 1336 if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
1367 return -1; 1337 return -1;