Reference manual: Fix user's manual generation
[nautilus-actions.git] / tools / init-dispose-diff.sh
blobe5ee4b25334cb6dfd316abc2c917f0a87a913b21
1 #!/bin/sh
3 # A script to check that we have as many instance_dispose that instance_init
4 # in our debug traces.
6 # $1 = input file (debug log)
8 #real 6m1.314s
9 #user 0m27.317s
10 #sys 1m28.583s
12 function usage
14 echo "Usage: $0 <logfile> [display_ok=true|false]" 1>&2
17 if [ "$1" = "" ]; then
18 usage
19 exit 1
22 if [ "${2}" = "" ]; then
23 display_ok=1
24 elif [ "${2}" = "display_ok=false" ]; then
25 display_ok=0
26 elif [ "${2}" != "display_ok=true" ]; then
27 usage
28 exit 1
31 tmp1=/tmp/$(basename $0).$$.1
32 tmp2=/tmp/$(basename $0).$$.2
33 tmp3=/tmp/$(basename $0).$$.3
35 \rm -f /tmp/$(basename $0).*
36 echo ""
38 function getftmp
40 echo /tmp/$(basename $0).$$.${1}
43 function str_init
45 typeset ftmp=$(getftmp ${1})
46 echo "" > ${ftmp}
49 function str_grep
51 typeset ftmp=$(getftmp ${1})
52 grep -w $2 ${ftmp}
55 function str_add
57 typeset ftmp=$(getftmp ${1})
58 echo ${2} >>${ftmp}
61 function count_init
63 typeset ftmp=$(getftmp ${1})
64 echo "0">${ftmp}
67 function count_inc
69 typeset ftmp=$(getftmp ${1})
70 typeset value=$(cat ${ftmp})
71 let value+=1
72 echo ${value}>${ftmp}
75 function count_display
77 typeset ftmp=$(getftmp ${1})
78 cat ${ftmp}
81 function is_reused
83 typeset fused=/tmp/$(basename $0).$$.reused
84 typeset triplet="${1}"
85 typeset -i count=0
87 typeset used_line="$(grep -w ${triplet} ${fused} 2>/dev/null)"
88 if [ "${used_line}" = "" ]; then
89 count=1
90 echo "${triplet} ${count}" >> ${fused}
91 else
92 count=$(echo ${used_line} | awk '{ print $2 }')
93 let count+=1
94 grep -v ${triplet} ${fused} > ${fused}.tmp
95 echo "${triplet} ${count}" >> ${fused}.tmp
96 mv ${fused}.tmp ${fused}
99 echo ${count}
102 # get in tmp1 just the list of instance_init/instance_dispose with line numbers
103 # it is kept in run order (line number order)
104 echo -n "Extracting and formatting relevant lines from ${1}"
105 count100=0
106 count500=0
107 total=0
108 grep -En 'instance_init|instance_dispose' ${1} | grep -vE 'quitting main window|parent=|children=|tree=|deleted=' | while read line; do
109 let total+=1
110 let count100+=1
111 if [ ${count100} -ge 100 ]; then
112 echo -n "."
113 count100=0
115 let count500+=1
116 if [ ${count500} -ge 500 ]; then
117 echo -n " ${total}"
118 count500=0
120 numline=$(echo ${line} | cut -d: -f1)
121 #echo "${numline} $(echo ${line} | cut -d' ' -f3-)" >> ${tmp1}
122 #numline=$(echo ${line} | awk '{ print $1 }')
123 fname=$(echo ${line} | awk '{ print $3 }' | sed 's/:$//')
124 address=$(echo ${line} | awk '{ print $4 }' | sed -e 's/.*=//' -e 's/,$//')
125 typename=$(echo ${line} | awk '{ print $5 }' | sed 's/[(),]*//g')
126 [ "${typename}" = "" ] && echo "warning: no type in line ${line}" 1>&2
127 prefix=$(echo ${fname} | sed 's/_instance.*$//')
128 nature=1:init
129 [ "$(echo ${fname} | grep init)" = "" ] && nature=2:disp
130 reused=$(is_reused ${address}-${prefix}-${nature})
131 #echo "address='${address}' fname='${fname}' object='${object}' typename='${typename}' numline='${numline}'" >> ${tmp3}
132 #echo -e "${numline}\t ${fname}\t ${address}\t ${typename}\t ${prefix}\t ${rang}" >> ${tmp3}
133 #echo "${numline} ${fname} ${address} ${typename} ${prefix} ${nature}" >> ${tmp3}
134 echo "${numline} ${fname} ${address} ${typename} ${prefix} ${nature} ${reused}" >> ${tmp1}
135 done
136 count=$(wc -l ${tmp1} | awk '{ print $1 }')
137 echo " ${count} readen lines"
138 #cat ${tmp1}
139 #exit
141 # get in tmp2 the same run-ordered lines, just with line numbers as a separated field
142 #cat ${tmp1} | while read line; do
143 # numline=$(echo ${line} | cut -d: -f1)
144 # echo "${numline} $(echo ${line} | cut -d' ' -f3-)" >> ${tmp2}
145 #done
146 #cat ${tmp2}
147 #exit
149 # get in tmp3 the same population of lines where fields are separated to prepare the sort
150 # fields in the line are yet in the same order as in tmp1 and tmp2 files
151 # 1: numline
152 # 2: function name
153 # 3: object address
154 # (note that the same address may be reused several times in the program)
155 # 4: object type name
156 # (note that instance_init of a base class use the base class name
157 # while the instance_dispose use the type name of the derived class)
158 # 5: radical of function name (e.g. base_application)
159 # 6: an help for the sort
160 #cat ${tmp2} | while read line; do
161 # numline=$(echo ${line} | awk '{ print $1 }')
162 # fname=$(echo ${line} | awk '{ print $2 }' | sed 's/:$//')
163 # address=$(echo ${line} | awk '{ print $3}' | sed -e 's/.*=//' -e 's/,$//')
164 # typename=$(echo ${line} | awk '{ print $4 }' | sed 's/[(),]*//g')
165 # [ "${typename}" = "" ] && echo "warning: no type in line ${line}" 1>&2
166 # prefix=$(echo ${fname} | sed 's/_instance.*$//')
167 # nature=1:init
168 # [ "$(echo ${fname} | grep init)" = "" ] && nature=2:disp
169 # #echo "address='${address}' fname='${fname}' object='${object}' typename='${typename}' numline='${numline}'" >> ${tmp3}
170 # #echo -e "${numline}\t ${fname}\t ${address}\t ${typename}\t ${prefix}\t ${rang}" >> ${tmp3}
171 # #echo "${numline} ${fname} ${address} ${typename} ${prefix} ${nature}" >> ${tmp3}
172 # echo "${numline} ${fname} ${address} ${typename} ${prefix} ${nature}" >> ${tmp3}
173 #done
175 export LC_ALL=C
177 # address, reused_count, function_prefix (should identify the class), line_number
178 echo "Sorting..."
179 sortparms="-k7,7n -k3,3 -k5,5 -k1,1n"
180 cat ${tmp1} | sort ${sortparms} > ${tmp2}
182 #cat ${tmp3} | sort ${sortparms}
183 #exit
185 echo "Apparying..."
186 line_init=""
187 count_init count_ok
188 count_init count_undisposed
189 count_init count_undisposed_bis
190 count_init count_warns
191 str_init list_undisposed
192 cat ${tmp2} | while read line; do
193 nature=$(echo ${line} | awk '{ print $6 }')
194 if [ "${line_init}" = "" -a "${nature}" != "1:init" ]; then
195 echo "warning: unwaited line: ${line}"
196 count_inc count_warns
197 continue
199 if [ "${line_init}" = "" ]; then
200 addr_init=$(echo ${line} | awk '{ print $3 }')
201 app_init=$(echo ${line} | awk '{ print $5 }')
202 line_init="${line}"
203 else
204 addr_dispose=$(echo ${line} | awk '{ print $3 }')
205 app_dispose=$(echo ${line} | awk '{ print $5 }')
206 line_dispose="${line}"
207 if [ "${addr_dispose}" = "${addr_init}" ]; then
208 numline_init=$(echo ${line_init} | awk '{ print $1 }')
209 numline_dispose=$(echo ${line_dispose} | awk '{ print $1 }')
210 type_init=$(echo ${line_init} | awk '{ print $4 }')
211 if [ ${display_ok} -eq 1 ]; then
212 echo "${type_init} ${addr_init} (${numline_init},${numline_dispose}): OK"
214 count_inc count_ok
215 line_init=""
216 else
217 nature=$(echo ${line_dispose} | awk '{ print $6 }')
218 if [ "${nature}" = "1:init" ]; then
219 if [ "$(str_grep list_undisposed ${addr_init})" = "" ]; then
220 class=$(echo ${line_init} | awk '{ print $4 }')
221 num=$(echo ${line_init} | awk '{ print $1 }')
222 echo "- undisposed ${class} at ${addr_init} intialized at line ${num}"
223 str_add list_undisposed ${addr_init}
224 count_inc count_undisposed
225 else
226 echo "- do not record ${class} already counted"
227 count_inc count_undisposed_bis
229 else
230 echo "warning: not apparied line: ${line_init}"
231 count_inc count_warns
233 addr_init=${addr_dispose}
234 app_init=${addr_dispose}
235 line_init="${line_dispose}"
238 done
240 echo ""
241 echo "Objects are OK : $(count_display count_ok)"
242 echo "Undisposed objects: $(count_display count_undisposed) (not re-counted lines: $(count_display count_undisposed_bis))"
243 echo "Other warnings : $(count_display count_warns)"