aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c66
1 files changed, 44 insertions, 22 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8fecd3b8130a..1e60ab70b2b1 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -28,6 +28,11 @@ 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
31enum perf_output_field { 36enum perf_output_field {
32 PERF_OUTPUT_COMM = 1U << 0, 37 PERF_OUTPUT_COMM = 1U << 0,
33 PERF_OUTPUT_TID = 1U << 1, 38 PERF_OUTPUT_TID = 1U << 1,
@@ -257,7 +262,8 @@ static int perf_session__check_output_opt(struct perf_session *session)
257 return 0; 262 return 0;
258} 263}
259 264
260static void print_sample_start(struct perf_sample *sample, 265static void print_sample_start(struct pevent *pevent,
266 struct perf_sample *sample,
261 struct thread *thread, 267 struct thread *thread,
262 struct perf_evsel *evsel) 268 struct perf_evsel *evsel)
263{ 269{
@@ -302,8 +308,14 @@ static void print_sample_start(struct perf_sample *sample,
302 308
303 if (PRINT_FIELD(EVNAME)) { 309 if (PRINT_FIELD(EVNAME)) {
304 if (attr->type == PERF_TYPE_TRACEPOINT) { 310 if (attr->type == PERF_TYPE_TRACEPOINT) {
305 type = trace_parse_common_type(sample->raw_data); 311 /*
306 event = trace_find_event(type); 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);
307 if (event) 319 if (event)
308 evname = event->name; 320 evname = event->name;
309 } else 321 } else
@@ -404,6 +416,7 @@ static void print_sample_bts(union perf_event *event,
404} 416}
405 417
406static void process_event(union perf_event *event __unused, 418static void process_event(union perf_event *event __unused,
419 struct pevent *pevent,
407 struct perf_sample *sample, 420 struct perf_sample *sample,
408 struct perf_evsel *evsel, 421 struct perf_evsel *evsel,
409 struct machine *machine, 422 struct machine *machine,
@@ -414,7 +427,7 @@ static void process_event(union perf_event *event __unused,
414 if (output[attr->type].fields == 0) 427 if (output[attr->type].fields == 0)
415 return; 428 return;
416 429
417 print_sample_start(sample, thread, evsel); 430 print_sample_start(pevent, sample, thread, evsel);
418 431
419 if (is_bts_event(attr)) { 432 if (is_bts_event(attr)) {
420 print_sample_bts(event, sample, evsel, machine, thread); 433 print_sample_bts(event, sample, evsel, machine, thread);
@@ -422,7 +435,7 @@ static void process_event(union perf_event *event __unused,
422 } 435 }
423 436
424 if (PRINT_FIELD(TRACE)) 437 if (PRINT_FIELD(TRACE))
425 print_trace_event(sample->cpu, sample->raw_data, 438 print_trace_event(pevent, sample->cpu, sample->raw_data,
426 sample->raw_size); 439 sample->raw_size);
427 440
428 if (PRINT_FIELD(ADDR)) 441 if (PRINT_FIELD(ADDR))
@@ -453,7 +466,8 @@ static int default_stop_script(void)
453 return 0; 466 return 0;
454} 467}
455 468
456static int default_generate_script(const char *outfile __unused) 469static int default_generate_script(struct pevent *pevent __unused,
470 const char *outfile __unused)
457{ 471{
458 return 0; 472 return 0;
459} 473}
@@ -491,6 +505,7 @@ static int process_sample_event(struct perf_tool *tool __used,
491 struct machine *machine) 505 struct machine *machine)
492{ 506{
493 struct addr_location al; 507 struct addr_location al;
508 struct perf_script *scr = container_of(tool, struct perf_script, tool);
494 struct thread *thread = machine__findnew_thread(machine, event->ip.tid); 509 struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
495 510
496 if (thread == NULL) { 511 if (thread == NULL) {
@@ -522,24 +537,27 @@ static int process_sample_event(struct perf_tool *tool __used,
522 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 537 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
523 return 0; 538 return 0;
524 539
525 scripting_ops->process_event(event, sample, evsel, machine, thread); 540 scripting_ops->process_event(event, scr->session->pevent,
541 sample, evsel, machine, thread);
526 542
527 evsel->hists.stats.total_period += sample->period; 543 evsel->hists.stats.total_period += sample->period;
528 return 0; 544 return 0;
529} 545}
530 546
531static struct perf_tool perf_script = { 547static struct perf_script perf_script = {
532 .sample = process_sample_event, 548 .tool = {
533 .mmap = perf_event__process_mmap, 549 .sample = process_sample_event,
534 .comm = perf_event__process_comm, 550 .mmap = perf_event__process_mmap,
535 .exit = perf_event__process_task, 551 .comm = perf_event__process_comm,
536 .fork = perf_event__process_task, 552 .exit = perf_event__process_task,
537 .attr = perf_event__process_attr, 553 .fork = perf_event__process_task,
538 .event_type = perf_event__process_event_type, 554 .attr = perf_event__process_attr,
539 .tracing_data = perf_event__process_tracing_data, 555 .event_type = perf_event__process_event_type,
540 .build_id = perf_event__process_build_id, 556 .tracing_data = perf_event__process_tracing_data,
541 .ordered_samples = true, 557 .build_id = perf_event__process_build_id,
542 .ordering_requires_timestamps = true, 558 .ordered_samples = true,
559 .ordering_requires_timestamps = true,
560 },
543}; 561};
544 562
545extern volatile int session_done; 563extern volatile int session_done;
@@ -555,7 +573,7 @@ static int __cmd_script(struct perf_session *session)
555 573
556 signal(SIGINT, sig_handler); 574 signal(SIGINT, sig_handler);
557 575
558 ret = perf_session__process_events(session, &perf_script); 576 ret = perf_session__process_events(session, &perf_script.tool);
559 577
560 if (debug_mode) 578 if (debug_mode)
561 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); 579 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
@@ -1337,10 +1355,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
1337 if (!script_name) 1355 if (!script_name)
1338 setup_pager(); 1356 setup_pager();
1339 1357
1340 session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script); 1358 session = perf_session__new(input_name, O_RDONLY, 0, false,
1359 &perf_script.tool);
1341 if (session == NULL) 1360 if (session == NULL)
1342 return -ENOMEM; 1361 return -ENOMEM;
1343 1362
1363 perf_script.session = session;
1364
1344 if (cpu_list) { 1365 if (cpu_list) {
1345 if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap)) 1366 if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
1346 return -1; 1367 return -1;
@@ -1386,7 +1407,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
1386 return -1; 1407 return -1;
1387 } 1408 }
1388 1409
1389 err = scripting_ops->generate_script("perf-script"); 1410 err = scripting_ops->generate_script(session->pevent,
1411 "perf-script");
1390 goto out; 1412 goto out;
1391 } 1413 }
1392 1414