Updated and new screenshots for Nautilus-Actions Configuration Tool 3.1
[nautilus-actions.git] / tools / init-finalize-diff.sh
blobfa09ee80f6621fa92911baa5fab90400986b3e7a
1 #!/bin/sh
3 # A script to check that we have as many instance_finalize 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] - default to 'false'" 1>&2
17 if [ "$1" = "" ]; then
18 usage
19 exit 1
22 if [ "${2}" = "" ]; then
23 display_ok=0
24 elif [ "${2}" = "display_ok=false" ]; then
25 display_ok=0
26 elif [ "${2}" = "display_ok=true" ]; then
27 display_ok=1
28 else
29 usage
30 exit 1
33 check_for="finalize"
35 tmp1=/tmp/${0##*/}.$$.1
36 tmp2=/tmp/${0##*/}.$$.2
37 tmp3=/tmp/${0##*/}.$$.3
39 \rm -f /tmp/${0##*/}.*
40 echo ""
42 function getftmp
44 echo /tmp/${0##*/}.$$.${1}
47 function str_init
49 typeset ftmp=$(getftmp ${1})
50 echo "" > ${ftmp}
53 function str_grep
55 typeset ftmp=$(getftmp ${1})
56 grep -w $2 ${ftmp}
59 function str_add
61 typeset ftmp=$(getftmp ${1})
62 echo ${2} >>${ftmp}
65 function count_init
67 typeset ftmp=$(getftmp ${1})
68 echo "0">${ftmp}
71 function count_inc
73 typeset ftmp=$(getftmp ${1})
74 typeset value=$(cat ${ftmp})
75 let value+=1
76 echo ${value}>${ftmp}
79 function count_display
81 typeset ftmp=$(getftmp ${1})
82 cat ${ftmp}
85 function is_reused
87 typeset fused=/tmp/${0##*/}.$$.reused
88 typeset triplet="${1}"
89 typeset -i count=0
91 typeset used_line="$(grep -w ${triplet} ${fused} 2>/dev/null)"
92 if [ "${used_line}" = "" ]; then
93 count=1
94 echo "${triplet} ${count}" >> ${fused}
95 else
96 count=$(echo ${used_line} | awk '{ print $2 }')
97 let count+=1
98 grep -v ${triplet} ${fused} > ${fused}.tmp
99 echo "${triplet} ${count}" >> ${fused}.tmp
100 mv ${fused}.tmp ${fused}
103 echo ${count}
106 # get in tmp1 just the list of instance_init/instance_dispose with line numbers
107 # it is kept in run order (input line number order)
108 # note that instance_init on a base class has the base class name
109 # while instance_finalize on this same base class has the derived class name
110 echo -n "Extracting and formatting relevant lines from ${1}"
111 count100=0
112 count500=0
113 total=0
114 grep -En "instance_init|instance_${check_for}" ${1} | grep -vE 'quitting main window|parent=|children=|tree=|deleted=' | while read line; do
115 let total+=1
116 let count100+=1
117 if [ ${count100} -ge 100 ]; then
118 echo -n "."
119 count100=0
121 let count500+=1
122 if [ ${count500} -ge 500 ]; then
123 echo -n " ${total}"
124 count500=0
126 numline=$(echo ${line} | cut -d: -f1)
127 fn_name=$(echo ${line} | awk '{ print $3 }' | sed 's/:$//')
128 obj_address=$(echo ${line} | awk '{ print $4 }' | sed -e 's/.*=//' -e 's/,$//')
129 class=$(echo ${line} | awk '{ print $5 }' | sed 's/[(),]*//g')
130 [ "${class}" = "" ] && echo "warning: no class found in line '${line}'" 1>&2
131 prefix=$(echo ${fn_name} | sed 's/_instance.*$//')
132 nature="1:init"
133 [ "$(echo ${fn_name} | grep instance_init)" = "" ] && nature="2:final"
134 reused=$(is_reused ${obj_address}-${prefix}-${nature})
135 echo "${numline} ${fn_name} ${obj_address} ${class} ${prefix} ${nature} ${reused}" >> ${tmp1}
136 done
137 count=$(wc -l ${tmp1} | awk '{ print $1 }')
138 echo " ${count} lines read"
139 #cat ${tmp1}
140 #exit
142 # sort on: reused_count, object_address, class_name, line_number
143 echo "Sorting..."
144 sortparms="-k7,7n -k3,3 -k5,5 -k1,1n"
145 cat ${tmp1} | LC_ALL=C sort ${sortparms} > ${tmp2}
147 #cat ${tmp3} | sort ${sortparms}
148 #exit
150 echo "Apparying..."
151 line_init=""
152 count_init count_ok
153 count_init count_undisposed
154 count_init count_undisposed_bis
155 count_init count_warns
156 str_init list_undisposed
157 cat ${tmp2} | while read line; do
158 nature=$(echo ${line} | awk '{ print $6 }')
159 if [ "${nature}" = "1:init" ]; then
160 if [ "${line_init}" = "" ]; then
161 # set line init
162 obj_address_init=$(echo ${line} | awk '{ print $3 }')
163 fn_prefix_init=$(echo ${line} | awk '{ print $5 }')
164 line_init="${line}"
165 else
166 # init line being read, but previous was also an init line
167 # say previous was an error
168 # and restart with init line being read
169 class=$(echo ${line_init} | awk '{ print $4 }')
170 if [ "$(str_grep list_undisposed ${obj_address_init})" = "" ]; then
171 num=$(echo ${line_init} | awk '{ print $1 }')
172 echo "- unfinalized ${class} at ${obj_address_init} intialized at line ${num}"
173 str_add list_undisposed ${obj_address_init}
174 count_inc count_undisposed
175 else
176 echo "- do not record ${class} at ${obj_address_init} already counted"
177 count_inc count_undisposed_bis
180 obj_address_init=$(echo ${line} | awk '{ print $3 }')
181 fn_prefix_init=$(echo ${line} | awk '{ print $5 }')
182 line_init="${line}"
184 else
185 if [ "${line_init}" = "" ]; then
186 # dispose line being read but previous was also a dispose line
187 # just signals the dispose line is an error
188 echo "warning: unwaited line: ${line}"
189 count_inc count_warns
190 else
191 # we have an init line, and are reading a dispose line
192 # test if they are for the same object
193 class=$(echo ${line} | awk '{ print $4 }')
194 obj_address_dispose=$(echo ${line} | awk '{ print $3 }')
195 fn_prefix_dispose=$(echo ${line} | awk '{ print $5 }')
196 line_dispose="${line}"
197 if [ "${obj_address_dispose}" = "${obj_address_init}" ]; then
198 numline_init=$(echo ${line_init} | awk '{ print $1 }')
199 numline_dispose=$(echo ${line_dispose} | awk '{ print $1 }')
200 type_init=$(echo ${line_init} | awk '{ print $4 }')
201 if [ ${display_ok} -eq 1 ]; then
202 echo "${type_init} ${addr_init} (${numline_init},${numline_dispose}): OK"
204 count_inc count_ok
205 line_init=""
206 # if they are not for the same object, the two are errors
207 else
208 class=$(echo ${line_init} | awk '{ print $4 }')
209 if [ "$(str_grep list_undisposed ${obj_address_init})" = "" ]; then
210 num=$(echo ${line_init} | awk '{ print $1 }')
211 echo "- unfinalized ${class} at ${obj_address_init} intialized at line ${num}"
212 str_add list_undisposed ${obj_address_init}
213 count_inc count_undisposed
214 else
215 echo "- do not record ${class} at ${obj_address_init} already counted"
216 count_inc count_undisposed_bis
219 echo "warning: unwaited line: ${line}"
220 count_inc count_warns
222 line_init=""
226 echo "${line_init}" > /tmp/${0##*/}.$$.line_init
227 done
228 # does not work because shell variables do not go out of a while loop in bash
229 #if [ "${line_init}" != "" ]; then
230 # class=$(echo ${line_init} | awk '{ print $4 }')
231 # if [ "$(str_grep list_undisposed ${obj_address_init})" = "" ]; then
232 # num=$(echo ${line_init} | awk '{ print $1 }')
233 # echo "- unfinalized ${class} at ${obj_address_init} intialized at line ${num}"
234 # str_add list_undisposed ${obj_address_init}
235 # count_inc count_undisposed
236 # else
237 # echo "- do not record ${class} at ${obj_address_init} already counted"
238 # count_inc count_undisposed_bis
239 # fi
241 line_init="$(cat /tmp/${0##*/}.$$.line_init)"
242 if [ "${line_init}" != "" ]; then
243 obj_address_init=$(echo "${line_init}" | awk '{ print $3 }')
244 class=$(echo "${line_init}" | awk '{ print $4 }')
245 if [ "$(str_grep list_undisposed ${obj_address_init})" = "" ]; then
246 num=$(echo "${line_init}" | awk '{ print $1 }')
247 echo "- unfinalized ${class} at ${obj_address_init} intialized at line ${num}"
248 str_add list_undisposed ${obj_address_init}
249 count_inc count_undisposed
250 else
251 echo "- do not record ${class} at ${obj_address_init} already counted"
252 count_inc count_undisposed_bis
256 echo ""
257 echo "Objects are OK : $(count_display count_ok)"
258 echo "Unfinalized objects: $(count_display count_undisposed) (not re-counted lines: $(count_display count_undisposed_bis))"
259 echo "Other warnings : $(count_display count_warns)"