diff options
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r-- | tools/perf/builtin-kmem.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index f315b052f819..4145049e7bf5 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -443,6 +443,15 @@ static int callsite_cmp(struct alloc_stat *l, struct alloc_stat *r) | |||
443 | return 0; | 443 | return 0; |
444 | } | 444 | } |
445 | 445 | ||
446 | static int hit_cmp(struct alloc_stat *l, struct alloc_stat *r) | ||
447 | { | ||
448 | if (l->hit < r->hit) | ||
449 | return -1; | ||
450 | else if (l->hit > r->hit) | ||
451 | return 1; | ||
452 | return 0; | ||
453 | } | ||
454 | |||
446 | static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r) | 455 | static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r) |
447 | { | 456 | { |
448 | if (l->bytes_alloc < r->bytes_alloc) | 457 | if (l->bytes_alloc < r->bytes_alloc) |
@@ -452,6 +461,20 @@ static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r) | |||
452 | return 0; | 461 | return 0; |
453 | } | 462 | } |
454 | 463 | ||
464 | static int frag_cmp(struct alloc_stat *l, struct alloc_stat *r) | ||
465 | { | ||
466 | double x, y; | ||
467 | |||
468 | x = fragmentation(l->bytes_req, l->bytes_alloc); | ||
469 | y = fragmentation(r->bytes_req, r->bytes_alloc); | ||
470 | |||
471 | if (x < y) | ||
472 | return -1; | ||
473 | else if (x > y) | ||
474 | return 1; | ||
475 | return 0; | ||
476 | } | ||
477 | |||
455 | static int parse_sort_opt(const struct option *opt __used, | 478 | static int parse_sort_opt(const struct option *opt __used, |
456 | const char *arg, int unset __used) | 479 | const char *arg, int unset __used) |
457 | { | 480 | { |
@@ -464,8 +487,12 @@ static int parse_sort_opt(const struct option *opt __used, | |||
464 | sort_fn = ptr_cmp; | 487 | sort_fn = ptr_cmp; |
465 | else if (strcmp(arg, "call_site") == 0) | 488 | else if (strcmp(arg, "call_site") == 0) |
466 | sort_fn = callsite_cmp; | 489 | sort_fn = callsite_cmp; |
490 | else if (strcmp(arg, "hit") == 0) | ||
491 | sort_fn = hit_cmp; | ||
467 | else if (strcmp(arg, "bytes") == 0) | 492 | else if (strcmp(arg, "bytes") == 0) |
468 | sort_fn = bytes_cmp; | 493 | sort_fn = bytes_cmp; |
494 | else if (strcmp(arg, "frag") == 0) | ||
495 | sort_fn = frag_cmp; | ||
469 | else | 496 | else |
470 | return -1; | 497 | return -1; |
471 | 498 | ||
@@ -517,7 +544,7 @@ static const struct option kmem_options[] = { | |||
517 | "stat selector, Pass 'alloc' or 'caller'.", | 544 | "stat selector, Pass 'alloc' or 'caller'.", |
518 | parse_stat_opt), | 545 | parse_stat_opt), |
519 | OPT_CALLBACK('s', "sort", NULL, "key", | 546 | OPT_CALLBACK('s', "sort", NULL, "key", |
520 | "sort by key: ptr, call_site, hit, bytes", | 547 | "sort by key: ptr, call_site, hit, bytes, frag", |
521 | parse_sort_opt), | 548 | parse_sort_opt), |
522 | OPT_CALLBACK('l', "line", NULL, "num", | 549 | OPT_CALLBACK('l', "line", NULL, "num", |
523 | "show n lins", | 550 | "show n lins", |