Skip to content

Commit

Permalink
checkstack: sort output by size and function name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hcahca authored and akpm00 committed Dec 11, 2023
1 parent b454ec2 commit fe1a25e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions scripts/checkstack.pl
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,20 @@ sub arm_push_handling {
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;

0 comments on commit fe1a25e

Please sign in to comment.