don't throw away command output when packaging installsets
[LibreOffice.git] / bin / ios-mapfile-statistics
blob07f3f0aa68b4378c0fea397e537b3d165022474c
1 #!/usr/bin/perl -w
3 use strict;
5 use Getopt::Std;
6 $Getopt::Std::STANDARD_HELP_VERSION++;
8 my %args;
10 getopts('f:s', \%args);
12 sub VERSION_MESSAGE {
13 # Nothing
16 sub HELP_MESSAGE {
17 print <<EOS
18 This program parses a linker map file, especially one produced when linking an iOS executable.
20 Input is read from a map file provided as command-line argument
22 By default a list of libraries used and the size of code and data
23 linked in from each library is printed, in reverse order of size.
25 The following options are available:
26 -s Print a list of symbols instead.
27 -f 'filter' Filter which libraries are handled. The filter can be
28 a regular expression, typically several library names
29 combined with the '|' operator. Makes sense only when
30 -s is used too.
31 EOS
34 die "The -f switch makes sense only if -s is also used\n" if defined($args{'f'}) && !defined($args{'s'});
36 die "Please provide one map file name\n" if !defined($ARGV[0]);
38 die "Just one argument please\n" if defined($ARGV[1]);
40 my $state = 0;
41 my %libofnumber;
42 my %sizeoflib;
43 my %sizeofsym;
45 open(INPUT, '<', $ARGV[0]) || die "Could not open $ARGV[0]: $!\n";
47 while (<INPUT>) {
48 if ($state == 0 && m!^# Object files:!) {
49 $state = 1;
50 } elsif ($state == 1 && m!^\[ *([0-9]+)\] .*/([-_a-z0-9]+\.a)\(.*!i) {
51 $libofnumber{$1} = $2;
52 } elsif ($state == 1 && m!^# Sections:!) {
53 $state = 2;
54 } elsif ($state == 2 && m!^# Address\s+Size\s+File\s+Name!) {
55 $state = 3;
56 } elsif ($state == 3 && m!^0x[0-9A-F]+\s+(0x[0-9A-F]+)\s+\[ *([0-9]+)\] (.*)!) {
57 my ($size,$libnum,$symbol) = ($1, $2, $3);
58 if (defined($libofnumber{$libnum})) {
59 $sizeoflib{$libofnumber{$libnum}} += hex($size);
60 if (!defined($args{'f'}) || $libofnumber{$libnum} =~ /$args{'f'}/) {
61 $sizeofsym{$symbol} = hex($size);
67 if ($args{'s'}) {
68 # Print symbols in reverse size order
69 foreach (sort { $sizeofsym{$b} <=> $sizeofsym{$a} } keys(%sizeofsym)) {
70 print $_, ": ", $sizeofsym{$_}, "\n";
72 } else {
73 # Print libraries in reverse size order
74 foreach (sort { $sizeoflib{$b} <=> $sizeoflib{$a} } keys(%sizeoflib)) {
75 print $_, ": ", $sizeoflib{$_}, "\n";