diff options
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r-- | tools/perf/builtin-kmem.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index de194958fe6e..e79ecbc17181 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -364,19 +364,6 @@ static struct perf_event_ops event_ops = { | |||
364 | .sample_type_check = sample_type_check, | 364 | .sample_type_check = sample_type_check, |
365 | }; | 365 | }; |
366 | 366 | ||
367 | static int read_events(void) | ||
368 | { | ||
369 | int err; | ||
370 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); | ||
371 | |||
372 | if (session == NULL) | ||
373 | return -ENOMEM; | ||
374 | |||
375 | err = perf_session__process_events(session, &event_ops); | ||
376 | perf_session__delete(session); | ||
377 | return err; | ||
378 | } | ||
379 | |||
380 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) | 367 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
381 | { | 368 | { |
382 | if (n_alloc == 0) | 369 | if (n_alloc == 0) |
@@ -385,7 +372,8 @@ static double fragmentation(unsigned long n_req, unsigned long n_alloc) | |||
385 | return 100.0 - (100.0 * n_req / n_alloc); | 372 | return 100.0 - (100.0 * n_req / n_alloc); |
386 | } | 373 | } |
387 | 374 | ||
388 | static void __print_result(struct rb_root *root, int n_lines, int is_caller) | 375 | static void __print_result(struct rb_root *root, struct perf_session *session, |
376 | int n_lines, int is_caller) | ||
389 | { | 377 | { |
390 | struct rb_node *next; | 378 | struct rb_node *next; |
391 | 379 | ||
@@ -406,7 +394,7 @@ static void __print_result(struct rb_root *root, int n_lines, int is_caller) | |||
406 | if (is_caller) { | 394 | if (is_caller) { |
407 | addr = data->call_site; | 395 | addr = data->call_site; |
408 | if (!raw_ip) | 396 | if (!raw_ip) |
409 | sym = map_groups__find_function(kmaps, addr, NULL); | 397 | sym = map_groups__find_function(&session->kmaps, session, addr, NULL); |
410 | } else | 398 | } else |
411 | addr = data->ptr; | 399 | addr = data->ptr; |
412 | 400 | ||
@@ -447,12 +435,12 @@ static void print_summary(void) | |||
447 | printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs); | 435 | printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs); |
448 | } | 436 | } |
449 | 437 | ||
450 | static void print_result(void) | 438 | static void print_result(struct perf_session *session) |
451 | { | 439 | { |
452 | if (caller_flag) | 440 | if (caller_flag) |
453 | __print_result(&root_caller_sorted, caller_lines, 1); | 441 | __print_result(&root_caller_sorted, session, caller_lines, 1); |
454 | if (alloc_flag) | 442 | if (alloc_flag) |
455 | __print_result(&root_alloc_sorted, alloc_lines, 0); | 443 | __print_result(&root_alloc_sorted, session, alloc_lines, 0); |
456 | print_summary(); | 444 | print_summary(); |
457 | } | 445 | } |
458 | 446 | ||
@@ -520,12 +508,21 @@ static void sort_result(void) | |||
520 | 508 | ||
521 | static int __cmd_kmem(void) | 509 | static int __cmd_kmem(void) |
522 | { | 510 | { |
511 | int err; | ||
512 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, | ||
513 | 0, NULL); | ||
514 | if (session == NULL) | ||
515 | return -ENOMEM; | ||
516 | |||
523 | setup_pager(); | 517 | setup_pager(); |
524 | read_events(); | 518 | err = perf_session__process_events(session, &event_ops); |
519 | if (err != 0) | ||
520 | goto out_delete; | ||
525 | sort_result(); | 521 | sort_result(); |
526 | print_result(); | 522 | print_result(session); |
527 | 523 | out_delete: | |
528 | return 0; | 524 | perf_session__delete(session); |
525 | return err; | ||
529 | } | 526 | } |
530 | 527 | ||
531 | static const char * const kmem_usage[] = { | 528 | static const char * const kmem_usage[] = { |