diff options
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r-- | tools/perf/builtin-kmem.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 0b4b796167be..46878daca5cc 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "util/debug.h" | 17 | #include "util/debug.h" |
18 | 18 | ||
19 | #include <linux/rbtree.h> | 19 | #include <linux/rbtree.h> |
20 | #include <linux/string.h> | ||
20 | 21 | ||
21 | struct alloc_stat; | 22 | struct alloc_stat; |
22 | typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); | 23 | typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); |
@@ -340,7 +341,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
340 | int n_lines, int is_caller) | 341 | int n_lines, int is_caller) |
341 | { | 342 | { |
342 | struct rb_node *next; | 343 | struct rb_node *next; |
343 | struct machine *machine; | 344 | struct machine *machine = &session->machines.host; |
344 | 345 | ||
345 | printf("%.102s\n", graph_dotted_line); | 346 | printf("%.102s\n", graph_dotted_line); |
346 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); | 347 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); |
@@ -349,11 +350,6 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
349 | 350 | ||
350 | next = rb_first(root); | 351 | next = rb_first(root); |
351 | 352 | ||
352 | machine = perf_session__find_host_machine(session); | ||
353 | if (!machine) { | ||
354 | pr_err("__print_result: couldn't find kernel information\n"); | ||
355 | return; | ||
356 | } | ||
357 | while (next && n_lines--) { | 353 | while (next && n_lines--) { |
358 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, | 354 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, |
359 | node); | 355 | node); |
@@ -614,8 +610,7 @@ static struct sort_dimension *avail_sorts[] = { | |||
614 | &pingpong_sort_dimension, | 610 | &pingpong_sort_dimension, |
615 | }; | 611 | }; |
616 | 612 | ||
617 | #define NUM_AVAIL_SORTS \ | 613 | #define NUM_AVAIL_SORTS ((int)ARRAY_SIZE(avail_sorts)) |
618 | (int)(sizeof(avail_sorts) / sizeof(struct sort_dimension *)) | ||
619 | 614 | ||
620 | static int sort_dimension__add(const char *tok, struct list_head *list) | 615 | static int sort_dimension__add(const char *tok, struct list_head *list) |
621 | { | 616 | { |
@@ -624,12 +619,11 @@ static int sort_dimension__add(const char *tok, struct list_head *list) | |||
624 | 619 | ||
625 | for (i = 0; i < NUM_AVAIL_SORTS; i++) { | 620 | for (i = 0; i < NUM_AVAIL_SORTS; i++) { |
626 | if (!strcmp(avail_sorts[i]->name, tok)) { | 621 | if (!strcmp(avail_sorts[i]->name, tok)) { |
627 | sort = malloc(sizeof(*sort)); | 622 | sort = memdup(avail_sorts[i], sizeof(*avail_sorts[i])); |
628 | if (!sort) { | 623 | if (!sort) { |
629 | pr_err("%s: malloc failed\n", __func__); | 624 | pr_err("%s: memdup failed\n", __func__); |
630 | return -1; | 625 | return -1; |
631 | } | 626 | } |
632 | memcpy(sort, avail_sorts[i], sizeof(*sort)); | ||
633 | list_add_tail(&sort->list, list); | 627 | list_add_tail(&sort->list, list); |
634 | return 0; | 628 | return 0; |
635 | } | 629 | } |