Home | History | Annotate | Download | only in codesighs
      1 #!/bin/bash
      2 #
      3 # ***** BEGIN LICENSE BLOCK *****
      4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
      5 #
      6 # The contents of this file are subject to the Mozilla Public License Version
      7 # 1.1 (the "License"); you may not use this file except in compliance with
      8 # the License. You may obtain a copy of the License at
      9 # http://www.mozilla.org/MPL/
     10 #
     11 # Software distributed under the License is distributed on an "AS IS" basis,
     12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     13 # for the specific language governing rights and limitations under the
     14 # License.
     15 #
     16 # The Original Code is autosummary.win.bash code, released
     17 # Oct 3, 2002.
     18 #
     19 # The Initial Developer of the Original Code is
     20 # Netscape Communications Corporation.
     21 # Portions created by the Initial Developer are Copyright (C) 2002
     22 # the Initial Developer. All Rights Reserved.
     23 #
     24 # Contributor(s):
     25 #   Garrett Arch Blythe, 03-October-2002
     26 #
     27 # Alternatively, the contents of this file may be used under the terms of
     28 # either the GNU General Public License Version 2 or later (the "GPL"), or
     29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
     30 # in which case the provisions of the GPL or the LGPL are applicable instead
     31 # of those above. If you wish to allow use of your version of this file only
     32 # under the terms of either the GPL or the LGPL, and not to allow others to
     33 # use your version of this file under the terms of the MPL, indicate your
     34 # decision by deleting the provisions above and replace them with the notice
     35 # and other provisions required by the GPL or the LGPL. If you do not delete
     36 # the provisions above, a recipient may use your version of this file under
     37 # the terms of any one of the MPL, the GPL or the LGPL.
     38 #
     39 # ***** END LICENSE BLOCK *****
     40 
     41 #
     42 # Check for optional objdir
     43 # 
     44 if [ "$1" = "-o" ]; then 
     45 OBJROOT="$2"
     46 shift
     47 shift
     48 else
     49 OBJROOT="./mozilla"
     50 fi
     51 
     52 if [ "$1" = "-s" ]; then 
     53 SRCROOT="$2"
     54 shift
     55 shift
     56 else
     57 SRCROOT="./mozilla"
     58 fi
     59 
     60 #
     61 #   A little help for my friends.
     62 #
     63 if [ "-h" == "$1" ];then 
     64     SHOWHELP="1"
     65 fi
     66 if [ "--help" == "$1" ];then 
     67     SHOWHELP="1"
     68 fi
     69 if [ "" == "$1" ]; then
     70     SHOWHELP="1"
     71 fi
     72 if [ "" == "$2" ]; then
     73     SHOWHELP="1"
     74 fi
     75 if [ "" == "$3" ]; then
     76     SHOWHELP="1"
     77 fi
     78 
     79 
     80 #
     81 #   Show the help if required.
     82 #
     83 if [ $SHOWHELP ]; then
     84     echo "usage: $0 <save_results> <old_results> <summary>"
     85     echo "  <save_results> is a file that will receive the results of this run."
     86     echo "    This file can be used in a future run as the old results."
     87     echo "  <old_results> is a results file from a previous run."
     88     echo "    It is used to diff with current results and come up with a summary"
     89     echo "      of changes."
     90     echo "    It is OK if the file does not exist, just supply the argument."
     91     echo "  <summary> is a file which will contain a human readable report."
     92     echo "    This file is most useful by providing more information than the"
     93     echo "      normally single digit output of this script."
     94     echo ""
     95     echo "Run this command from the parent directory of the mozilla tree."
     96     echo ""
     97     echo "This command will output two numbers to stdout that will represent"
     98     echo "  the total size of all code and data, and a delta from the prior."
     99     echo "  the old results."
    100     echo "For much more detail on size drifts refer to the summary report."
    101     echo ""
    102     echo "This tool reports on all executables in the directory tree."
    103     exit
    104 fi
    105 
    106 
    107 #
    108 #   Stash our arguments away.
    109 #
    110 COPYSORTTSV="$1"
    111 OLDTSVFILE="$2"
    112 SUMMARYFILE="$3"
    113 
    114 
    115 #
    116 #   Create our temporary directory.
    117 #
    118 MYTMPDIR=`mktemp -d ./codesighs.tmp.XXXXXXXX`
    119 
    120 
    121 #
    122 #   Find the types of files we are interested in.
    123 #
    124 ONEFINDPASS="$MYTMPDIR/onefind.list"
    125 /usr/bin/find $OBJROOT -type f -name "*.obj" -or -name "*.map" | while read FNAME; do
    126     cygpath -m $FNAME >> $ONEFINDPASS
    127 done
    128 
    129 
    130 #
    131 #   Find all object files.
    132 #
    133 ALLOBJSFILE="$MYTMPDIR/allobjs.list"
    134 grep -i "\.obj$" < $ONEFINDPASS > $ALLOBJSFILE
    135 
    136 
    137 #
    138 #   Get a dump of the symbols in every object file.
    139 #
    140 ALLOBJSYMSFILE="$MYTMPDIR/allobjsyms.list"
    141 xargs -n 1 dumpbin.exe /symbols < $ALLOBJSFILE > $ALLOBJSYMSFILE 2> /dev/null
    142 
    143 
    144 #
    145 #   Produce the symdb for the symbols in all object files.
    146 #
    147 SYMDBFILE="$MYTMPDIR/symdb.tsv"
    148 $OBJROOT/dist/bin/msdump2symdb --input $ALLOBJSYMSFILE | /usr/bin/sort > $SYMDBFILE 2> /dev/null
    149 
    150 
    151 #
    152 #   Find all map files.
    153 #
    154 ALLMAPSFILE="$MYTMPDIR/allmaps.list"
    155 grep -i "\.map$" < $ONEFINDPASS > $ALLMAPSFILE
    156 
    157 
    158 #
    159 #   Produce the TSV output.
    160 #
    161 RAWTSVFILE="$MYTMPDIR/raw.tsv"
    162 $OBJROOT/dist/bin/msmap2tsv --symdb $SYMDBFILE --batch < $ALLMAPSFILE > $RAWTSVFILE 2> /dev/null
    163 
    164 
    165 #
    166 #   Sort the TSV output for useful diffing and eyeballing in general.
    167 #
    168 /usr/bin/sort -r $RAWTSVFILE > $COPYSORTTSV
    169 
    170 
    171 #
    172 #   If a historical file was specified, diff it with our sorted tsv values.
    173 #   Run it through a tool to summaries the diffs to the module
    174 #       level report.
    175 #   Otherwise, generate the module level report from our new data.
    176 #
    177 rm -f $SUMMARYFILE
    178 DIFFFILE="$MYTMPDIR/diff.txt"
    179 if [ -e $OLDTSVFILE ]; then
    180   diff $OLDTSVFILE $COPYSORTTSV > $DIFFFILE
    181   $OBJROOT/dist/bin/maptsvdifftool --negation --input $DIFFFILE | dos2unix >> $SUMMARYFILE
    182 else
    183   $OBJROOT/dist/bin/codesighs --modules --input $COPYSORTTSV | dos2unix >> $SUMMARYFILE
    184 fi
    185 
    186 
    187 #
    188 #   Output our numbers, that will let tinderbox specify everything all
    189 #       at once.
    190 #   First number is in fact the total size of all code and data in the map
    191 #       files parsed.
    192 #   Second number, if present, is growth/shrinkage.
    193 #
    194 
    195 if [ $TINDERBOX_OUTPUT ]; then
    196     echo -n "__codesize:"
    197 fi
    198 $OBJROOT/dist/bin/codesighs --totalonly --input $COPYSORTTSV | dos2unix
    199 
    200 
    201 if [ -e $DIFFFILE ]; then
    202 if [ $TINDERBOX_OUTPUT ]; then
    203     echo -n "__codesizeDiff:"
    204 fi
    205     $OBJROOT/dist/bin/maptsvdifftool --negation --summary --input $DIFFFILE | dos2unix
    206 fi
    207 
    208 #
    209 #   Remove our temporary directory.
    210 #
    211 rm -rf $MYTMPDIR
    212