return 0;
}
+static int hit_cmp(struct alloc_stat *l, struct alloc_stat *r)
+{
+ if (l->hit < r->hit)
+ return -1;
+ else if (l->hit > r->hit)
+ return 1;
+ return 0;
+}
+
static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r)
{
if (l->bytes_alloc < r->bytes_alloc)
return 0;
}
+static int frag_cmp(struct alloc_stat *l, struct alloc_stat *r)
+{
+ double x, y;
+
+ x = fragmentation(l->bytes_req, l->bytes_alloc);
+ y = fragmentation(r->bytes_req, r->bytes_alloc);
+
+ if (x < y)
+ return -1;
+ else if (x > y)
+ return 1;
+ return 0;
+}
+
static int parse_sort_opt(const struct option *opt __used,
const char *arg, int unset __used)
{
sort_fn = ptr_cmp;
else if (strcmp(arg, "call_site") == 0)
sort_fn = callsite_cmp;
+ else if (strcmp(arg, "hit") == 0)
+ sort_fn = hit_cmp;
else if (strcmp(arg, "bytes") == 0)
sort_fn = bytes_cmp;
+ else if (strcmp(arg, "frag") == 0)
+ sort_fn = frag_cmp;
else
return -1;
"stat selector, Pass 'alloc' or 'caller'.",
parse_stat_opt),
OPT_CALLBACK('s', "sort", NULL, "key",
- "sort by key: ptr, call_site, hit, bytes",
+ "sort by key: ptr, call_site, hit, bytes, frag",
parse_sort_opt),
OPT_CALLBACK('l', "line", NULL, "num",
"show n lins",