3 # A script to check that we have as many instance_dispose that instance_init
6 # $1 = input file (debug log)
14 echo "Usage: $0 <logfile> [display_ok=true|false]" 1>&2
17 if [ "$1" = "" ]; then
22 if [ "${2}" = "" ]; then
24 elif [ "${2}" = "display_ok=false" ]; then
26 elif [ "${2}" != "display_ok=true" ]; then
31 tmp1
=/tmp
/$
(basename $0).$$
.1
32 tmp2
=/tmp
/$
(basename $0).$$
.2
33 tmp3
=/tmp
/$
(basename $0).$$
.3
35 \rm
-f /tmp
/$
(basename $0).
*
40 echo /tmp
/$
(basename $0).$$.
${1}
45 typeset ftmp
=$
(getftmp
${1})
51 typeset ftmp
=$
(getftmp
${1})
57 typeset ftmp
=$
(getftmp
${1})
63 typeset ftmp
=$
(getftmp
${1})
69 typeset ftmp
=$
(getftmp
${1})
70 typeset value
=$
(cat ${ftmp})
75 function count_display
77 typeset ftmp
=$
(getftmp
${1})
83 typeset fused
=/tmp
/$
(basename $0).$$.reused
84 typeset triplet
="${1}"
87 typeset used_line
="$(grep -w ${triplet} ${fused} 2>/dev/null)"
88 if [ "${used_line}" = "" ]; then
90 echo "${triplet} ${count}" >> ${fused}
92 count=$(echo ${used_line} | awk '{ print $2 }')
94 grep -v ${triplet} ${fused} > ${fused}.tmp
95 echo "${triplet} ${count}" >> ${fused}.tmp
96 mv ${fused}.tmp
${fused}
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}"
108 grep -En 'instance_init|instance_dispose' ${1} |
grep -vE 'quitting main window|parent=|children=|tree=|deleted=' |
while read line
; do
111 if [ ${count100} -ge 100 ]; then
116 if [ ${count500} -ge 500 ]; then
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.*$//')
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}
136 count=$(wc -l ${tmp1} | awk '{ print $1 }')
137 echo " ${count} readen lines
"
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}
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
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.*$//')
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}
177 # address, reused_count, function_prefix (should identify the class), line_number
179 sortparms
="-k7,7n -k3,3 -k5,5 -k1,1n"
180 cat ${tmp1} | sort ${sortparms} > ${tmp2}
182 #cat ${tmp3} | sort ${sortparms}
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
199 if [ "${line_init}" = "" ]; then
200 addr_init
=$
(echo ${line} |
awk '{ print $3 }')
201 app_init
=$
(echo ${line} |
awk '{ print $5 }')
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"
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
226 echo "- do not record ${class} already counted"
227 count_inc count_undisposed_bis
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}"
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)"