- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / codesighs / basesummary.win.bash
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.win.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 #
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 #
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 MANIFEST="$SRCROOT/embedding/config/basebrowser-win"
62
63 #
64 #   A little help for my friends.
65 #
66 if [ "-h" == "$1" ];then 
67     SHOWHELP="1"
68 fi
69 if [ "--help" == "$1" ];then 
70     SHOWHELP="1"
71 fi
72 if [ "" == "$1" ]; then
73     SHOWHELP="1"
74 fi
75 if [ "" == "$2" ]; then
76     SHOWHELP="1"
77 fi
78 if [ "" == "$3" ]; then
79     SHOWHELP="1"
80 fi
81
82
83 #
84 #   Show the help if required.
85 #
86 if [ $SHOWHELP ]; then
87     echo "usage: $0 <save_results> <old_results> <summary>"
88     echo "  <save_results> is a file that will receive the results of this run."
89     echo "    This file can be used in a future run as the old results."
90     echo "  <old_results> is a results file from a previous run."
91     echo "    It is used to diff with current results and come up with a summary"
92     echo "      of changes."
93     echo "    It is OK if the file does not exist, just supply the argument."
94     echo "  <summary> is a file which will contain a human readable report."
95     echo "    This file is most useful by providing more information than the"
96     echo "      normally single digit output of this script."
97     echo ""
98     echo "Run this command from the parent directory of the mozilla tree."
99     echo ""
100     echo "This command will output two numbers to stdout that will represent"
101     echo "  the total size of all code and data, and a delta from the prior."
102     echo "  the old results."
103     echo "For much more detail on size drifts refer to the summary report."
104     echo ""
105     echo "This tool reports on executables listed in the following file:"
106     echo "$MANIFEST"
107     exit
108 fi
109
110
111 #
112 #   Stash our arguments away.
113 #
114 COPYSORTTSV="$1"
115 OLDTSVFILE="$2"
116 SUMMARYFILE="$3"
117
118
119 #
120 #   Create our temporary directory.
121 #
122 MYTMPDIR=`mktemp -d ./codesighs.tmp.XXXXXXXX`
123
124
125 #
126 #   Find the types of files we are interested in.
127 #
128 ONEFINDPASS="$MYTMPDIR/onefind.list"
129 /usr/bin/find $OBJROOT -type f -name "*.obj" -or -name "*.map" | while read FNAME; do
130     cygpath -m $FNAME >> $ONEFINDPASS
131 done
132
133
134 #
135 #   Find all object files.
136 #
137 ALLOBJSFILE="$MYTMPDIR/allobjs.list"
138 grep -i "\.obj$" < $ONEFINDPASS > $ALLOBJSFILE
139
140
141 #
142 #   Get a dump of the symbols in every object file.
143 #
144 ALLOBJSYMSFILE="$MYTMPDIR/allobjsyms.list"
145 xargs -n 1 dumpbin.exe /symbols < $ALLOBJSFILE > $ALLOBJSYMSFILE 2> /dev/null
146
147
148 #
149 #   Produce the symdb for the symbols in all object files.
150 #
151 SYMDBFILE="$MYTMPDIR/symdb.tsv"
152 $OBJROOT/dist/bin/msdump2symdb --input $ALLOBJSYMSFILE | /usr/bin/sort > $SYMDBFILE 2> /dev/null
153
154
155 #
156 #   Find all map files.
157 #
158 ALLMAPSFILE="$MYTMPDIR/allmaps.list"
159 grep -i "\.map$" < $ONEFINDPASS > $ALLMAPSFILE
160
161
162 #
163 #   Figure out which modules in specific we care about.
164 #   The relevant set meaning that the map file name prefix must be found
165 #       in the file mozilla/embedding/config/basebrowser-win.
166 #
167 RELEVANTSETFILE="$MYTMPDIR/relevant.set"
168 grep -v '\;' < $MANIFEST | sed 's/.*\\//' | grep '\.[eEdD][xXlL][eElL]' | sed 's/\.[eEdD][xXlL][eElL]//' > $RELEVANTSETFILE
169 RELEVANTARG=`xargs -n 1 echo --match-module < $RELEVANTSETFILE`
170
171
172 #
173 #   Produce the TSV output.
174 #
175 RAWTSVFILE="$MYTMPDIR/raw.tsv"
176 $OBJROOT/dist/bin/msmap2tsv --symdb $SYMDBFILE --batch $RELEVANTARG < $ALLMAPSFILE > $RAWTSVFILE 2> /dev/null
177
178
179 #
180 #   Sort the TSV output for useful diffing and eyeballing in general.
181 #
182 /usr/bin/sort -r $RAWTSVFILE > $COPYSORTTSV
183
184
185 #
186 #   If a historical file was specified, diff it with our sorted tsv values.
187 #   Run it through a tool to summaries the diffs to the module
188 #       level report.
189 #   Otherwise, generate the module level report from our new data.
190 #
191 rm -f $SUMMARYFILE
192 DIFFFILE="$MYTMPDIR/diff.txt"
193 if [ -e $OLDTSVFILE ]; then
194   diff $OLDTSVFILE $COPYSORTTSV > $DIFFFILE
195   $OBJROOT/dist/bin/maptsvdifftool --negation --input $DIFFFILE | dos2unix >> $SUMMARYFILE
196 else
197   $OBJROOT/dist/bin/codesighs --modules --input $COPYSORTTSV | dos2unix >> $SUMMARYFILE
198 fi
199
200
201 #
202 #   Output our numbers, that will let tinderbox specify everything all
203 #       at once.
204 #   First number is in fact the total size of all code and data in the map
205 #       files parsed.
206 #   Second number, if present, is growth/shrinkage.
207 #
208
209 if [ $TINDERBOX_OUTPUT ]; then
210     echo -n "__codesize:"
211 fi
212 $OBJROOT/dist/bin/codesighs --totalonly --input $COPYSORTTSV | dos2unix
213
214 if [ -e $DIFFFILE ]; then
215 if [ $TINDERBOX_OUTPUT ]; then
216     echo -n "__codesizeDiff:"
217 fi
218     $OBJROOT/dist/bin/maptsvdifftool --negation --summary --input $DIFFFILE | dos2unix
219 fi
220
221 #
222 #   Remove our temporary directory.
223 #
224 rm -rf $MYTMPDIR