[email protected] | a89043a | 2009-04-25 13:27:25 | [diff] [blame] | 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 basesummary.linx.bash code, released |
| 17 | # Nov 15, 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, 15-November-2002 |
| 26 | # Simon Fraser <[email protected]> |
| 27 | # |
| 28 | # Alternatively, the contents of this file may be used under the terms of |
| 29 | # either the GNU General Public License Version 2 or later (the "GPL"), or |
| 30 | # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 31 | # in which case the provisions of the GPL or the LGPL are applicable instead |
| 32 | # of those above. If you wish to allow use of your version of this file only |
| 33 | # under the terms of either the GPL or the LGPL, and not to allow others to |
| 34 | # use your version of this file under the terms of the MPL, indicate your |
| 35 | # decision by deleting the provisions above and replace them with the notice |
| 36 | # and other provisions required by the GPL or the LGPL. If you do not delete |
| 37 | # the provisions above, a recipient may use your version of this file under |
| 38 | # the terms of any one of the MPL, the GPL or the LGPL. |
| 39 | # |
| 40 | # ***** END LICENSE BLOCK ***** |
| 41 | |
| 42 | # |
| 43 | # Check for optional objdir |
| 44 | # |
| 45 | if [ "$1" = "-o" ]; then |
| 46 | OBJROOT="$2" |
| 47 | shift |
| 48 | shift |
| 49 | else |
| 50 | OBJROOT="./mozilla" |
| 51 | fi |
| 52 | |
| 53 | if [ "$1" = "-s" ]; then |
| 54 | SRCROOT="$2" |
| 55 | shift |
| 56 | shift |
| 57 | else |
| 58 | SRCROOT="./mozilla" |
| 59 | fi |
| 60 | |
| 61 | OSTYPE=`uname -s` |
| 62 | |
| 63 | if [ $OSTYPE == "Darwin" ]; then |
| 64 | MANIFEST="$SRCROOT/embedding/config/basebrowser-mac-macho" |
| 65 | else |
| 66 | MANIFEST="$SRCROOT/embedding/config/basebrowser-unix" |
| 67 | fi |
| 68 | |
| 69 | # |
| 70 | # A little help for my friends. |
| 71 | # |
| 72 | if [ "-h" == "$1" ];then |
| 73 | SHOWHELP="1" |
| 74 | fi |
| 75 | if [ "--help" == "$1" ];then |
| 76 | SHOWHELP="1" |
| 77 | fi |
| 78 | if [ "" == "$1" ]; then |
| 79 | SHOWHELP="1" |
| 80 | fi |
| 81 | if [ "" == "$2" ]; then |
| 82 | SHOWHELP="1" |
| 83 | fi |
| 84 | if [ "" == "$3" ]; then |
| 85 | SHOWHELP="1" |
| 86 | fi |
| 87 | |
| 88 | |
| 89 | # |
| 90 | # Show the help if required. |
| 91 | # |
| 92 | if [ $SHOWHELP ]; then |
| 93 | echo "usage: $0 <save_results> <old_results> <summary>" |
| 94 | echo " <save_results> is a file that will receive the results of this run." |
| 95 | echo " This file can be used in a future run as the old results." |
| 96 | echo " <old_results> is a results file from a previous run." |
| 97 | echo " It is used to diff with current results and come up with a summary" |
| 98 | echo " of changes." |
| 99 | echo " It is OK if the file does not exist, just supply the argument." |
| 100 | echo " <summary> is a file which will contain a human readable report." |
| 101 | echo " This file is most useful by providing more information than the" |
| 102 | echo " normally single digit output of this script." |
| 103 | echo "" |
| 104 | echo "Run this command from the parent directory of the mozilla tree." |
| 105 | echo "" |
| 106 | echo "This command will output two numbers to stdout that will represent" |
| 107 | echo " the total size of all code and data, and a delta from the prior." |
| 108 | echo " the old results." |
| 109 | echo "For much more detail on size drifts refer to the summary report." |
| 110 | echo "" |
| 111 | echo "This tool reports on executables listed in the following file:" |
| 112 | echo "$MANIFEST" |
| 113 | exit |
| 114 | fi |
| 115 | |
| 116 | |
| 117 | # |
| 118 | # Stash our arguments away. |
| 119 | # |
| 120 | COPYSORTTSV="$1" |
| 121 | OLDTSVFILE="$2" |
| 122 | SUMMARYFILE="$3" |
| 123 | |
| 124 | |
| 125 | # |
| 126 | # On Mac OS X, use the --zerodrift option to maptsvdifftool |
| 127 | # |
| 128 | if [ $OSTYPE == "Darwin" ]; then |
| 129 | ZERODRIFT="--zerodrift" |
| 130 | else |
| 131 | ZERODRIFT="" |
| 132 | fi |
| 133 | |
| 134 | |
| 135 | # |
| 136 | # Create our temporary directory. |
| 137 | # mktemp on Darwin doesn't support -d (suckage) |
| 138 | # |
| 139 | if [ $OSTYPE == "Darwin" ]; then |
| 140 | MYTMPDIR=`mktemp ./codesighs.tmp.XXXXXXXX` |
| 141 | rm $MYTMPDIR |
| 142 | mkdir $MYTMPDIR |
| 143 | else |
| 144 | MYTMPDIR=`mktemp -d ./codesighs.tmp.XXXXXXXX` |
| 145 | fi |
| 146 | |
| 147 | |
| 148 | # Check whether we have 'eu-readelf' or 'readelf' available. |
| 149 | # If we do, it will give more accurate symbol sizes than nm. |
| 150 | |
| 151 | if [ $OSTYPE == "Darwin" ]; then |
| 152 | USE_READELF= |
| 153 | else |
| 154 | READELF_PROG=`which eu-readelf 2>/dev/null | grep /eu-readelf$` |
| 155 | if test "$READELF_PROG"; then |
| 156 | USE_READELF=1 |
| 157 | else |
| 158 | READELF_PROG=`which readelf 2>/dev/null | grep /readelf$` |
| 159 | if test "$READELF_PROG"; then |
| 160 | # Check whether we need -W |
| 161 | if readelf --help | grep "\--wide" >&/dev/null; then |
| 162 | READELF_PROG="readelf -W" |
| 163 | else |
| 164 | READELF_PROG="readelf" |
| 165 | fi |
| 166 | USE_READELF=1 |
| 167 | else |
| 168 | USE_READELF= |
| 169 | fi |
| 170 | fi |
| 171 | fi |
| 172 | |
| 173 | # |
| 174 | # Find all relevant files. |
| 175 | # |
| 176 | ALLFILES="$MYTMPDIR/allfiles.list" |
| 177 | grep -v '[\;\[]' < $MANIFEST | grep -v '^$' | sed "s|^|${OBJROOT}/dist/bin/|" > $ALLFILES |
| 178 | |
| 179 | |
| 180 | RAWTSVFILE="$MYTMPDIR/raw.tsv" |
| 181 | |
| 182 | if test "$USE_READELF"; then |
| 183 | export READELF_PROG |
| 184 | xargs -n 1 $SRCROOT/tools/codesighs/readelf_wrap.pl < $ALLFILES > $RAWTSVFILE |
| 185 | else |
| 186 | |
| 187 | # |
| 188 | # Produce the cumulative nm output. |
| 189 | # We are very particular on what switches to use. |
| 190 | # nm --format=bsd --size-sort --print-file-name --demangle |
| 191 | # |
| 192 | # Darwin (Mac OS X) has a lame nm that we have to wrap in a perl |
| 193 | # script to get decent output. |
| 194 | # |
| 195 | NMRESULTS="$MYTMPDIR/nm.txt" |
| 196 | if [ $OSTYPE == "Darwin" ]; then |
| 197 | xargs -n 1 $SRCROOT/tools/codesighs/nm_wrap_osx.pl < $ALLFILES > $NMRESULTS 2> /dev/null |
| 198 | else |
| 199 | xargs -n 1 nm --format=bsd --size-sort --print-file-name --demangle < $ALLFILES > $NMRESULTS 2> /dev/null |
| 200 | fi |
| 201 | |
| 202 | # |
| 203 | # Produce the TSV output. |
| 204 | # |
| 205 | $OBJROOT/dist/bin/nm2tsv --input $NMRESULTS > $RAWTSVFILE |
| 206 | |
| 207 | fi # USE_READELF |
| 208 | |
| 209 | # |
| 210 | # Sort the TSV output for useful diffing and eyeballing in general. |
| 211 | # |
| 212 | sort -r $RAWTSVFILE > $COPYSORTTSV |
| 213 | |
| 214 | |
| 215 | # |
| 216 | # If a historical file was specified, diff it with our sorted tsv values. |
| 217 | # Run it through a tool to summaries the diffs to the module |
| 218 | # level report. |
| 219 | # Otherwise, generate the module level report from our new data. |
| 220 | # |
| 221 | rm -f $SUMMARYFILE |
| 222 | DIFFFILE="$MYTMPDIR/diff.txt" |
| 223 | if [ -e $OLDTSVFILE ]; then |
| 224 | diff $OLDTSVFILE $COPYSORTTSV > $DIFFFILE |
| 225 | $OBJROOT/dist/bin/maptsvdifftool $ZERODRIFT --input $DIFFFILE >> $SUMMARYFILE |
| 226 | else |
| 227 | $OBJROOT/dist/bin/codesighs --modules --input $COPYSORTTSV >> $SUMMARYFILE |
| 228 | fi |
| 229 | |
| 230 | |
| 231 | # |
| 232 | # Output our numbers, that will let tinderbox specify everything all |
| 233 | # at once. |
| 234 | # First number is in fact the total size of all code and data in the map |
| 235 | # files parsed. |
| 236 | # Second number, if present, is growth/shrinkage. |
| 237 | # |
| 238 | |
| 239 | if [ $TINDERBOX_OUTPUT ]; then |
| 240 | echo -n "__codesize:" |
| 241 | fi |
| 242 | $OBJROOT/dist/bin/codesighs --totalonly --input $COPYSORTTSV |
| 243 | |
| 244 | if [ -e $DIFFFILE ]; then |
| 245 | if [ $TINDERBOX_OUTPUT ]; then |
| 246 | echo -n "__codesizeDiff:" |
| 247 | fi |
| 248 | $OBJROOT/dist/bin/maptsvdifftool $ZERODRIFT --summary --input $DIFFFILE |
| 249 | fi |
| 250 | |
| 251 | # |
| 252 | # Remove our temporary directory. |
| 253 | # |
| 254 | rm -rf $MYTMPDIR |