diff options
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r-- | tools/perf/builtin-kmem.c | 39 |
1 files changed, 12 insertions, 27 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(); |