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 | |
| 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>
| -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 ce35015f2dc6..ffb93f424953 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 b3c428548868..142b3033e4be 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; |
