checkstack: sort output by size and function name
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 20 Nov 2023 18:37:18 +0000 (19:37 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 11 Dec 2023 01:21:32 +0000 (17:21 -0800)
Sort output by size and in addition by function name.  This increases
readability for cases where there are many functions with the same stack
usage.

Link: https://lkml.kernel.org/r/20231120183719.2188479-3-hca@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Cc: Maninder Singh <maninder1.s@samsung.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Vaneet Narang <v.narang@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
scripts/checkstack.pl

index f27d552aec43f2b41aacf195069510c3121be03b..13408714ba0f88794311b2b332e470870cba1ae7 100755 (executable)
@@ -189,5 +189,20 @@ if ($total_size > $min_stack) {
        push @stack, "$intro$total_size\n";
 }
 
-# Sort output by size (last field)
-print sort { ($b =~ /:\t*(\d+)$/)[0] <=> ($a =~ /:\t*(\d+)$/)[0] } @stack;
+# Sort output by size (last field) and function name if size is the same
+sub sort_lines {
+       my ($a, $b) = @_;
+
+       my $num_a = $1 if $a =~ /:\t*(\d+)$/;
+       my $num_b = $1 if $b =~ /:\t*(\d+)$/;
+       my $func_a = $1 if $a =~ / (.*):/;
+       my $func_b = $1 if $b =~ / (.*):/;
+
+       if ($num_a != $num_b) {
+               return $num_b <=> $num_a;
+       } else {
+               return $func_a cmp $func_b;
+       }
+}
+
+print sort { sort_lines($a, $b) } @stack;