cb77f0d623ff3 (Kamil Rytarowski 2017-05-07 23:25:26 +0200 1) #!/usr/bin/env perl
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 2) # SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) # Check the stack usage of functions
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) #
2b54aaef7a3a7 (Joern Engel 2008-02-06 01:38:02 -0800 6) # Copyright Joern Engel <joern@lazybastard.org>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7) # Inspired by Linus Torvalds
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 8) # Original idea maybe from Keith Owens
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9) # s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10) # Mips port by Juan Quintela <quintela@mandrakesoft.com>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 11) # IA64 port via Andreas Dilger
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) # Arm port by Holger Schurig
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) # sh64 port by Paul Mundt
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14) # Random bits by Matt Mackall <mpm@selenic.com>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) # M68k port by Geert Uytterhoeven and Andreas Schwab
208ad0012e372 (Kyle McMartin 2014-06-20 11:41:37 -0400 16) # AArch64, PARISC ports by Kyle McMartin
d41e2d7317cd5 (Martin Habets 2008-10-21 21:58:29 -0700 17) # sparc port by Martin Habets <errandir_news@mph.eclipse.co.uk>
8449a4cb69ab6 (Breno Leitao 2017-11-28 17:29:34 -0200 18) # ppc64le port by Breno Leitao <leitao@debian.org>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) # Usage:
477116e69dc48 (Joern Engel 2007-10-18 23:39:18 -0700 21) # objdump -d vmlinux | scripts/checkstack.pl [arch]
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) # TODO : Port to all architectures (one regex per arch)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24)
1f2a144f5ab5e (Stephen Hemminger 2010-02-22 15:17:09 -0800 25) use strict;
1f2a144f5ab5e (Stephen Hemminger 2010-02-22 15:17:09 -0800 26)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 27) # check for arch
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29) # $re is used for two matches:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 30) # $& (whole re) matches the complete objdump line with the stack growth
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 31) # $1 (first bracket) matches the size of the stack growth
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 32) #
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 33) # $dre is similar, but for dynamic stack redutions:
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 34) # $& (whole re) matches the complete objdump line with the stack growth
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 35) # $1 (first bracket) matches the dynamic amount of the stack growth
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 36) #
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 37) # $sub: subroutine for special handling to check stack usage.
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 38) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 39) # use anything else and feel the pain ;)
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 40) my (@stack, $re, $dre, $sub, $x, $xs, $funcre, $min_stack);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 42) my $arch = shift;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 43) if ($arch eq "") {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 44) $arch = `uname -m`;
abddaec56ebb7 (Eric Sandeen 2008-07-25 01:45:28 -0700 45) chomp($arch);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 47)
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 48) $min_stack = shift;
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 49) if ($min_stack eq "" || $min_stack !~ /^\d+$/) {
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 50) $min_stack = 100;
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 51) }
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 52)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 53) $x = "[0-9a-f]"; # hex character
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 54) $xs = "[0-9a-f ]"; # hex character or space
690998b629a55 (James Hogan 2012-10-17 15:21:13 +0100 55) $funcre = qr/^$x* <(.*)>:$/;
4f45d62a52297 (George G. Davis 2019-06-03 10:30:39 -0400 56) if ($arch =~ '^(aarch|arm)64$') {
f1733a1d3cd32 (Qian Cai 2018-12-14 14:17:20 -0800 57) #ffffffc0006325cc: a9bb7bfd stp x29, x30, [sp, #-80]!
919e9d39e722d (Qian Cai 2018-12-28 00:31:28 -0800 58) #a110: d11643ff sub sp, sp, #0x590
f1733a1d3cd32 (Qian Cai 2018-12-14 14:17:20 -0800 59) $re = qr/^.*stp.*sp, \#-([0-9]{1,8})\]\!/o;
919e9d39e722d (Qian Cai 2018-12-28 00:31:28 -0800 60) $dre = qr/^.*sub.*sp, sp, #(0x$x{1,8})/o;
208ad0012e372 (Kyle McMartin 2014-06-20 11:41:37 -0400 61) } elsif ($arch eq 'arm') {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 62) #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
6ce16f2bc879f (Maninder Singh 2020-05-08 16:33:17 +0530 63) $re = qr/.*sub.*sp, sp, #([0-9]{1,4})/o;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 64) $sub = \&arm_push_handling;
fda9f9903be6c (Konstantin Khlebnikov 2014-08-08 14:23:35 -0700 65) } elsif ($arch =~ /^x86(_64)?$/ || $arch =~ /^i[3456]86$/) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 66) #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
fda9f9903be6c (Konstantin Khlebnikov 2014-08-08 14:23:35 -0700 67) # or
fda9f9903be6c (Konstantin Khlebnikov 2014-08-08 14:23:35 -0700 68) # 2f60: 48 81 ec e8 05 00 00 sub $0x5e8,%rsp
fda9f9903be6c (Konstantin Khlebnikov 2014-08-08 14:23:35 -0700 69) $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%(e|r)sp$/o;
fda9f9903be6c (Konstantin Khlebnikov 2014-08-08 14:23:35 -0700 70) $dre = qr/^.*[as][du][db] (%.*),\%(e|r)sp$/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 71) } elsif ($arch eq 'ia64') {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 72) #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 73) $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 74) } elsif ($arch eq 'm68k') {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 75) # 2b6c: 4e56 fb70 linkw %fp,#-1168
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 76) # 1df770: defc ffe4 addaw #-28,%sp
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 77) $re = qr/.*(?:linkw %fp,|addaw )#-([0-9]{1,4})(?:,%sp)?$/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 78) } elsif ($arch eq 'mips64') {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 79) #8800402c: 67bdfff0 daddiu sp,sp,-16
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 80) $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 81) } elsif ($arch eq 'mips') {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 82) #88003254: 27bdffe0 addiu sp,sp,-32
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 83) $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
0e5a47a8d346c (Tobias Klauser 2017-02-22 15:40:23 -0800 84) } elsif ($arch eq 'nios2') {
0e5a47a8d346c (Tobias Klauser 2017-02-22 15:40:23 -0800 85) #25a8: defffb04 addi sp,sp,-20
0e5a47a8d346c (Tobias Klauser 2017-02-22 15:40:23 -0800 86) $re = qr/.*addi.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
f72deab378db8 (Stafford Horne 2017-01-03 16:15:03 +0900 87) } elsif ($arch eq 'openrisc') {
f72deab378db8 (Stafford Horne 2017-01-03 16:15:03 +0900 88) # c000043c: 9c 21 fe f0 l.addi r1,r1,-272
f72deab378db8 (Stafford Horne 2017-01-03 16:15:03 +0900 89) $re = qr/.*l\.addi.*r1,r1,-(([0-9]{2}|[3-9])[0-9]{2})/o;
562d139cc587f (Kyle McMartin 2007-10-20 13:18:56 -0700 90) } elsif ($arch eq 'parisc' || $arch eq 'parisc64') {
562d139cc587f (Kyle McMartin 2007-10-20 13:18:56 -0700 91) $re = qr/.*ldo ($x{1,8})\(sp\),sp/o;
8449a4cb69ab6 (Breno Leitao 2017-11-28 17:29:34 -0200 92) } elsif ($arch eq 'powerpc' || $arch =~ /^ppc(64)?(le)?$/ ) {
8449a4cb69ab6 (Breno Leitao 2017-11-28 17:29:34 -0200 93) # powerpc : 94 21 ff 30 stwu r1,-208(r1)
8449a4cb69ab6 (Breno Leitao 2017-11-28 17:29:34 -0200 94) # ppc64(le) : 81 ff 21 f8 stdu r1,-128(r1)
271c511db9d37 (Johannes Berg 2006-08-22 16:57:05 +0200 95) $re = qr/.*st[dw]u.*r1,-($x{1,8})\(r1\)/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 96) } elsif ($arch =~ /^s390x?$/) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 97) # 11160: a7 fb ff 60 aghi %r15,-160
89d49841e9e7a (Christian Borntraeger 2008-10-10 21:33:30 +0200 98) # or
89d49841e9e7a (Christian Borntraeger 2008-10-10 21:33:30 +0200 99) # 100092: e3 f0 ff c8 ff 71 lay %r15,-56(%r15)
89d49841e9e7a (Christian Borntraeger 2008-10-10 21:33:30 +0200 100) $re = qr/.*(?:lay|ag?hi).*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})
89d49841e9e7a (Christian Borntraeger 2008-10-10 21:33:30 +0200 101) (?:\(\%r15\))?$/ox;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 102) } elsif ($arch =~ /^sh64$/) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 103) #XXX: we only check for the immediate case presently,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 104) # though we will want to check for the movi/sub
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 105) # pair for larger users. -- PFM.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 106) #a00048e0: d4fc40f0 addi.l r15,-240,r15
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 107) $re = qr/.*addi\.l.*r15,-(([0-9]{2}|[3-9])[0-9]{2}),r15/o;
d41e2d7317cd5 (Martin Habets 2008-10-21 21:58:29 -0700 108) } elsif ($arch eq 'sparc' || $arch eq 'sparc64') {
d41e2d7317cd5 (Martin Habets 2008-10-21 21:58:29 -0700 109) # f0019d10: 9d e3 bf 90 save %sp, -112, %sp
d41e2d7317cd5 (Martin Habets 2008-10-21 21:58:29 -0700 110) $re = qr/.*save.*%sp, -(([0-9]{2}|[3-9])[0-9]{2}), %sp/o;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 111) } else {
abddaec56ebb7 (Eric Sandeen 2008-07-25 01:45:28 -0700 112) print("wrong or unknown architecture \"$arch\"\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 113) exit
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 114) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 115) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 116)
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 117) #
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 118) # To count stack usage of push {*, fp, ip, lr, pc} instruction in ARM,
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 119) # if FRAME POINTER is enabled.
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 120) # e.g. c01f0d48: e92ddff0 push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc}
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 121) #
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 122) sub arm_push_handling {
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 123) my $regex = qr/.*push.*fp, ip, lr, pc}/o;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 124) my $size = 0;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 125) my $line_arg = shift;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 126)
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 127) if ($line_arg =~ m/$regex/) {
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 128) $size = $line_arg =~ tr/,//;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 129) $size = ($size + 1) * 4;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 130) }
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 131)
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 132) return $size;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 133) }
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 134)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 135) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 136) # main()
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 137) #
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 138) my ($func, $file, $lastslash, $total_size, $addr, $intro);
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 139)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 140) $total_size = 0;
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 141)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 142) while (my $line = <STDIN>) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 143) if ($line =~ m/$funcre/) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 144) $func = $1;
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 145) next if $line !~ m/^($xs*)/;
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 146) if ($total_size > $min_stack) {
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 147) push @stack, "$intro$total_size\n";
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 148) }
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 149)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 150) $addr = $1;
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 151) $addr =~ s/ /0/g;
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 152) $addr = "0x$addr";
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 153)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 154) $intro = "$addr $func [$file]:";
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 155) my $padlen = 56 - length($intro);
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 156) while ($padlen > 0) {
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 157) $intro .= ' ';
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 158) $padlen -= 8;
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 159) }
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 160)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 161) $total_size = 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 162) }
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 163) elsif ($line =~ m/(.*):\s*file format/) {
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 164) $file = $1;
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 165) $file =~ s/\.ko//;
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 166) $lastslash = rindex($file, "/");
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 167) if ($lastslash != -1) {
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 168) $file = substr($file, $lastslash + 1);
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 169) }
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 170) }
8ad2914d9cc55 (Randy Dunlap 2006-06-25 05:48:29 -0700 171) elsif ($line =~ m/$re/) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 172) my $size = $1;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 173) $size = hex($size) if ($size =~ /^0x/);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 174)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 175) if ($size > 0xf0000000) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 176) $size = - $size;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 177) $size += 0x80000000;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 178) $size += 0x80000000;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 179) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 180) next if ($size > 0x10000000);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 181)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 182) $total_size += $size;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 183) }
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 184) elsif (defined $dre && $line =~ m/$dre/) {
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 185) my $size = $1;
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 186)
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 187) $size = hex($size) if ($size =~ /^0x/);
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 188) $total_size += $size;
585e93ae83b80 (Eric Sandeen 2008-07-25 01:45:27 -0700 189) }
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 190) elsif (defined $sub) {
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 191) my $size = &$sub($line);
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 192)
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 193) $total_size += $size;
3311eeebae94b (Maninder Singh 2020-05-08 16:33:16 +0530 194) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 195) }
572220aad525b (Maninder Singh 2020-05-08 16:33:15 +0530 196) if ($total_size > $min_stack) {
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 197) push @stack, "$intro$total_size\n";
677f1410e0581 (Maninder Singh 2020-05-08 16:33:14 +0530 198) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 199)
1f2a144f5ab5e (Stephen Hemminger 2010-02-22 15:17:09 -0800 200) # Sort output by size (last field)
1f2a144f5ab5e (Stephen Hemminger 2010-02-22 15:17:09 -0800 201) print sort { ($b =~ /:\t*(\d+)$/)[0] <=> ($a =~ /:\t*(\d+)$/)[0] } @stack;