aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-kmem.c37
-rw-r--r--tools/perf/builtin-lock.c4
-rw-r--r--tools/perf/builtin-sched.c36
-rw-r--r--tools/perf/builtin-script.c66
-rw-r--r--tools/perf/util/evlist.c4
-rw-r--r--tools/perf/util/evlist.h3
-rw-r--r--tools/perf/util/header.c31
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c28
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c21
-rw-r--r--tools/perf/util/session.c56
-rw-r--r--tools/perf/util/session.h10
-rw-r--r--tools/perf/util/trace-event-parse.c58
-rw-r--r--tools/perf/util/trace-event-read.c97
-rw-r--r--tools/perf/util/trace-event-scripting.c7
-rw-r--r--tools/perf/util/trace-event.h38
15 files changed, 314 insertions, 182 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 547af48deb4f..ce35015f2dc6 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -57,6 +57,11 @@ static unsigned long nr_allocs, nr_cross_allocs;
57 57
58#define PATH_SYS_NODE "/sys/devices/system/node" 58#define PATH_SYS_NODE "/sys/devices/system/node"
59 59
60struct perf_kmem {
61 struct perf_tool tool;
62 struct perf_session *session;
63};
64
60static void init_cpunode_map(void) 65static void init_cpunode_map(void)
61{ 66{
62 FILE *fp; 67 FILE *fp;
@@ -278,14 +283,16 @@ static void process_free_event(void *data,
278 s_alloc->alloc_cpu = -1; 283 s_alloc->alloc_cpu = -1;
279} 284}
280 285
281static void process_raw_event(union perf_event *raw_event __used, void *data, 286static void process_raw_event(struct perf_tool *tool,
287 union perf_event *raw_event __used, void *data,
282 int cpu, u64 timestamp, struct thread *thread) 288 int cpu, u64 timestamp, struct thread *thread)
283{ 289{
290 struct perf_kmem *kmem = container_of(tool, struct perf_kmem, tool);
284 struct event_format *event; 291 struct event_format *event;
285 int type; 292 int type;
286 293
287 type = trace_parse_common_type(data); 294 type = trace_parse_common_type(kmem->session->pevent, data);
288 event = trace_find_event(type); 295 event = pevent_find_event(kmem->session->pevent, type);
289 296
290 if (!strcmp(event->name, "kmalloc") || 297 if (!strcmp(event->name, "kmalloc") ||
291 !strcmp(event->name, "kmem_cache_alloc")) { 298 !strcmp(event->name, "kmem_cache_alloc")) {
@@ -306,7 +313,7 @@ static void process_raw_event(union perf_event *raw_event __used, void *data,
306 } 313 }
307} 314}
308 315
309static int process_sample_event(struct perf_tool *tool __used, 316static int process_sample_event(struct perf_tool *tool,
310 union perf_event *event, 317 union perf_event *event,
311 struct perf_sample *sample, 318 struct perf_sample *sample,
312 struct perf_evsel *evsel __used, 319 struct perf_evsel *evsel __used,
@@ -322,16 +329,18 @@ static int process_sample_event(struct perf_tool *tool __used,
322 329
323 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); 330 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
324 331
325 process_raw_event(event, sample->raw_data, sample->cpu, 332 process_raw_event(tool, event, sample->raw_data, sample->cpu,
326 sample->time, thread); 333 sample->time, thread);
327 334
328 return 0; 335 return 0;
329} 336}
330 337
331static struct perf_tool perf_kmem = { 338static struct perf_kmem perf_kmem = {
332 .sample = process_sample_event, 339 .tool = {
333 .comm = perf_event__process_comm, 340 .sample = process_sample_event,
334 .ordered_samples = true, 341 .comm = perf_event__process_comm,
342 .ordered_samples = true,
343 },
335}; 344};
336 345
337static double fragmentation(unsigned long n_req, unsigned long n_alloc) 346static double fragmentation(unsigned long n_req, unsigned long n_alloc)
@@ -486,11 +495,15 @@ static void sort_result(void)
486static int __cmd_kmem(void) 495static int __cmd_kmem(void)
487{ 496{
488 int err = -EINVAL; 497 int err = -EINVAL;
489 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 498 struct perf_session *session;
490 0, false, &perf_kmem); 499
500 session = perf_session__new(input_name, O_RDONLY, 0, false,
501 &perf_kmem.tool);
491 if (session == NULL) 502 if (session == NULL)
492 return -ENOMEM; 503 return -ENOMEM;
493 504
505 perf_kmem.session = session;
506
494 if (perf_session__create_kernel_maps(session) < 0) 507 if (perf_session__create_kernel_maps(session) < 0)
495 goto out_delete; 508 goto out_delete;
496 509
@@ -498,7 +511,7 @@ static int __cmd_kmem(void)
498 goto out_delete; 511 goto out_delete;
499 512
500 setup_pager(); 513 setup_pager();
501 err = perf_session__process_events(session, &perf_kmem); 514 err = perf_session__process_events(session, &perf_kmem.tool);
502 if (err != 0) 515 if (err != 0)
503 goto out_delete; 516 goto out_delete;
504 sort_result(); 517 sort_result();
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index fd53319de20d..b3c428548868 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -724,8 +724,8 @@ process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread)
724 struct event_format *event; 724 struct event_format *event;
725 int type; 725 int type;
726 726
727 type = trace_parse_common_type(data); 727 type = trace_parse_common_type(session->pevent, data);
728 event = trace_find_event(type); 728 event = pevent_find_event(session->pevent, type);
729 729
730 if (!strcmp(event->name, "lock_acquire")) 730 if (!strcmp(event->name, "lock_acquire"))
731 process_lock_acquire_event(data, event, cpu, timestamp, thread); 731 process_lock_acquire_event(data, event, cpu, timestamp, thread);
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 9fe77b185338..7a9ad2b1ee76 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -43,6 +43,11 @@ static u64 sleep_measurement_overhead;
43 43
44static unsigned long nr_tasks; 44static unsigned long nr_tasks;
45 45
46struct perf_sched {
47 struct perf_tool tool;
48 struct perf_session *session;
49};
50
46struct sched_atom; 51struct sched_atom;
47 52
48struct task_desc { 53struct task_desc {
@@ -1597,6 +1602,8 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool,
1597 struct perf_evsel *evsel, 1602 struct perf_evsel *evsel,
1598 struct machine *machine) 1603 struct machine *machine)
1599{ 1604{
1605 struct perf_sched *sched = container_of(tool, struct perf_sched, tool);
1606 struct pevent *pevent = sched->session->pevent;
1600 struct thread *thread = machine__findnew_thread(machine, sample->pid); 1607 struct thread *thread = machine__findnew_thread(machine, sample->pid);
1601 1608
1602 if (thread == NULL) { 1609 if (thread == NULL) {
@@ -1612,7 +1619,8 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool,
1612 tracepoint_handler f = evsel->handler.func; 1619 tracepoint_handler f = evsel->handler.func;
1613 1620
1614 if (evsel->handler.data == NULL) 1621 if (evsel->handler.data == NULL)
1615 evsel->handler.data = trace_find_event(evsel->attr.config); 1622 evsel->handler.data = pevent_find_event(pevent,
1623 evsel->attr.config);
1616 1624
1617 f(tool, evsel->handler.data, sample, machine, thread); 1625 f(tool, evsel->handler.data, sample, machine, thread);
1618 } 1626 }
@@ -1620,12 +1628,14 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool,
1620 return 0; 1628 return 0;
1621} 1629}
1622 1630
1623static struct perf_tool perf_sched = { 1631static struct perf_sched perf_sched = {
1624 .sample = perf_sched__process_tracepoint_sample, 1632 .tool = {
1625 .comm = perf_event__process_comm, 1633 .sample = perf_sched__process_tracepoint_sample,
1626 .lost = perf_event__process_lost, 1634 .comm = perf_event__process_comm,
1627 .fork = perf_event__process_task, 1635 .lost = perf_event__process_lost,
1628 .ordered_samples = true, 1636 .fork = perf_event__process_task,
1637 .ordered_samples = true,
1638 },
1629}; 1639};
1630 1640
1631static void read_events(bool destroy, struct perf_session **psession) 1641static void read_events(bool destroy, struct perf_session **psession)
@@ -1640,16 +1650,20 @@ static void read_events(bool destroy, struct perf_session **psession)
1640 { "sched:sched_process_exit", process_sched_exit_event, }, 1650 { "sched:sched_process_exit", process_sched_exit_event, },
1641 { "sched:sched_migrate_task", process_sched_migrate_task_event, }, 1651 { "sched:sched_migrate_task", process_sched_migrate_task_event, },
1642 }; 1652 };
1643 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 1653 struct perf_session *session;
1644 0, false, &perf_sched); 1654
1655 session = perf_session__new(input_name, O_RDONLY, 0, false,
1656 &perf_sched.tool);
1645 if (session == NULL) 1657 if (session == NULL)
1646 die("No Memory"); 1658 die("No Memory");
1647 1659
1648 err = perf_evlist__set_tracepoints_handlers_array(session->evlist, handlers); 1660 perf_sched.session = session;
1661
1662 err = perf_session__set_tracepoints_handlers(session, handlers);
1649 assert(err == 0); 1663 assert(err == 0);
1650 1664
1651 if (perf_session__has_traces(session, "record -R")) { 1665 if (perf_session__has_traces(session, "record -R")) {
1652 err = perf_session__process_events(session, &perf_sched); 1666 err = perf_session__process_events(session, &perf_sched.tool);
1653 if (err) 1667 if (err)
1654 die("Failed to process events, error %d", err); 1668 die("Failed to process events, error %d", err);
1655 1669
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
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7400fb3fc50c..f74e9560350e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -224,8 +224,8 @@ out_free_attrs:
224 return err; 224 return err;
225} 225}
226 226
227static struct perf_evsel * 227struct perf_evsel *
228 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id) 228perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id)
229{ 229{
230 struct perf_evsel *evsel; 230 struct perf_evsel *evsel;
231 231
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 989bee9624c2..40d4d3cdced0 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -73,6 +73,9 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist,
73#define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ 73#define perf_evlist__set_tracepoints_handlers_array(evlist, array) \
74 perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) 74 perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
75 75
76struct perf_evsel *
77perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
78
76void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, 79void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
77 int cpu, int thread, u64 id); 80 int cpu, int thread, u64 id);
78 81
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index a5e2015319ee..5a47aba46759 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1474,15 +1474,15 @@ out:
1474 1474
1475static int process_tracing_data(struct perf_file_section *section __unused, 1475static int process_tracing_data(struct perf_file_section *section __unused,
1476 struct perf_header *ph __unused, 1476 struct perf_header *ph __unused,
1477 int feat __unused, int fd) 1477 int feat __unused, int fd, void *data)
1478{ 1478{
1479 trace_report(fd, false); 1479 trace_report(fd, data, false);
1480 return 0; 1480 return 0;
1481} 1481}
1482 1482
1483static int process_build_id(struct perf_file_section *section, 1483static int process_build_id(struct perf_file_section *section,
1484 struct perf_header *ph, 1484 struct perf_header *ph,
1485 int feat __unused, int fd) 1485 int feat __unused, int fd, void *data __used)
1486{ 1486{
1487 if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) 1487 if (perf_header__read_build_ids(ph, fd, section->offset, section->size))
1488 pr_debug("Failed to read buildids, continuing...\n"); 1488 pr_debug("Failed to read buildids, continuing...\n");
@@ -1493,7 +1493,7 @@ struct feature_ops {
1493 int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); 1493 int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
1494 void (*print)(struct perf_header *h, int fd, FILE *fp); 1494 void (*print)(struct perf_header *h, int fd, FILE *fp);
1495 int (*process)(struct perf_file_section *section, 1495 int (*process)(struct perf_file_section *section,
1496 struct perf_header *h, int feat, int fd); 1496 struct perf_header *h, int feat, int fd, void *data);
1497 const char *name; 1497 const char *name;
1498 bool full_only; 1498 bool full_only;
1499}; 1499};
@@ -1988,7 +1988,7 @@ int perf_file_header__read(struct perf_file_header *header,
1988 1988
1989static int perf_file_section__process(struct perf_file_section *section, 1989static int perf_file_section__process(struct perf_file_section *section,
1990 struct perf_header *ph, 1990 struct perf_header *ph,
1991 int feat, int fd, void *data __used) 1991 int feat, int fd, void *data)
1992{ 1992{
1993 if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { 1993 if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) {
1994 pr_debug("Failed to lseek to %" PRIu64 " offset for feature " 1994 pr_debug("Failed to lseek to %" PRIu64 " offset for feature "
@@ -2004,7 +2004,7 @@ static int perf_file_section__process(struct perf_file_section *section,
2004 if (!feat_ops[feat].process) 2004 if (!feat_ops[feat].process)
2005 return 0; 2005 return 0;
2006 2006
2007 return feat_ops[feat].process(section, ph, feat, fd); 2007 return feat_ops[feat].process(section, ph, feat, fd, data);
2008} 2008}
2009 2009
2010static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, 2010static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
@@ -2093,9 +2093,11 @@ static int read_attr(int fd, struct perf_header *ph,
2093 return ret <= 0 ? -1 : 0; 2093 return ret <= 0 ? -1 : 0;
2094} 2094}
2095 2095
2096static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel) 2096static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel,
2097 struct pevent *pevent)
2097{ 2098{
2098 struct event_format *event = trace_find_event(evsel->attr.config); 2099 struct event_format *event = pevent_find_event(pevent,
2100 evsel->attr.config);
2099 char bf[128]; 2101 char bf[128];
2100 2102
2101 if (event == NULL) 2103 if (event == NULL)
@@ -2109,13 +2111,14 @@ static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel)
2109 return 0; 2111 return 0;
2110} 2112}
2111 2113
2112static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist) 2114static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist,
2115 struct pevent *pevent)
2113{ 2116{
2114 struct perf_evsel *pos; 2117 struct perf_evsel *pos;
2115 2118
2116 list_for_each_entry(pos, &evlist->entries, node) { 2119 list_for_each_entry(pos, &evlist->entries, node) {
2117 if (pos->attr.type == PERF_TYPE_TRACEPOINT && 2120 if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
2118 perf_evsel__set_tracepoint_name(pos)) 2121 perf_evsel__set_tracepoint_name(pos, pevent))
2119 return -1; 2122 return -1;
2120 } 2123 }
2121 2124
@@ -2198,12 +2201,12 @@ int perf_session__read_header(struct perf_session *session, int fd)
2198 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); 2201 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type);
2199 } 2202 }
2200 2203
2201 perf_header__process_sections(header, fd, NULL, 2204 perf_header__process_sections(header, fd, &session->pevent,
2202 perf_file_section__process); 2205 perf_file_section__process);
2203 2206
2204 lseek(fd, header->data_offset, SEEK_SET); 2207 lseek(fd, header->data_offset, SEEK_SET);
2205 2208
2206 if (perf_evlist__set_tracepoint_names(session->evlist)) 2209 if (perf_evlist__set_tracepoint_names(session->evlist, session->pevent))
2207 goto out_delete_evlist; 2210 goto out_delete_evlist;
2208 2211
2209 header->frozen = 1; 2212 header->frozen = 1;
@@ -2419,8 +2422,8 @@ int perf_event__process_tracing_data(union perf_event *event,
2419 lseek(session->fd, offset + sizeof(struct tracing_data_event), 2422 lseek(session->fd, offset + sizeof(struct tracing_data_event),
2420 SEEK_SET); 2423 SEEK_SET);
2421 2424
2422 size_read = trace_report(session->fd, session->repipe); 2425 size_read = trace_report(session->fd, &session->pevent,
2423 2426 session->repipe);
2424 padding = ALIGN(size_read, sizeof(u64)) - size_read; 2427 padding = ALIGN(size_read, sizeof(u64)) - size_read;
2425 2428
2426 if (read(session->fd, buf, padding) < 0) 2429 if (read(session->fd, buf, padding) < 0)
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 4c1b3d72a1d2..b3620fe12763 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -233,7 +233,8 @@ static void define_event_symbols(struct event_format *event,
233 define_event_symbols(event, ev_name, args->next); 233 define_event_symbols(event, ev_name, args->next);
234} 234}
235 235
236static inline struct event_format *find_cache_event(int type) 236static inline
237struct event_format *find_cache_event(struct pevent *pevent, int type)
237{ 238{
238 static char ev_name[256]; 239 static char ev_name[256];
239 struct event_format *event; 240 struct event_format *event;
@@ -241,7 +242,7 @@ static inline struct event_format *find_cache_event(int type)
241 if (events[type]) 242 if (events[type])
242 return events[type]; 243 return events[type];
243 244
244 events[type] = event = trace_find_event(type); 245 events[type] = event = pevent_find_event(pevent, type);
245 if (!event) 246 if (!event)
246 return NULL; 247 return NULL;
247 248
@@ -252,7 +253,8 @@ static inline struct event_format *find_cache_event(int type)
252 return event; 253 return event;
253} 254}
254 255
255static void perl_process_tracepoint(union perf_event *pevent __unused, 256static void perl_process_tracepoint(union perf_event *perf_event __unused,
257 struct pevent *pevent,
256 struct perf_sample *sample, 258 struct perf_sample *sample,
257 struct perf_evsel *evsel, 259 struct perf_evsel *evsel,
258 struct machine *machine __unused, 260 struct machine *machine __unused,
@@ -275,13 +277,13 @@ static void perl_process_tracepoint(union perf_event *pevent __unused,
275 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) 277 if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
276 return; 278 return;
277 279
278 type = trace_parse_common_type(data); 280 type = trace_parse_common_type(pevent, data);
279 281
280 event = find_cache_event(type); 282 event = find_cache_event(pevent, type);
281 if (!event) 283 if (!event)
282 die("ug! no event found for type %d", type); 284 die("ug! no event found for type %d", type);
283 285
284 pid = trace_parse_common_pid(data); 286 pid = trace_parse_common_pid(pevent, data);
285 287
286 sprintf(handler, "%s::%s", event->system, event->name); 288 sprintf(handler, "%s::%s", event->system, event->name);
287 289
@@ -314,7 +316,8 @@ static void perl_process_tracepoint(union perf_event *pevent __unused,
314 offset = field->offset; 316 offset = field->offset;
315 XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0))); 317 XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0)));
316 } else { /* FIELD_IS_NUMERIC */ 318 } else { /* FIELD_IS_NUMERIC */
317 val = read_size(data + field->offset, field->size); 319 val = read_size(pevent, data + field->offset,
320 field->size);
318 if (field->flags & FIELD_IS_SIGNED) { 321 if (field->flags & FIELD_IS_SIGNED) {
319 XPUSHs(sv_2mortal(newSViv(val))); 322 XPUSHs(sv_2mortal(newSViv(val)));
320 } else { 323 } else {
@@ -368,14 +371,15 @@ static void perl_process_event_generic(union perf_event *pevent __unused,
368 LEAVE; 371 LEAVE;
369} 372}
370 373
371static void perl_process_event(union perf_event *pevent, 374static void perl_process_event(union perf_event *event,
375 struct pevent *pevent,
372 struct perf_sample *sample, 376 struct perf_sample *sample,
373 struct perf_evsel *evsel, 377 struct perf_evsel *evsel,
374 struct machine *machine, 378 struct machine *machine,
375 struct thread *thread) 379 struct thread *thread)
376{ 380{
377 perl_process_tracepoint(pevent, sample, evsel, machine, thread); 381 perl_process_tracepoint(event, pevent, sample, evsel, machine, thread);
378 perl_process_event_generic(pevent, sample, evsel, machine, thread); 382 perl_process_event_generic(event, sample, evsel, machine, thread);
379} 383}
380 384
381static void run_start_sub(void) 385static void run_start_sub(void)
@@ -448,7 +452,7 @@ static int perl_stop_script(void)
448 return 0; 452 return 0;
449} 453}
450 454
451static int perl_generate_script(const char *outfile) 455static int perl_generate_script(struct pevent *pevent, const char *outfile)
452{ 456{
453 struct event_format *event = NULL; 457 struct event_format *event = NULL;
454 struct format_field *f; 458 struct format_field *f;
@@ -495,7 +499,7 @@ static int perl_generate_script(const char *outfile)
495 fprintf(ofp, "sub trace_begin\n{\n\t# optional\n}\n\n"); 499 fprintf(ofp, "sub trace_begin\n{\n\t# optional\n}\n\n");
496 fprintf(ofp, "sub trace_end\n{\n\t# optional\n}\n\n"); 500 fprintf(ofp, "sub trace_end\n{\n\t# optional\n}\n\n");
497 501
498 while ((event = trace_find_next_event(event))) { 502 while ((event = trace_find_next_event(pevent, event))) {
499 fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name); 503 fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name);
500 fprintf(ofp, "\tmy ("); 504 fprintf(ofp, "\tmy (");
501 505
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index acb9795286c4..a8ca2f8179a9 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -190,7 +190,8 @@ static void define_event_symbols(struct event_format *event,
190 define_event_symbols(event, ev_name, args->next); 190 define_event_symbols(event, ev_name, args->next);
191} 191}
192 192
193static inline struct event_format *find_cache_event(int type) 193static inline
194struct event_format *find_cache_event(struct pevent *pevent, int type)
194{ 195{
195 static char ev_name[256]; 196 static char ev_name[256];
196 struct event_format *event; 197 struct event_format *event;
@@ -198,7 +199,7 @@ static inline struct event_format *find_cache_event(int type)
198 if (events[type]) 199 if (events[type])
199 return events[type]; 200 return events[type];
200 201
201 events[type] = event = trace_find_event(type); 202 events[type] = event = pevent_find_event(pevent, type);
202 if (!event) 203 if (!event)
203 return NULL; 204 return NULL;
204 205
@@ -209,7 +210,8 @@ static inline struct event_format *find_cache_event(int type)
209 return event; 210 return event;
210} 211}
211 212
212static void python_process_event(union perf_event *pevent __unused, 213static void python_process_event(union perf_event *perf_event __unused,
214 struct pevent *pevent,
213 struct perf_sample *sample, 215 struct perf_sample *sample,
214 struct perf_evsel *evsel __unused, 216 struct perf_evsel *evsel __unused,
215 struct machine *machine __unused, 217 struct machine *machine __unused,
@@ -233,13 +235,13 @@ static void python_process_event(union perf_event *pevent __unused,
233 if (!t) 235 if (!t)
234 Py_FatalError("couldn't create Python tuple"); 236 Py_FatalError("couldn't create Python tuple");
235 237
236 type = trace_parse_common_type(data); 238 type = trace_parse_common_type(pevent, data);
237 239
238 event = find_cache_event(type); 240 event = find_cache_event(pevent, type);
239 if (!event) 241 if (!event)
240 die("ug! no event found for type %d", type); 242 die("ug! no event found for type %d", type);
241 243
242 pid = trace_parse_common_pid(data); 244 pid = trace_parse_common_pid(pevent, data);
243 245
244 sprintf(handler_name, "%s__%s", event->system, event->name); 246 sprintf(handler_name, "%s__%s", event->system, event->name);
245 247
@@ -284,7 +286,8 @@ static void python_process_event(union perf_event *pevent __unused,
284 offset = field->offset; 286 offset = field->offset;
285 obj = PyString_FromString((char *)data + offset); 287 obj = PyString_FromString((char *)data + offset);
286 } else { /* FIELD_IS_NUMERIC */ 288 } else { /* FIELD_IS_NUMERIC */
287 val = read_size(data + field->offset, field->size); 289 val = read_size(pevent, data + field->offset,
290 field->size);
288 if (field->flags & FIELD_IS_SIGNED) { 291 if (field->flags & FIELD_IS_SIGNED) {
289 if ((long long)val >= LONG_MIN && 292 if ((long long)val >= LONG_MIN &&
290 (long long)val <= LONG_MAX) 293 (long long)val <= LONG_MAX)
@@ -438,7 +441,7 @@ out:
438 return err; 441 return err;
439} 442}
440 443
441static int python_generate_script(const char *outfile) 444static int python_generate_script(struct pevent *pevent, const char *outfile)
442{ 445{
443 struct event_format *event = NULL; 446 struct event_format *event = NULL;
444 struct format_field *f; 447 struct format_field *f;
@@ -487,7 +490,7 @@ static int python_generate_script(const char *outfile)
487 fprintf(ofp, "def trace_end():\n"); 490 fprintf(ofp, "def trace_end():\n");
488 fprintf(ofp, "\tprint \"in trace_end\"\n\n"); 491 fprintf(ofp, "\tprint \"in trace_end\"\n\n");
489 492
490 while ((event = trace_find_next_event(event))) { 493 while ((event = trace_find_next_event(pevent, event))) {
491 fprintf(ofp, "def %s__%s(", event->system, event->name); 494 fprintf(ofp, "def %s__%s(", event->system, event->name);
492 fprintf(ofp, "event_name, "); 495 fprintf(ofp, "event_name, ");
493 fprintf(ofp, "context, "); 496 fprintf(ofp, "context, ");
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6b305fbcc986..f5baff1495e6 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -14,6 +14,7 @@
14#include "sort.h" 14#include "sort.h"
15#include "util.h" 15#include "util.h"
16#include "cpumap.h" 16#include "cpumap.h"
17#include "event-parse.h"
17 18
18static int perf_session__open(struct perf_session *self, bool force) 19static int perf_session__open(struct perf_session *self, bool force)
19{ 20{
@@ -1610,3 +1611,58 @@ void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
1610 perf_header__fprintf_info(session, fp, full); 1611 perf_header__fprintf_info(session, fp, full);
1611 fprintf(fp, "# ========\n#\n"); 1612 fprintf(fp, "# ========\n#\n");
1612} 1613}
1614
1615
1616int __perf_session__set_tracepoints_handlers(struct perf_session *session,
1617 const struct perf_evsel_str_handler *assocs,
1618 size_t nr_assocs)
1619{
1620 struct perf_evlist *evlist = session->evlist;
1621 struct event_format *format;
1622 struct perf_evsel *evsel;
1623 char *tracepoint, *name;
1624 size_t i;
1625 int err;
1626
1627 for (i = 0; i < nr_assocs; i++) {
1628 err = -ENOMEM;
1629 tracepoint = strdup(assocs[i].name);
1630 if (tracepoint == NULL)
1631 goto out;
1632
1633 err = -ENOENT;
1634 name = strchr(tracepoint, ':');
1635 if (name == NULL)
1636 goto out_free;
1637
1638 *name++ = '\0';
1639 format = pevent_find_event_by_name(session->pevent,
1640 tracepoint, name);
1641 if (format == NULL) {
1642 /*
1643 * Adding a handler for an event not in the session,
1644 * just ignore it.
1645 */
1646 goto next;
1647 }
1648
1649 evsel = perf_evlist__find_tracepoint_by_id(evlist, format->id);
1650 if (evsel == NULL)
1651 goto next;
1652
1653 err = -EEXIST;
1654 if (evsel->handler.func != NULL)
1655 goto out_free;
1656 evsel->handler.func = assocs[i].handler;
1657next:
1658 free(tracepoint);
1659 }
1660
1661 err = 0;
1662out:
1663 return err;
1664
1665out_free:
1666 free(tracepoint);
1667 goto out;
1668}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index c71a1a7b05ed..7c435bde6eb0 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -33,6 +33,7 @@ struct perf_session {
33 struct machine host_machine; 33 struct machine host_machine;
34 struct rb_root machines; 34 struct rb_root machines;
35 struct perf_evlist *evlist; 35 struct perf_evlist *evlist;
36 struct pevent *pevent;
36 /* 37 /*
37 * FIXME: Need to split this up further, we need global 38 * FIXME: Need to split this up further, we need global
38 * stats + per event stats. 'perf diff' also needs 39 * stats + per event stats. 'perf diff' also needs
@@ -158,4 +159,13 @@ int perf_session__cpu_bitmap(struct perf_session *session,
158 const char *cpu_list, unsigned long *cpu_bitmap); 159 const char *cpu_list, unsigned long *cpu_bitmap);
159 160
160void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full); 161void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
162
163struct perf_evsel_str_handler;
164
165int __perf_session__set_tracepoints_handlers(struct perf_session *session,
166 const struct perf_evsel_str_handler *assocs,
167 size_t nr_assocs);
168
169#define perf_session__set_tracepoints_handlers(session, array) \
170 __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array))
161#endif /* __PERF_SESSION_H */ 171#endif /* __PERF_SESSION_H */
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index df2fddbf0cd2..a51bd86f4d09 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -32,29 +32,25 @@ int header_page_size_size;
32int header_page_ts_size; 32int header_page_ts_size;
33int header_page_data_offset; 33int header_page_data_offset;
34 34
35struct pevent *perf_pevent;
36static struct pevent *pevent;
37
38bool latency_format; 35bool latency_format;
39 36
40int read_trace_init(int file_bigendian, int host_bigendian) 37struct pevent *read_trace_init(int file_bigendian, int host_bigendian)
41{ 38{
42 if (pevent) 39 struct pevent *pevent = pevent_alloc();
43 return 0;
44
45 perf_pevent = pevent_alloc();
46 pevent = perf_pevent;
47 40
48 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); 41 if (pevent != NULL) {
49 pevent_set_file_bigendian(pevent, file_bigendian); 42 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
50 pevent_set_host_bigendian(pevent, host_bigendian); 43 pevent_set_file_bigendian(pevent, file_bigendian);
44 pevent_set_host_bigendian(pevent, host_bigendian);
45 }
51 46
52 return 0; 47 return pevent;
53} 48}
54 49
55static int get_common_field(struct scripting_context *context, 50static int get_common_field(struct scripting_context *context,
56 int *offset, int *size, const char *type) 51 int *offset, int *size, const char *type)
57{ 52{
53 struct pevent *pevent = context->pevent;
58 struct event_format *event; 54 struct event_format *event;
59 struct format_field *field; 55 struct format_field *field;
60 56
@@ -150,7 +146,7 @@ void *raw_field_ptr(struct event_format *event, const char *name, void *data)
150 return data + field->offset; 146 return data + field->offset;
151} 147}
152 148
153int trace_parse_common_type(void *data) 149int trace_parse_common_type(struct pevent *pevent, void *data)
154{ 150{
155 struct pevent_record record; 151 struct pevent_record record;
156 152
@@ -158,7 +154,7 @@ int trace_parse_common_type(void *data)
158 return pevent_data_type(pevent, &record); 154 return pevent_data_type(pevent, &record);
159} 155}
160 156
161int trace_parse_common_pid(void *data) 157int trace_parse_common_pid(struct pevent *pevent, void *data)
162{ 158{
163 struct pevent_record record; 159 struct pevent_record record;
164 160
@@ -166,27 +162,21 @@ int trace_parse_common_pid(void *data)
166 return pevent_data_pid(pevent, &record); 162 return pevent_data_pid(pevent, &record);
167} 163}
168 164
169unsigned long long read_size(void *ptr, int size) 165unsigned long long read_size(struct pevent *pevent, void *ptr, int size)
170{ 166{
171 return pevent_read_number(pevent, ptr, size); 167 return pevent_read_number(pevent, ptr, size);
172} 168}
173 169
174struct event_format *trace_find_event(int type) 170void print_trace_event(struct pevent *pevent, int cpu, void *data, int size)
175{
176 return pevent_find_event(pevent, type);
177}
178
179
180void print_trace_event(int cpu, void *data, int size)
181{ 171{
182 struct event_format *event; 172 struct event_format *event;
183 struct pevent_record record; 173 struct pevent_record record;
184 struct trace_seq s; 174 struct trace_seq s;
185 int type; 175 int type;
186 176
187 type = trace_parse_common_type(data); 177 type = trace_parse_common_type(pevent, data);
188 178
189 event = trace_find_event(type); 179 event = pevent_find_event(pevent, type);
190 if (!event) { 180 if (!event) {
191 warning("ug! no event found for type %d", type); 181 warning("ug! no event found for type %d", type);
192 return; 182 return;
@@ -203,8 +193,8 @@ void print_trace_event(int cpu, void *data, int size)
203 printf("\n"); 193 printf("\n");
204} 194}
205 195
206void print_event(int cpu, void *data, int size, unsigned long long nsecs, 196void print_event(struct pevent *pevent, int cpu, void *data, int size,
207 char *comm) 197 unsigned long long nsecs, char *comm)
208{ 198{
209 struct pevent_record record; 199 struct pevent_record record;
210 struct trace_seq s; 200 struct trace_seq s;
@@ -227,7 +217,8 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs,
227 printf("\n"); 217 printf("\n");
228} 218}
229 219
230void parse_proc_kallsyms(char *file, unsigned int size __unused) 220void parse_proc_kallsyms(struct pevent *pevent,
221 char *file, unsigned int size __unused)
231{ 222{
232 unsigned long long addr; 223 unsigned long long addr;
233 char *func; 224 char *func;
@@ -258,7 +249,8 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused)
258 } 249 }
259} 250}
260 251
261void parse_ftrace_printk(char *file, unsigned int size __unused) 252void parse_ftrace_printk(struct pevent *pevent,
253 char *file, unsigned int size __unused)
262{ 254{
263 unsigned long long addr; 255 unsigned long long addr;
264 char *printk; 256 char *printk;
@@ -282,17 +274,19 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)
282 } 274 }
283} 275}
284 276
285int parse_ftrace_file(char *buf, unsigned long size) 277int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size)
286{ 278{
287 return pevent_parse_event(pevent, buf, size, "ftrace"); 279 return pevent_parse_event(pevent, buf, size, "ftrace");
288} 280}
289 281
290int parse_event_file(char *buf, unsigned long size, char *sys) 282int parse_event_file(struct pevent *pevent,
283 char *buf, unsigned long size, char *sys)
291{ 284{
292 return pevent_parse_event(pevent, buf, size, sys); 285 return pevent_parse_event(pevent, buf, size, sys);
293} 286}
294 287
295struct event_format *trace_find_next_event(struct event_format *event) 288struct event_format *trace_find_next_event(struct pevent *pevent,
289 struct event_format *event)
296{ 290{
297 static int idx; 291 static int idx;
298 292
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index f097e0dd6c5c..719ed74a8565 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -114,20 +114,20 @@ static void skip(int size)
114 }; 114 };
115} 115}
116 116
117static unsigned int read4(void) 117static unsigned int read4(struct pevent *pevent)
118{ 118{
119 unsigned int data; 119 unsigned int data;
120 120
121 read_or_die(&data, 4); 121 read_or_die(&data, 4);
122 return __data2host4(perf_pevent, data); 122 return __data2host4(pevent, data);
123} 123}
124 124
125static unsigned long long read8(void) 125static unsigned long long read8(struct pevent *pevent)
126{ 126{
127 unsigned long long data; 127 unsigned long long data;
128 128
129 read_or_die(&data, 8); 129 read_or_die(&data, 8);
130 return __data2host8(perf_pevent, data); 130 return __data2host8(pevent, data);
131} 131}
132 132
133static char *read_string(void) 133static char *read_string(void)
@@ -168,12 +168,12 @@ static char *read_string(void)
168 return str; 168 return str;
169} 169}
170 170
171static void read_proc_kallsyms(void) 171static void read_proc_kallsyms(struct pevent *pevent)
172{ 172{
173 unsigned int size; 173 unsigned int size;
174 char *buf; 174 char *buf;
175 175
176 size = read4(); 176 size = read4(pevent);
177 if (!size) 177 if (!size)
178 return; 178 return;
179 179
@@ -181,29 +181,29 @@ static void read_proc_kallsyms(void)
181 read_or_die(buf, size); 181 read_or_die(buf, size);
182 buf[size] = '\0'; 182 buf[size] = '\0';
183 183
184 parse_proc_kallsyms(buf, size); 184 parse_proc_kallsyms(pevent, buf, size);
185 185
186 free(buf); 186 free(buf);
187} 187}
188 188
189static void read_ftrace_printk(void) 189static void read_ftrace_printk(struct pevent *pevent)
190{ 190{
191 unsigned int size; 191 unsigned int size;
192 char *buf; 192 char *buf;
193 193
194 size = read4(); 194 size = read4(pevent);
195 if (!size) 195 if (!size)
196 return; 196 return;
197 197
198 buf = malloc_or_die(size); 198 buf = malloc_or_die(size);
199 read_or_die(buf, size); 199 read_or_die(buf, size);
200 200
201 parse_ftrace_printk(buf, size); 201 parse_ftrace_printk(pevent, buf, size);
202 202
203 free(buf); 203 free(buf);
204} 204}
205 205
206static void read_header_files(void) 206static void read_header_files(struct pevent *pevent)
207{ 207{
208 unsigned long long size; 208 unsigned long long size;
209 char *header_event; 209 char *header_event;
@@ -214,7 +214,7 @@ static void read_header_files(void)
214 if (memcmp(buf, "header_page", 12) != 0) 214 if (memcmp(buf, "header_page", 12) != 0)
215 die("did not read header page"); 215 die("did not read header page");
216 216
217 size = read8(); 217 size = read8(pevent);
218 skip(size); 218 skip(size);
219 219
220 /* 220 /*
@@ -227,47 +227,48 @@ static void read_header_files(void)
227 if (memcmp(buf, "header_event", 13) != 0) 227 if (memcmp(buf, "header_event", 13) != 0)
228 die("did not read header event"); 228 die("did not read header event");
229 229
230 size = read8(); 230 size = read8(pevent);
231 header_event = malloc_or_die(size); 231 header_event = malloc_or_die(size);
232 read_or_die(header_event, size); 232 read_or_die(header_event, size);
233 free(header_event); 233 free(header_event);
234} 234}
235 235
236static void read_ftrace_file(unsigned long long size) 236static void read_ftrace_file(struct pevent *pevent, unsigned long long size)
237{ 237{
238 char *buf; 238 char *buf;
239 239
240 buf = malloc_or_die(size); 240 buf = malloc_or_die(size);
241 read_or_die(buf, size); 241 read_or_die(buf, size);
242 parse_ftrace_file(buf, size); 242 parse_ftrace_file(pevent, buf, size);
243 free(buf); 243 free(buf);
244} 244}
245 245
246static void read_event_file(char *sys, unsigned long long size) 246static void read_event_file(struct pevent *pevent, char *sys,
247 unsigned long long size)
247{ 248{
248 char *buf; 249 char *buf;
249 250
250 buf = malloc_or_die(size); 251 buf = malloc_or_die(size);
251 read_or_die(buf, size); 252 read_or_die(buf, size);
252 parse_event_file(buf, size, sys); 253 parse_event_file(pevent, buf, size, sys);
253 free(buf); 254 free(buf);
254} 255}
255 256
256static void read_ftrace_files(void) 257static void read_ftrace_files(struct pevent *pevent)
257{ 258{
258 unsigned long long size; 259 unsigned long long size;
259 int count; 260 int count;
260 int i; 261 int i;
261 262
262 count = read4(); 263 count = read4(pevent);
263 264
264 for (i = 0; i < count; i++) { 265 for (i = 0; i < count; i++) {
265 size = read8(); 266 size = read8(pevent);
266 read_ftrace_file(size); 267 read_ftrace_file(pevent, size);
267 } 268 }
268} 269}
269 270
270static void read_event_files(void) 271static void read_event_files(struct pevent *pevent)
271{ 272{
272 unsigned long long size; 273 unsigned long long size;
273 char *sys; 274 char *sys;
@@ -275,15 +276,15 @@ static void read_event_files(void)
275 int count; 276 int count;
276 int i,x; 277 int i,x;
277 278
278 systems = read4(); 279 systems = read4(pevent);
279 280
280 for (i = 0; i < systems; i++) { 281 for (i = 0; i < systems; i++) {
281 sys = read_string(); 282 sys = read_string();
282 283
283 count = read4(); 284 count = read4(pevent);
284 for (x=0; x < count; x++) { 285 for (x=0; x < count; x++) {
285 size = read8(); 286 size = read8(pevent);
286 read_event_file(sys, size); 287 read_event_file(pevent, sys, size);
287 } 288 }
288 } 289 }
289} 290}
@@ -377,7 +378,7 @@ static int calc_index(void *ptr, int cpu)
377 return (unsigned long)ptr - (unsigned long)cpu_data[cpu].page; 378 return (unsigned long)ptr - (unsigned long)cpu_data[cpu].page;
378} 379}
379 380
380struct pevent_record *trace_peek_data(int cpu) 381struct pevent_record *trace_peek_data(struct pevent *pevent, int cpu)
381{ 382{
382 struct pevent_record *data; 383 struct pevent_record *data;
383 void *page = cpu_data[cpu].page; 384 void *page = cpu_data[cpu].page;
@@ -399,15 +400,15 @@ struct pevent_record *trace_peek_data(int cpu)
399 /* FIXME: handle header page */ 400 /* FIXME: handle header page */
400 if (header_page_ts_size != 8) 401 if (header_page_ts_size != 8)
401 die("expected a long long type for timestamp"); 402 die("expected a long long type for timestamp");
402 cpu_data[cpu].timestamp = data2host8(perf_pevent, ptr); 403 cpu_data[cpu].timestamp = data2host8(pevent, ptr);
403 ptr += 8; 404 ptr += 8;
404 switch (header_page_size_size) { 405 switch (header_page_size_size) {
405 case 4: 406 case 4:
406 cpu_data[cpu].page_size = data2host4(perf_pevent, ptr); 407 cpu_data[cpu].page_size = data2host4(pevent, ptr);
407 ptr += 4; 408 ptr += 4;
408 break; 409 break;
409 case 8: 410 case 8:
410 cpu_data[cpu].page_size = data2host8(perf_pevent, ptr); 411 cpu_data[cpu].page_size = data2host8(pevent, ptr);
411 ptr += 8; 412 ptr += 8;
412 break; 413 break;
413 default: 414 default:
@@ -421,10 +422,10 @@ read_again:
421 422
422 if (idx >= cpu_data[cpu].page_size) { 423 if (idx >= cpu_data[cpu].page_size) {
423 get_next_page(cpu); 424 get_next_page(cpu);
424 return trace_peek_data(cpu); 425 return trace_peek_data(pevent, cpu);
425 } 426 }
426 427
427 type_len_ts = data2host4(perf_pevent, ptr); 428 type_len_ts = data2host4(pevent, ptr);
428 ptr += 4; 429 ptr += 4;
429 430
430 type_len = type_len4host(type_len_ts); 431 type_len = type_len4host(type_len_ts);
@@ -434,14 +435,14 @@ read_again:
434 case RINGBUF_TYPE_PADDING: 435 case RINGBUF_TYPE_PADDING:
435 if (!delta) 436 if (!delta)
436 die("error, hit unexpected end of page"); 437 die("error, hit unexpected end of page");
437 length = data2host4(perf_pevent, ptr); 438 length = data2host4(pevent, ptr);
438 ptr += 4; 439 ptr += 4;
439 length *= 4; 440 length *= 4;
440 ptr += length; 441 ptr += length;
441 goto read_again; 442 goto read_again;
442 443
443 case RINGBUF_TYPE_TIME_EXTEND: 444 case RINGBUF_TYPE_TIME_EXTEND:
444 extend = data2host4(perf_pevent, ptr); 445 extend = data2host4(pevent, ptr);
445 ptr += 4; 446 ptr += 4;
446 extend <<= TS_SHIFT; 447 extend <<= TS_SHIFT;
447 extend += delta; 448 extend += delta;
@@ -452,7 +453,7 @@ read_again:
452 ptr += 12; 453 ptr += 12;
453 break; 454 break;
454 case 0: 455 case 0:
455 length = data2host4(perf_pevent, ptr); 456 length = data2host4(pevent, ptr);
456 ptr += 4; 457 ptr += 4;
457 die("here! length=%d", length); 458 die("here! length=%d", length);
458 break; 459 break;
@@ -477,17 +478,17 @@ read_again:
477 return data; 478 return data;
478} 479}
479 480
480struct pevent_record *trace_read_data(int cpu) 481struct pevent_record *trace_read_data(struct pevent *pevent, int cpu)
481{ 482{
482 struct pevent_record *data; 483 struct pevent_record *data;
483 484
484 data = trace_peek_data(cpu); 485 data = trace_peek_data(pevent, cpu);
485 cpu_data[cpu].next = NULL; 486 cpu_data[cpu].next = NULL;
486 487
487 return data; 488 return data;
488} 489}
489 490
490ssize_t trace_report(int fd, bool __repipe) 491ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
491{ 492{
492 char buf[BUFSIZ]; 493 char buf[BUFSIZ];
493 char test[] = { 23, 8, 68 }; 494 char test[] = { 23, 8, 68 };
@@ -519,30 +520,32 @@ ssize_t trace_report(int fd, bool __repipe)
519 file_bigendian = buf[0]; 520 file_bigendian = buf[0];
520 host_bigendian = bigendian(); 521 host_bigendian = bigendian();
521 522
522 read_trace_init(file_bigendian, host_bigendian); 523 *ppevent = read_trace_init(file_bigendian, host_bigendian);
524 if (*ppevent == NULL)
525 die("read_trace_init failed");
523 526
524 read_or_die(buf, 1); 527 read_or_die(buf, 1);
525 long_size = buf[0]; 528 long_size = buf[0];
526 529
527 page_size = read4(); 530 page_size = read4(*ppevent);
528 531
529 read_header_files(); 532 read_header_files(*ppevent);
530 533
531 read_ftrace_files(); 534 read_ftrace_files(*ppevent);
532 read_event_files(); 535 read_event_files(*ppevent);
533 read_proc_kallsyms(); 536 read_proc_kallsyms(*ppevent);
534 read_ftrace_printk(); 537 read_ftrace_printk(*ppevent);
535 538
536 size = calc_data_size - 1; 539 size = calc_data_size - 1;
537 calc_data_size = 0; 540 calc_data_size = 0;
538 repipe = false; 541 repipe = false;
539 542
540 if (show_funcs) { 543 if (show_funcs) {
541 pevent_print_funcs(perf_pevent); 544 pevent_print_funcs(*ppevent);
542 return size; 545 return size;
543 } 546 }
544 if (show_printk) { 547 if (show_printk) {
545 pevent_print_printk(perf_pevent); 548 pevent_print_printk(*ppevent);
546 return size; 549 return size;
547 } 550 }
548 551
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 18ae6c1831d3..474aa7a7df43 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -36,6 +36,7 @@ static int stop_script_unsupported(void)
36} 36}
37 37
38static void process_event_unsupported(union perf_event *event __unused, 38static void process_event_unsupported(union perf_event *event __unused,
39 struct pevent *pevent __unused,
39 struct perf_sample *sample __unused, 40 struct perf_sample *sample __unused,
40 struct perf_evsel *evsel __unused, 41 struct perf_evsel *evsel __unused,
41 struct machine *machine __unused, 42 struct machine *machine __unused,
@@ -61,7 +62,8 @@ static int python_start_script_unsupported(const char *script __unused,
61 return -1; 62 return -1;
62} 63}
63 64
64static int python_generate_script_unsupported(const char *outfile __unused) 65static int python_generate_script_unsupported(struct pevent *pevent __unused,
66 const char *outfile __unused)
65{ 67{
66 print_python_unsupported_msg(); 68 print_python_unsupported_msg();
67 69
@@ -122,7 +124,8 @@ static int perl_start_script_unsupported(const char *script __unused,
122 return -1; 124 return -1;
123} 125}
124 126
125static int perl_generate_script_unsupported(const char *outfile __unused) 127static int perl_generate_script_unsupported(struct pevent *pevent __unused,
128 const char *outfile __unused)
126{ 129{
127 print_perl_unsupported_msg(); 130 print_perl_unsupported_msg();
128 131
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 639852ac1117..8fef1d6687b7 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -8,6 +8,7 @@
8struct machine; 8struct machine;
9struct perf_sample; 9struct perf_sample;
10union perf_event; 10union perf_event;
11struct perf_tool;
11struct thread; 12struct thread;
12 13
13extern int header_page_size_size; 14extern int header_page_size_size;
@@ -29,35 +30,36 @@ enum {
29 30
30int bigendian(void); 31int bigendian(void);
31 32
32int read_trace_init(int file_bigendian, int host_bigendian); 33struct pevent *read_trace_init(int file_bigendian, int host_bigendian);
33void print_trace_event(int cpu, void *data, int size); 34void print_trace_event(struct pevent *pevent, int cpu, void *data, int size);
34 35
35void print_event(int cpu, void *data, int size, unsigned long long nsecs, 36void print_event(struct pevent *pevent, int cpu, void *data, int size,
36 char *comm); 37 unsigned long long nsecs, char *comm);
37 38
38int parse_ftrace_file(char *buf, unsigned long size); 39int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size);
39int parse_event_file(char *buf, unsigned long size, char *sys); 40int parse_event_file(struct pevent *pevent,
41 char *buf, unsigned long size, char *sys);
40 42
41struct pevent_record *trace_peek_data(int cpu); 43struct pevent_record *trace_peek_data(struct pevent *pevent, int cpu);
42struct event_format *trace_find_event(int type);
43 44
44unsigned long long 45unsigned long long
45raw_field_value(struct event_format *event, const char *name, void *data); 46raw_field_value(struct event_format *event, const char *name, void *data);
46void *raw_field_ptr(struct event_format *event, const char *name, void *data); 47void *raw_field_ptr(struct event_format *event, const char *name, void *data);
47 48
48void parse_proc_kallsyms(char *file, unsigned int size __unused); 49void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size);
49void parse_ftrace_printk(char *file, unsigned int size __unused); 50void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size);
50 51
51ssize_t trace_report(int fd, bool repipe); 52ssize_t trace_report(int fd, struct pevent **pevent, bool repipe);
52 53
53int trace_parse_common_type(void *data); 54int trace_parse_common_type(struct pevent *pevent, void *data);
54int trace_parse_common_pid(void *data); 55int trace_parse_common_pid(struct pevent *pevent, void *data);
55 56
56struct event_format *trace_find_next_event(struct event_format *event); 57struct event_format *trace_find_next_event(struct pevent *pevent,
57unsigned long long read_size(void *ptr, int size); 58 struct event_format *event);
59unsigned long long read_size(struct pevent *pevent, void *ptr, int size);
58unsigned long long eval_flag(const char *flag); 60unsigned long long eval_flag(const char *flag);
59 61
60struct pevent_record *trace_read_data(int cpu); 62struct pevent_record *trace_read_data(struct pevent *pevent, int cpu);
61int read_tracing_data(int fd, struct list_head *pattrs); 63int read_tracing_data(int fd, struct list_head *pattrs);
62 64
63struct tracing_data { 65struct tracing_data {
@@ -77,11 +79,12 @@ struct scripting_ops {
77 int (*start_script) (const char *script, int argc, const char **argv); 79 int (*start_script) (const char *script, int argc, const char **argv);
78 int (*stop_script) (void); 80 int (*stop_script) (void);
79 void (*process_event) (union perf_event *event, 81 void (*process_event) (union perf_event *event,
82 struct pevent *pevent,
80 struct perf_sample *sample, 83 struct perf_sample *sample,
81 struct perf_evsel *evsel, 84 struct perf_evsel *evsel,
82 struct machine *machine, 85 struct machine *machine,
83 struct thread *thread); 86 struct thread *thread);
84 int (*generate_script) (const char *outfile); 87 int (*generate_script) (struct pevent *pevent, const char *outfile);
85}; 88};
86 89
87int script_spec_register(const char *spec, struct scripting_ops *ops); 90int script_spec_register(const char *spec, struct scripting_ops *ops);
@@ -90,6 +93,7 @@ void setup_perl_scripting(void);
90void setup_python_scripting(void); 93void setup_python_scripting(void);
91 94
92struct scripting_context { 95struct scripting_context {
96 struct pevent *pevent;
93 void *event_data; 97 void *event_data;
94}; 98};
95 99