summaryrefslogtreecommitdiff
path: root/tools/vm
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2022-03-24 18:08:41 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2022-03-24 19:06:44 -0700
commit82f5ebc2beb3c803bf17bead4e38c1d5bf2c8d78 (patch)
tree0acd451c8aaa4f1a7d7b7858528f02e237b19e28 /tools/vm
parentba5a396be51cd232d6647f70f7d792c6dcc63223 (diff)
tools/vm/page_owner_sort.c: support sorting by stack trace
This adds the ability to sort by stacktraces. This is helpful when comparing multiple dumps of page_owner taken at different times, since blocks will not be reordered if they were allocated/free'd. Link: https://lkml.kernel.org/r/20211124193709.1805776-2-seanga2@gmail.com Signed-off-by: Sean Anderson <seanga2@gmail.com> Cc: Zhenliang Wei <weizhenliang@huawei.com> Cc: Changhee Han <ch0.han@lge.com> Cc: Tang Bin <tangbin@cmss.chinamobile.com> Cc: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Yinan Zhang <zhangyinan2019@email.szu.edu.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/vm')
-rw-r--r--tools/vm/page_owner_sort.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index 5582d8454d3b..1b2acf02d3cd 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -29,7 +29,6 @@ struct block_list {
int page_num;
};
-static int sort_by_memory;
static regex_t order_pattern;
static struct block_list *list;
static int list_size;
@@ -134,13 +133,16 @@ static void add_list(char *buf, int len)
static void usage(void)
{
- printf("Usage: ./page_owner_sort [-m] <input> <output>\n"
- "-m Sort by total memory. If this option is unset, sort by times\n"
+ printf("Usage: ./page_owner_sort [OPTIONS] <input> <output>\n"
+ "-m Sort by total memory.\n"
+ "-s Sort by the stack trace.\n"
+ "-t Sort by times (default).\n"
);
}
int main(int argc, char **argv)
{
+ int (*cmp)(const void *, const void *) = compare_num;
FILE *fin, *fout;
char *buf;
int ret, i, count;
@@ -149,10 +151,16 @@ int main(int argc, char **argv)
int err;
int opt;
- while ((opt = getopt(argc, argv, "m")) != -1)
+ while ((opt = getopt(argc, argv, "mst")) != -1)
switch (opt) {
case 'm':
- sort_by_memory = 1;
+ cmp = compare_page_num;
+ break;
+ case 's':
+ cmp = compare_stacktrace;
+ break;
+ case 't':
+ cmp = compare_num;
break;
default:
usage();
@@ -221,10 +229,7 @@ int main(int argc, char **argv)
}
}
- if (sort_by_memory)
- qsort(list2, count, sizeof(list[0]), compare_page_num);
- else
- qsort(list2, count, sizeof(list[0]), compare_num);
+ qsort(list2, count, sizeof(list[0]), cmp);
for (i = 0; i < count; i++)
fprintf(fout, "%d times, %d pages:\n%s\n",