diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 08:58:03 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 22:43:37 -0400 |
| commit | fcf65bf149afa91b875ffde4455967cb63ee0be9 (patch) | |
| tree | 9b6137e60d4142b1aa00f9e20860bdd8374035d3 /tools | |
| parent | 8b6ee4c5d48d93527dcf6e36c51cbb7703d7fffb (diff) | |
perf evsel: Cache associated event_format
We already lookup the associated event_format when reading the perf.data
header, so that we can cache the tracepoint name in evsel->name, so do
it a little further and save the event_format itself, so that we can
avoid relookups in tools that need to access it.
Change the tools to take the most obvious advantage, when they were
using pevent_find_event directly. More work is needed for further
removing the need of a pointer to pevent, such as when asking for event
field values ("common_pid" and the other common fields and per
event_format fields).
This is something that was planned but only got actually done when
Andrey Wagin needed to do this lookup at perf_tool->sample() time, when
we don't have access to pevent (session->pevent) to use with
pevent_find_event().
Cc: Andrey Wagin <avagin@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/n/tip-txkvew2ckko0b594ae8fbnyk@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/builtin-kmem.c | 39 | ||||
| -rw-r--r-- | tools/perf/builtin-lock.c | 15 | ||||
| -rw-r--r-- | tools/perf/builtin-sched.c | 37 | ||||
| -rw-r--r-- | tools/perf/builtin-script.c | 29 | ||||
| -rw-r--r-- | tools/perf/util/evsel.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/header.c | 1 | ||||
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-perl.c | 13 | ||||
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 21 | ||||
| -rw-r--r-- | tools/perf/util/trace-event-parse.c | 26 | ||||
| -rw-r--r-- | tools/perf/util/trace-event.h | 2 |
10 files changed, 70 insertions, 114 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index ce35015f2dc..ffb93f42495 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include "builtin.h" | 1 | #include "builtin.h" |
| 2 | #include "perf.h" | 2 | #include "perf.h" |
| 3 | 3 | ||
| 4 | #include "util/evsel.h" | ||
| 4 | #include "util/util.h" | 5 | #include "util/util.h" |
| 5 | #include "util/cache.h" | 6 | #include "util/cache.h" |
| 6 | #include "util/symbol.h" | 7 | #include "util/symbol.h" |
| @@ -57,11 +58,6 @@ static unsigned long nr_allocs, nr_cross_allocs; | |||
| 57 | 58 | ||
| 58 | #define PATH_SYS_NODE "/sys/devices/system/node" | 59 | #define PATH_SYS_NODE "/sys/devices/system/node" |
| 59 | 60 | ||
| 60 | struct perf_kmem { | ||
| 61 | struct perf_tool tool; | ||
| 62 | struct perf_session *session; | ||
| 63 | }; | ||
| 64 | |||
| 65 | static void init_cpunode_map(void) | 61 | static void init_cpunode_map(void) |
| 66 | { | 62 | { |
| 67 | FILE *fp; | 63 | FILE *fp; |
| @@ -283,16 +279,10 @@ static void process_free_event(void *data, | |||
| 283 | s_alloc->alloc_cpu = -1; | 279 | s_alloc->alloc_cpu = -1; |
| 284 | } | 280 | } |
| 285 | 281 | ||
| 286 | static void process_raw_event(struct perf_tool *tool, | 282 | static void process_raw_event(struct perf_evsel *evsel, void *data, |
| 287 | union perf_event *raw_event __used, void *data, | ||
| 288 | int cpu, u64 timestamp, struct thread *thread) | 283 | int cpu, u64 timestamp, struct thread *thread) |
| 289 | { | 284 | { |
| 290 | struct perf_kmem *kmem = container_of(tool, struct perf_kmem, tool); | 285 | struct event_format *event = evsel->tp_format; |
| 291 | struct event_format *event; | ||
| 292 | int type; | ||
| 293 | |||
| 294 | type = trace_parse_common_type(kmem->session->pevent, data); | ||
| 295 | event = pevent_find_event(kmem->session->pevent, type); | ||
| 296 | 286 | ||
| 297 | if (!strcmp(event->name, "kmalloc") || | 287 | if (!strcmp(event->name, "kmalloc") || |
| 298 | !strcmp(event->name, "kmem_cache_alloc")) { | 288 | !strcmp(event->name, "kmem_cache_alloc")) { |
| @@ -313,10 +303,10 @@ static void process_raw_event(struct perf_tool *tool, | |||
| 313 | } | 303 | } |
| 314 | } | 304 | } |
| 315 | 305 | ||
| 316 | static int process_sample_event(struct perf_tool *tool, | 306 | static int process_sample_event(struct perf_tool *tool __used, |
| 317 | union perf_event *event, | 307 | union perf_event *event, |
| 318 | struct perf_sample *sample, | 308 | struct perf_sample *sample, |
| 319 | struct perf_evsel *evsel __used, | 309 | struct perf_evsel *evsel, |
| 320 | struct machine *machine) | 310 | struct machine *machine) |
| 321 | { | 311 | { |
| 322 | struct thread *thread = machine__findnew_thread(machine, event->ip.pid); | 312 | struct thread *thread = machine__findnew_thread(machine, event->ip.pid); |
| @@ -329,18 +319,16 @@ static int process_sample_event(struct perf_tool *tool, | |||
| 329 | 319 | ||
| 330 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | 320 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 331 | 321 | ||
| 332 | process_raw_event(tool, event, sample->raw_data, sample->cpu, | 322 | process_raw_event(evsel, sample->raw_data, sample->cpu, |
| 333 | sample->time, thread); | 323 | sample->time, thread); |
| 334 | 324 | ||
| 335 | return 0; | 325 | return 0; |
| 336 | } | 326 | } |
| 337 | 327 | ||
| 338 | static struct perf_kmem perf_kmem = { | 328 | static struct perf_tool perf_kmem = { |
| 339 | .tool = { | 329 | .sample = process_sample_event, |
| 340 | .sample = process_sample_event, | 330 | .comm = perf_event__process_comm, |
| 341 | .comm = perf_event__process_comm, | 331 | .ordered_samples = true, |
| 342 | .ordered_samples = true, | ||
| 343 | }, | ||
| 344 | }; | 332 | }; |
| 345 | 333 | ||
| 346 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) | 334 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
| @@ -497,13 +485,10 @@ static int __cmd_kmem(void) | |||
| 497 | int err = -EINVAL; | 485 | int err = -EINVAL; |
| 498 | struct perf_session *session; | 486 | struct perf_session *session; |
| 499 | 487 | ||
| 500 | session = perf_session__new(input_name, O_RDONLY, 0, false, | 488 | session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_kmem); |
| 501 | &perf_kmem.tool); | ||
| 502 | if (session == NULL) | 489 | if (session == NULL) |
| 503 | return -ENOMEM; | 490 | return -ENOMEM; |
| 504 | 491 | ||
| 505 | perf_kmem.session = session; | ||
| 506 | |||
| 507 | if (perf_session__create_kernel_maps(session) < 0) | 492 | if (perf_session__create_kernel_maps(session) < 0) |
| 508 | goto out_delete; | 493 | goto out_delete; |
| 509 | 494 | ||
| @@ -511,7 +496,7 @@ static int __cmd_kmem(void) | |||
| 511 | goto out_delete; | 496 | goto out_delete; |
| 512 | 497 | ||
| 513 | setup_pager(); | 498 | setup_pager(); |
| 514 | err = perf_session__process_events(session, &perf_kmem.tool); | 499 | err = perf_session__process_events(session, &perf_kmem); |
| 515 | if (err != 0) | 500 | if (err != 0) |
| 516 | goto out_delete; | 501 | goto out_delete; |
| 517 | sort_result(); | 502 | sort_result(); |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index b3c42854886..142b3033e4b 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include "builtin.h" | 1 | #include "builtin.h" |
| 2 | #include "perf.h" | 2 | #include "perf.h" |
| 3 | 3 | ||
| 4 | #include "util/evsel.h" | ||
| 4 | #include "util/util.h" | 5 | #include "util/util.h" |
| 5 | #include "util/cache.h" | 6 | #include "util/cache.h" |
| 6 | #include "util/symbol.h" | 7 | #include "util/symbol.h" |
| @@ -718,14 +719,10 @@ process_lock_release_event(void *data, | |||
| 718 | trace_handler->release_event(&release_event, event, cpu, timestamp, thread); | 719 | trace_handler->release_event(&release_event, event, cpu, timestamp, thread); |
| 719 | } | 720 | } |
| 720 | 721 | ||
| 721 | static void | 722 | static void process_raw_event(struct perf_evsel *evsel, void *data, int cpu, |
| 722 | process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread) | 723 | u64 timestamp, struct thread *thread) |
| 723 | { | 724 | { |
| 724 | struct event_format *event; | 725 | struct event_format *event = evsel->tp_format; |
| 725 | int type; | ||
| 726 | |||
| 727 | type = trace_parse_common_type(session->pevent, data); | ||
| 728 | event = pevent_find_event(session->pevent, type); | ||
| 729 | 726 | ||
| 730 | if (!strcmp(event->name, "lock_acquire")) | 727 | if (!strcmp(event->name, "lock_acquire")) |
| 731 | process_lock_acquire_event(data, event, cpu, timestamp, thread); | 728 | process_lock_acquire_event(data, event, cpu, timestamp, thread); |
| @@ -849,7 +846,7 @@ static void dump_info(void) | |||
| 849 | static int process_sample_event(struct perf_tool *tool __used, | 846 | static int process_sample_event(struct perf_tool *tool __used, |
| 850 | union perf_event *event, | 847 | union perf_event *event, |
| 851 | struct perf_sample *sample, | 848 | struct perf_sample *sample, |
| 852 | struct perf_evsel *evsel __used, | 849 | struct perf_evsel *evsel, |
| 853 | struct machine *machine) | 850 | struct machine *machine) |
| 854 | { | 851 | { |
| 855 | struct thread *thread = machine__findnew_thread(machine, sample->tid); | 852 | struct thread *thread = machine__findnew_thread(machine, sample->tid); |
| @@ -860,7 +857,7 @@ static int process_sample_event(struct perf_tool *tool __used, | |||
| 860 | return -1; | 857 | return -1; |
| 861 | } | 858 | } |
| 862 | 859 | ||
| 863 | process_raw_event(sample->raw_data, sample->cpu, sample->time, thread); | 860 | process_raw_event(evsel, sample->raw_data, sample->cpu, sample->time, thread); |
| 864 | 861 | ||
| 865 | return 0; | 862 | return 0; |
| 866 | } | 863 | } |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 7a9ad2b1ee7..30ef82aca88 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
| @@ -43,11 +43,6 @@ static u64 sleep_measurement_overhead; | |||
| 43 | 43 | ||
| 44 | static unsigned long nr_tasks; | 44 | static unsigned long nr_tasks; |
| 45 | 45 | ||
| 46 | struct perf_sched { | ||
| 47 | struct perf_tool tool; | ||
| 48 | struct perf_session *session; | ||
| 49 | }; | ||
| 50 | |||
| 51 | struct sched_atom; | 46 | struct sched_atom; |
| 52 | 47 | ||
| 53 | struct task_desc { | 48 | struct task_desc { |
| @@ -1596,14 +1591,12 @@ typedef void (*tracepoint_handler)(struct perf_tool *tool, struct event_format * | |||
| 1596 | struct machine *machine, | 1591 | struct machine *machine, |
| 1597 | struct thread *thread); | 1592 | struct thread *thread); |
| 1598 | 1593 | ||
| 1599 | static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | 1594 | static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __used, |
| 1600 | union perf_event *event __used, | 1595 | union perf_event *event __used, |
| 1601 | struct perf_sample *sample, | 1596 | struct perf_sample *sample, |
| 1602 | struct perf_evsel *evsel, | 1597 | struct perf_evsel *evsel, |
| 1603 | struct machine *machine) | 1598 | struct machine *machine) |
| 1604 | { | 1599 | { |
| 1605 | struct perf_sched *sched = container_of(tool, struct perf_sched, tool); | ||
| 1606 | struct pevent *pevent = sched->session->pevent; | ||
| 1607 | struct thread *thread = machine__findnew_thread(machine, sample->pid); | 1600 | struct thread *thread = machine__findnew_thread(machine, sample->pid); |
| 1608 | 1601 | ||
| 1609 | if (thread == NULL) { | 1602 | if (thread == NULL) { |
| @@ -1617,25 +1610,18 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | |||
| 1617 | 1610 | ||
| 1618 | if (evsel->handler.func != NULL) { | 1611 | if (evsel->handler.func != NULL) { |
| 1619 | tracepoint_handler f = evsel->handler.func; | 1612 | tracepoint_handler f = evsel->handler.func; |
| 1620 | 1613 | f(tool, evsel->tp_format, sample, machine, thread); | |
| 1621 | if (evsel->handler.data == NULL) | ||
| 1622 | evsel->handler.data = pevent_find_event(pevent, | ||
| 1623 | evsel->attr.config); | ||
| 1624 | |||
| 1625 | f(tool, evsel->handler.data, sample, machine, thread); | ||
| 1626 | } | 1614 | } |
| 1627 | 1615 | ||
| 1628 | return 0; | 1616 | return 0; |
| 1629 | } | 1617 | } |
| 1630 | 1618 | ||
| 1631 | static struct perf_sched perf_sched = { | 1619 | static struct perf_tool perf_sched = { |
| 1632 | .tool = { | 1620 | .sample = perf_sched__process_tracepoint_sample, |
| 1633 | .sample = perf_sched__process_tracepoint_sample, | 1621 | .comm = perf_event__process_comm, |
| 1634 | .comm = perf_event__process_comm, | 1622 | .lost = perf_event__process_lost, |
| 1635 | .lost = perf_event__process_lost, | 1623 | .fork = perf_event__process_task, |
| 1636 | .fork = perf_event__process_task, | 1624 | .ordered_samples = true, |
| 1637 | .ordered_samples = true, | ||
| 1638 | }, | ||
| 1639 | }; | 1625 | }; |
| 1640 | 1626 | ||
| 1641 | static void read_events(bool destroy, struct perf_session **psession) | 1627 | static void read_events(bool destroy, struct perf_session **psession) |
| @@ -1652,18 +1638,15 @@ static void read_events(bool destroy, struct perf_session **psession) | |||
| 1652 | }; | 1638 | }; |
| 1653 | struct perf_session *session; | 1639 | struct perf_session *session; |
| 1654 | 1640 | ||
| 1655 | session = perf_session__new(input_name, O_RDONLY, 0, false, | 1641 | session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_sched); |
| 1656 | &perf_sched.tool); | ||
| 1657 | if (session == NULL) | 1642 | if (session == NULL) |
| 1658 | die("No Memory"); | 1643 | die("No Memory"); |
| 1659 | 1644 | ||
| 1660 | perf_sched.session = session; | ||
| 1661 | |||
| 1662 | err = perf_session__set_tracepoints_handlers(session, handlers); | 1645 | err = perf_session__set_tracepoints_handlers(session, handlers); |
| 1663 | assert(err == 0); | 1646 | assert(err == 0); |
| 1664 | 1647 | ||
| 1665 | if (perf_session__has_traces(session, "record -R")) { | 1648 | if (perf_session__has_traces(session, "record -R")) { |
| 1666 | err = perf_session__process_events(session, &perf_sched.tool); | 1649 | err = perf_session__process_events(session, &perf_sched); |
| 1667 | if (err) | 1650 | if (err) |
| 1668 | die("Failed to process events, error %d", err); | 1651 | die("Failed to process events, error %d", err); |
| 1669 | 1652 | ||
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 1e60ab70b2b..8dba4707b03 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
| @@ -262,14 +262,11 @@ static int perf_session__check_output_opt(struct perf_session *session) | |||
| 262 | return 0; | 262 | return 0; |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | static void print_sample_start(struct pevent *pevent, | 265 | static void print_sample_start(struct perf_sample *sample, |
| 266 | struct perf_sample *sample, | ||
| 267 | struct thread *thread, | 266 | struct thread *thread, |
| 268 | struct perf_evsel *evsel) | 267 | struct perf_evsel *evsel) |
| 269 | { | 268 | { |
| 270 | int type; | ||
| 271 | struct perf_event_attr *attr = &evsel->attr; | 269 | struct perf_event_attr *attr = &evsel->attr; |
| 272 | struct event_format *event; | ||
| 273 | const char *evname = NULL; | 270 | const char *evname = NULL; |
| 274 | unsigned long secs; | 271 | unsigned long secs; |
| 275 | unsigned long usecs; | 272 | unsigned long usecs; |
| @@ -307,20 +304,7 @@ static void print_sample_start(struct pevent *pevent, | |||
| 307 | } | 304 | } |
| 308 | 305 | ||
| 309 | if (PRINT_FIELD(EVNAME)) { | 306 | if (PRINT_FIELD(EVNAME)) { |
| 310 | if (attr->type == PERF_TYPE_TRACEPOINT) { | 307 | 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]"); | 308 | printf("%s: ", evname ? evname : "[unknown]"); |
| 325 | } | 309 | } |
| 326 | } | 310 | } |
| @@ -416,7 +400,7 @@ static void print_sample_bts(union perf_event *event, | |||
| 416 | } | 400 | } |
| 417 | 401 | ||
| 418 | static void process_event(union perf_event *event __unused, | 402 | static void process_event(union perf_event *event __unused, |
| 419 | struct pevent *pevent, | 403 | struct pevent *pevent __unused, |
| 420 | struct perf_sample *sample, | 404 | struct perf_sample *sample, |
| 421 | struct perf_evsel *evsel, | 405 | struct perf_evsel *evsel, |
| 422 | struct machine *machine, | 406 | struct machine *machine, |
| @@ -427,7 +411,7 @@ static void process_event(union perf_event *event __unused, | |||
| 427 | if (output[attr->type].fields == 0) | 411 | if (output[attr->type].fields == 0) |
| 428 | return; | 412 | return; |
| 429 | 413 | ||
| 430 | print_sample_start(pevent, sample, thread, evsel); | 414 | print_sample_start(sample, thread, evsel); |
| 431 | 415 | ||
| 432 | if (is_bts_event(attr)) { | 416 | if (is_bts_event(attr)) { |
| 433 | print_sample_bts(event, sample, evsel, machine, thread); | 417 | print_sample_bts(event, sample, evsel, machine, thread); |
| @@ -435,9 +419,8 @@ static void process_event(union perf_event *event __unused, | |||
| 435 | } | 419 | } |
| 436 | 420 | ||
| 437 | if (PRINT_FIELD(TRACE)) | 421 | if (PRINT_FIELD(TRACE)) |
| 438 | print_trace_event(pevent, sample->cpu, sample->raw_data, | 422 | event_format__print(evsel->tp_format, sample->cpu, |
| 439 | sample->raw_size); | 423 | sample->raw_data, sample->raw_size); |
| 440 | |||
| 441 | if (PRINT_FIELD(ADDR)) | 424 | if (PRINT_FIELD(ADDR)) |
| 442 | print_sample_addr(event, sample, machine, thread, attr); | 425 | print_sample_addr(event, sample, machine, thread, attr); |
| 443 | 426 | ||
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index b559929983b..a56c4574b3f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
| @@ -56,6 +56,7 @@ struct perf_evsel { | |||
| 56 | int ids; | 56 | int ids; |
| 57 | struct hists hists; | 57 | struct hists hists; |
| 58 | char *name; | 58 | char *name; |
| 59 | struct event_format *tp_format; | ||
| 59 | union { | 60 | union { |
| 60 | void *priv; | 61 | void *priv; |
| 61 | off_t id_offset; | 62 | off_t id_offset; |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e2b4864bd11..b2da439bce7 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -2123,6 +2123,7 @@ static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel, | |||
| 2123 | if (event->name == NULL) | 2123 | if (event->name == NULL) |
| 2124 | return -1; | 2124 | return -1; |
| 2125 | 2125 | ||
| 2126 | evsel->tp_format = event; | ||
| 2126 | return 0; | 2127 | return 0; |
| 2127 | } | 2128 | } |
| 2128 | 2129 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 02dfa19a467..c2662811659 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c | |||
| @@ -237,16 +237,16 @@ static void define_event_symbols(struct event_format *event, | |||
| 237 | define_event_symbols(event, ev_name, args->next); | 237 | define_event_symbols(event, ev_name, args->next); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | static inline | 240 | static inline struct event_format *find_cache_event(struct perf_evsel *evsel) |
| 241 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
| 242 | { | 241 | { |
| 243 | static char ev_name[256]; | 242 | static char ev_name[256]; |
| 244 | struct event_format *event; | 243 | struct event_format *event; |
| 244 | int type = evsel->attr.config; | ||
| 245 | 245 | ||
| 246 | if (events[type]) | 246 | if (events[type]) |
| 247 | return events[type]; | 247 | return events[type]; |
| 248 | 248 | ||
| 249 | events[type] = event = pevent_find_event(pevent, type); | 249 | events[type] = event = evsel->tp_format; |
| 250 | if (!event) | 250 | if (!event) |
| 251 | return NULL; | 251 | return NULL; |
| 252 | 252 | ||
| @@ -269,7 +269,6 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, | |||
| 269 | unsigned long long val; | 269 | unsigned long long val; |
| 270 | unsigned long s, ns; | 270 | unsigned long s, ns; |
| 271 | struct event_format *event; | 271 | struct event_format *event; |
| 272 | int type; | ||
| 273 | int pid; | 272 | int pid; |
| 274 | int cpu = sample->cpu; | 273 | int cpu = sample->cpu; |
| 275 | void *data = sample->raw_data; | 274 | void *data = sample->raw_data; |
| @@ -281,11 +280,9 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, | |||
| 281 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | 280 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) |
| 282 | return; | 281 | return; |
| 283 | 282 | ||
| 284 | type = trace_parse_common_type(pevent, data); | 283 | event = find_cache_event(evsel); |
| 285 | |||
| 286 | event = find_cache_event(pevent, type); | ||
| 287 | if (!event) | 284 | if (!event) |
| 288 | die("ug! no event found for type %d", type); | 285 | die("ug! no event found for type %d", evsel->attr.config); |
| 289 | 286 | ||
| 290 | pid = trace_parse_common_pid(pevent, data); | 287 | pid = trace_parse_common_pid(pevent, data); |
| 291 | 288 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index ce4d1b0c386..8006978d839 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <errno.h> | 27 | #include <errno.h> |
| 28 | 28 | ||
| 29 | #include "../../perf.h" | 29 | #include "../../perf.h" |
| 30 | #include "../evsel.h" | ||
| 30 | #include "../util.h" | 31 | #include "../util.h" |
| 31 | #include "../event.h" | 32 | #include "../event.h" |
| 32 | #include "../thread.h" | 33 | #include "../thread.h" |
| @@ -194,16 +195,21 @@ static void define_event_symbols(struct event_format *event, | |||
| 194 | define_event_symbols(event, ev_name, args->next); | 195 | define_event_symbols(event, ev_name, args->next); |
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | static inline | 198 | static inline struct event_format *find_cache_event(struct perf_evsel *evsel) |
| 198 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
| 199 | { | 199 | { |
| 200 | static char ev_name[256]; | 200 | static char ev_name[256]; |
| 201 | struct event_format *event; | 201 | struct event_format *event; |
| 202 | int type = evsel->attr.config; | ||
| 202 | 203 | ||
| 204 | /* | ||
| 205 | * XXX: Do we really need to cache this since now we have evsel->tp_format | ||
| 206 | * cached already? Need to re-read this "cache" routine that as well calls | ||
| 207 | * define_event_symbols() :-\ | ||
| 208 | */ | ||
| 203 | if (events[type]) | 209 | if (events[type]) |
| 204 | return events[type]; | 210 | return events[type]; |
| 205 | 211 | ||
| 206 | events[type] = event = pevent_find_event(pevent, type); | 212 | events[type] = event = evsel->tp_format; |
| 207 | if (!event) | 213 | if (!event) |
| 208 | return NULL; | 214 | return NULL; |
| 209 | 215 | ||
| @@ -217,7 +223,7 @@ struct event_format *find_cache_event(struct pevent *pevent, int type) | |||
| 217 | static void python_process_event(union perf_event *perf_event __unused, | 223 | static void python_process_event(union perf_event *perf_event __unused, |
| 218 | struct pevent *pevent, | 224 | struct pevent *pevent, |
| 219 | struct perf_sample *sample, | 225 | struct perf_sample *sample, |
| 220 | struct perf_evsel *evsel __unused, | 226 | struct perf_evsel *evsel, |
| 221 | struct machine *machine __unused, | 227 | struct machine *machine __unused, |
| 222 | struct thread *thread) | 228 | struct thread *thread) |
| 223 | { | 229 | { |
| @@ -228,7 +234,6 @@ static void python_process_event(union perf_event *perf_event __unused, | |||
| 228 | unsigned long s, ns; | 234 | unsigned long s, ns; |
| 229 | struct event_format *event; | 235 | struct event_format *event; |
| 230 | unsigned n = 0; | 236 | unsigned n = 0; |
| 231 | int type; | ||
| 232 | int pid; | 237 | int pid; |
| 233 | int cpu = sample->cpu; | 238 | int cpu = sample->cpu; |
| 234 | void *data = sample->raw_data; | 239 | void *data = sample->raw_data; |
| @@ -239,11 +244,9 @@ static void python_process_event(union perf_event *perf_event __unused, | |||
| 239 | if (!t) | 244 | if (!t) |
| 240 | Py_FatalError("couldn't create Python tuple"); | 245 | Py_FatalError("couldn't create Python tuple"); |
| 241 | 246 | ||
| 242 | type = trace_parse_common_type(pevent, data); | 247 | event = find_cache_event(evsel); |
| 243 | |||
| 244 | event = find_cache_event(pevent, type); | ||
| 245 | if (!event) | 248 | if (!event) |
| 246 | die("ug! no event found for type %d", type); | 249 | die("ug! no event found for type %d", (int)evsel->attr.config); |
| 247 | 250 | ||
| 248 | pid = trace_parse_common_pid(pevent, data); | 251 | pid = trace_parse_common_pid(pevent, data); |
| 249 | 252 | ||
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index 0715c843c2e..12088348ac0 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
| @@ -167,20 +167,11 @@ unsigned long long read_size(struct pevent *pevent, void *ptr, int size) | |||
| 167 | return pevent_read_number(pevent, ptr, size); | 167 | return pevent_read_number(pevent, ptr, size); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size) | 170 | void event_format__print(struct event_format *event, |
| 171 | int cpu, void *data, int size) | ||
| 171 | { | 172 | { |
| 172 | struct event_format *event; | ||
| 173 | struct pevent_record record; | 173 | struct pevent_record record; |
| 174 | struct trace_seq s; | 174 | struct trace_seq s; |
| 175 | int type; | ||
| 176 | |||
| 177 | type = trace_parse_common_type(pevent, data); | ||
| 178 | |||
| 179 | event = pevent_find_event(pevent, type); | ||
| 180 | if (!event) { | ||
| 181 | warning("ug! no event found for type %d", type); | ||
| 182 | return; | ||
| 183 | } | ||
| 184 | 175 | ||
| 185 | memset(&record, 0, sizeof(record)); | 176 | memset(&record, 0, sizeof(record)); |
| 186 | record.cpu = cpu; | 177 | record.cpu = cpu; |
| @@ -192,6 +183,19 @@ void print_trace_event(struct pevent *pevent, int cpu, void *data, int size) | |||
| 192 | trace_seq_do_printf(&s); | 183 | trace_seq_do_printf(&s); |
| 193 | } | 184 | } |
| 194 | 185 | ||
| 186 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size) | ||
| 187 | { | ||
| 188 | int type = trace_parse_common_type(pevent, data); | ||
| 189 | struct event_format *event = pevent_find_event(pevent, type); | ||
| 190 | |||
| 191 | if (!event) { | ||
| 192 | warning("ug! no event found for type %d", type); | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | event_format__print(event, cpu, data, size); | ||
| 197 | } | ||
| 198 | |||
| 195 | void print_event(struct pevent *pevent, int cpu, void *data, int size, | 199 | void print_event(struct pevent *pevent, int cpu, void *data, int size, |
| 196 | unsigned long long nsecs, char *comm) | 200 | unsigned long long nsecs, char *comm) |
| 197 | { | 201 | { |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 8fef1d6687b..069d105e0fc 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
| @@ -32,6 +32,8 @@ int bigendian(void); | |||
| 32 | 32 | ||
| 33 | struct pevent *read_trace_init(int file_bigendian, int host_bigendian); | 33 | struct pevent *read_trace_init(int file_bigendian, int host_bigendian); |
| 34 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size); | 34 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size); |
| 35 | void event_format__print(struct event_format *event, | ||
| 36 | int cpu, void *data, int size); | ||
| 35 | 37 | ||
| 36 | void print_event(struct pevent *pevent, int cpu, void *data, int size, | 38 | void print_event(struct pevent *pevent, int cpu, void *data, int size, |
| 37 | unsigned long long nsecs, char *comm); | 39 | unsigned long long nsecs, char *comm); |
