summaryrefslogtreecommitdiff
path: root/bin/ios-mapfile-statistics
blob: 2e16ed72f940db1745d8c3b6a5dc887b12f4771b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w

use strict;

use Getopt::Std;

my %args;

getopts('s', \%args);

my $state = 0;
my %libofnumber;
my %sizeoflib;
my %sizeofsym;

while (<>) {
  if ($state == 0 && m!^# Object files:!) {
    $state = 1;
  } elsif ($state == 1 && m!^\[ *([0-9]+)\] .*/([-_a-z0-9]+\.a)\(.*!i) {
    $libofnumber{$1} = $2;
  } elsif ($state == 1 && m!^# Sections:!) {
    $state = 2;
  } elsif ($state == 2 && m!^# Address\s+Size\s+File\s+Name!) {
    $state = 3;
  } elsif ($state == 3 && m!^0x[0-9A-F]+\s+(0x[0-9A-F]+)\s+\[ *([0-9]+)\] (.*)!) {
    if (defined($libofnumber{$2})) {
      $sizeoflib{$libofnumber{$2}} += hex($1);
    }
    $sizeofsym{$3} = hex($1);
  }
}

if ($args{'s'}) {
  # Print symbols in reverse size order
  foreach (sort { $sizeofsym{$b} <=> $sizeofsym{$a} } keys(%sizeofsym)) {
    print $_, ": ", $sizeofsym{$_}, "\n";
  }
} else {
  # Print libraries in reverse size order
  foreach (sort { $sizeoflib{$b} <=> $sizeoflib{$a} } keys(%sizeoflib)) {
    print $_, ": ", $sizeoflib{$_}, "\n";
  }
}