Debian Codegraph @

tools/graph_lockdep_chains

raw symbols SCIP
1 #! /bin/shscip-shell filesystem . . `/bin/sh`.
2 progname="${0##*/}"
3 progname="${progname%.sh}"
4
5 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage().() {
6 echoscip-shell system . . echo. "Host side filter pipeline tool to convert kernel /proc/lockdep_chains via"
7 echoscip-shell system . . echo. "graphviz into dependency chart for visualization. Watch out for any up-arrows"
8 echoscip-shell system . . echo. "as they signify a circular dependency."
9 echoscip-shell system . . echo.
10 echoscip-shell system . . echo. "Usage: ${progname} [flags...] [regex...] < input-file > output-file"
11 echoscip-shell system . . echo.
12 echoscip-shell system . . echo. "flags:"
13 echoscip-shell system . . echo. " --format={png|ps|svg|fig|imap|cmapx} | -T<format>"
14 echoscip-shell system . . echo. " Output format, default png"
15 echoscip-shell system . . echo. " --debug | -d"
16 echoscip-shell system . . echo. " Leave intermediate files /tmp/${progname}.*"
17 echoscip-shell system . . echo. " --verbose | -v"
18 echoscip-shell system . . echo. " Do not strip address from lockname"
19 echoscip-shell system . . echo. " --focus | -f"
20 echoscip-shell system . . echo. " Show only primary references for regex matches"
21 echoscip-shell system . . echo. " --cluster"
22 echoscip-shell system . . echo. " Cluster the primary references for regex matches"
23 echoscip-shell system . . echo. " --serial=<serial> | -s <serial>"
24 echoscip-shell system . . echo. " Input from 'adb -s <serial> shell su 0 cat /proc/lockdep_chains'"
25 echoscip-shell system . . echo. " --input=<filename> | -i <filename>"
26 echoscip-shell system . . echo. " Input lockdeps from filename, otherwise from standard in"
27 echoscip-shell system . . echo. " --output=<filename> | -o <filename>"
28 echoscip-shell system . . echo. " Output formatted graph to filename, otherwise to standard out"
29 echoscip-shell system . . echo.
30 echoscip-shell system . . echo. "Chart is best viewed in portrait. ps or pdf formats tend to pixelate. png tends"
31 echoscip-shell system . . echo. "to hit a bug in cairo rendering at scale. Not having a set of regex matches for"
32 echoscip-shell system . . echo. "locknames will probably give you what you deserve ..."
33 echoscip-shell system . . echo.
34 echoscip-shell system . . echo. "Kernel Prerequisite to get /proc/lockdep_chains:"
35 echoscip-shell system . . echo. " CONFIG_PROVE_LOCKING=y"
36 echoscip-shell system . . echo. " CONFIG_LOCK_STAT=y"
37 echoscip-shell system . . echo. " CONFIG_DEBUG_LOCKDEP=y"
38 }
39
40 rmscip-shell system . . rm. -f /tmp/${progname}.*
41
42 # Indent rules and strip out address (may be overridden below)
43 beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify().() {
44 sedscip-shell system . . sed. 's/^./ &/
45 s/"[[][0-9a-f]*[]] /"/g'
46 }
47
48 input="cat -"
49 output="cat -"
50
51 dot_format="-Tpng"
52 filter=
53 debug=
54 focus=
55 cluster=
56
57 while [scip-shell system . . `[`. ${#} -gt 0 ]; do
58 case ${1} in
59
60 -T | --format)
61 dot_format="-T${2}"
62 shift
63 ;;
64
65 -T*)
66 dot_format="${1}"
67 ;;
68
69 --format=*)
70 dot_format="-T${1#--format=}"
71 ;;
72
73 --debug | -d)
74 debug=1
75 ;;
76
77 --verbose | -v)
78 # indent, but do _not_ strip out addresses
79 beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify().() {
80 sedscip-shell system . . sed. 's/^./ &/'
81 }
82 ;;
83
84 --focus | -f | --primary) # reserving --primary
85 focus=1
86 ;;
87
88 --secondary) # reserving --secondary
89 focus=
90 ;;
91
92 --cluster) # reserve -c for dot (configure plugins)
93 cluster=1
94 ;;
95
96 --serial | -s)
97 if [scip-shell system . . `[`. "${input}" != "cat -" ]; then
98 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage(). >&2
99 echoscip-shell system . . echo. "ERROR: --input or --serial can only be specified once" >&2
100 exit 1
101 fi
102 input="adb -s ${2} shell su 0 cat /proc/lockdep_chains"
103 shift
104 ;;
105
106 --serial=*)
107 input="adb -s ${1#--serial=} shell su 0 cat /proc/lockdep_chains"
108 ;;
109
110 --input | -i)
111 if [scip-shell system . . `[`. "${input}" != "cat -" ]; then
112 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage(). >&2
113 echoscip-shell system . . echo. "ERROR: --input or --serial can only be specified once" >&2
114 exit 1
115 fi
116 input="cat ${2}"
117 shift
118 ;;
119
120 --input=*)
121 if [scip-shell system . . `[`. "${input}" != "cat -" ]; then
122 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage(). >&2
123 echoscip-shell system . . echo. "ERROR: --input or --serial can only be specified once" >&2
124 exit 1
125 fi
126 input="cat ${1#--input=}"
127 ;;
128
129 --output | -o)
130 if [scip-shell system . . `[`. "${output}" != "cat -" ]; then
131 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage(). >&2
132 echoscip-shell system . . echo. "ERROR: --output can only be specified once" >&2
133 exit 1
134 fi
135 output="cat - > ${2}" # run through eval
136 shift
137 ;;
138
139 --output=*)
140 if [scip-shell system . . `[`. "${output}" != "cat -" ]; then
141 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage(). >&2
142 echoscip-shell system . . echo. "ERROR: --output can only be specified once" >&2
143 exit 1
144 fi
145 output="cat - > ${1#--output=}" # run through eval
146 ;;
147
148 --help | -h | -\?)
149 usagescip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 usage().
150 exit
151 ;;
152
153 *)
154 # Everything else is a filter, which will also hide bad option flags,
155 # which is an as-designed price we pay to allow "->rwlock" for instance.
156 if [scip-shell system . . `[`. X"${1}" = X"${1#* }" ]; then
157 if [scip-shell system . . `[`. -z "${filter}" ]; then
158 filter="${1}"
159 else
160 filter="${filter}|${1}"
161 fi
162 else
163 if [scip-shell system . . `[`. -z "${filter}" ]; then
164 filter=" ${1}"
165 else
166 filter="${filter}| ${1}"
167 fi
168 fi
169 ;;
170
171 esac
172 shift
173 done
174
175 if [scip-shell system . . `[`. -z "${filter}" ]; then
176 echoscip-shell system . . echo. "WARNING: no regex specified will give you what you deserve!" >&2
177 fi
178 if [scip-shell system . . `[`. -n "${focus}" -a -z "${filter}" ]; then
179 echoscip-shell system . . echo. "WARNING: --focus without regex, ignored" >&2
180 fi
181 if [scip-shell system . . `[`. -n "${cluster}" -a -z "${filter}" ]; then
182 echoscip-shell system . . echo. "WARNING: --cluster without regex, ignored" >&2
183 fi
184 if [scip-shell system . . `[`. -n "${cluster}" -a -n "${focus}" -a -n "${filter}" ]; then
185 echoscip-shell system . . echo. "WARNING: orthogonal options --cluster & --focus, ignoring --cluster" >&2
186 cluster=
187 fi
188
189 # convert to dot digraph series
190 ${input} |
191 sedscip-shell system . . sed. '/^all lock chains:$/d
192 / [&]__lockdep_no_validate__$/d
193 /irq_context: 0/d
194 s/irq_context: [1-9]/irq_context/
195 s/..*/"&" ->/
196 s/^$/;/' |
197 sedscip-shell system . . sed. ': loop
198 N
199 s/ ->\n;$/ ;/
200 t
201 s/ ->\n/ -> /
202 b loop' > /tmp/${progname}.formed
203
204 if [scip-shell system . . `[`. ! -s /tmp/${progname}.formed ]; then
205 echoscip-shell system . . echo. "ERROR: no input" >&2
206 if [scip-shell system . . `[`. -z "${debug}" ]; then
207 rmscip-shell system . . rm. -f /tmp/${progname}.*
208 fi
209 exit 2
210 fi
211
212 if [scip-shell system . . `[`. -n "${filter}" ]; then
213 grepscip-shell system . . grep. "${filter}" /tmp/${progname}.formed |
214 sedscip-shell system . . sed. 's/ ;//
215 s/ -> /|/g' |
216 trscip-shell system . . tr. '|' '\n' |
217 sortscip-shell system . . sort. -u > /tmp/${progname}.symbols
218 fi
219
220 (
221 echoscip-shell system . . echo. 'digraph G {'
222 (
223 echoscip-shell system . . echo. 'remincross="true";'
224 echoscip-shell system . . echo. 'concentrate="true";'
225 echoscip-shell system . . echo.
226
227 if [scip-shell system . . `[`. -s /tmp/${progname}.symbols ]; then
228 if [scip-shell system . . `[`. -n "${cluster}" ]; then
229 echoscip-shell system . . echo. 'subgraph cluster_symbols {'
230 (
231 grepscip-shell system . . grep. "${filter}" /tmp/${progname}.symbols |
232 sedscip-shell system . . sed. 's/.*/& [shape=box] ;/'
233 grepscip-shell system . . grep. -v "${filter}" /tmp/${progname}.symbols |
234 sedscip-shell system . . sed. 's/.*/& [shape=diamond] ;/'
235 ) | beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify().
236 echoscip-shell system . . echo. '}'
237 else
238 grepscip-shell system . . grep. "${filter}" /tmp/${progname}.symbols |
239 sedscip-shell system . . sed. 's/.*/& [shape=box] ;/'
240 grepscip-shell system . . grep. -v "${filter}" /tmp/${progname}.symbols |
241 sedscip-shell system . . sed. 's/.*/& [shape=diamond] ;/'
242 fi
243
244 echoscip-shell system . . echo.
245 fi
246 ) | beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify().
247
248 if [scip-shell system . . `[`. -s /tmp/${progname}.symbols ]; then
249 if [scip-shell system . . `[`. -z "${focus}" ]; then
250 # Secondary relationships
251 fgrepscip-shell system . . fgrep. -f /tmp/${progname}.symbols /tmp/${progname}.formed
252 else
253 # Focus only on primary relationships
254 grepscip-shell system . . grep. "${filter}" /tmp/${progname}.formed
255 fi
256 else
257 catscip-shell system . . cat. /tmp/${progname}.formed
258 fi |
259 # optimize int A -> B ; single references
260 sedscip-shell system . . sed. 's/\("[^"]*"\) -> \("[^"]*"\) ->/\1 -> \2 ;|\2 ->/g' |
261 sedscip-shell system . . sed. 's/\("[^"]*"\) -> \("[^"]*"\) ->/\1 -> \2 ;|\2 ->/g' |
262 trscip-shell system . . tr. '|' '\n' |
263 beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify(). |
264 grepscip-shell system . . grep. ' -> ' |
265 sortscip-shell system . . sort. -u |
266 if [scip-shell system . . `[`. -s /tmp/${progname}.symbols ]; then
267 beautifyscip-shell shell android-platform-system-extras 10.0.0+r36+ds-2.1 beautify(). < /tmp/${progname}.symbols |
268 sedscip-shell system . . sed. 's/^ */ /' > /tmp/${progname}.short
269 teescip-shell system . . tee. /tmp/${progname}.split |
270 fgrepscip-shell system . . fgrep. -f /tmp/${progname}.short |
271 sedscip-shell system . . sed. 's/ ;$/ [color=red] ;/'
272 fgrepscip-shell system . . fgrep. -v -f /tmp/${progname}.short /tmp/${progname}.split
273 rmscip-shell system . . rm. -f /tmp/${progname}.short /tmp/${progname}.split
274 else
275 catscip-shell system . . cat. -
276 fi
277
278 echoscip-shell system . . echo. '}'
279 ) |
280 teescip-shell system . . tee. /tmp/${progname}.input |
281 if dot ${dot_format} && [scip-shell system . . `[`. -z "${debug}" ]; then
282 rmscip-shell system . . rm. -f /tmp/${progname}.*
283 fi |
284 eval ${output}