xref: /titanic_50/usr/src/lib/libsqlite/tool/memleak2.awk (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1*c5c4113dSnw141292
2*c5c4113dSnw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*c5c4113dSnw141292
4*c5c4113dSnw141292# This AWK script reads the output of testfixture when compiled for memory
5*c5c4113dSnw141292# debugging.  It generates SQL commands that can be fed into an sqlite
6*c5c4113dSnw141292# instance to determine what memory is never freed.  A typical usage would
7*c5c4113dSnw141292# be as follows:
8*c5c4113dSnw141292#
9*c5c4113dSnw141292#     make -f memleak.mk fulltest 2>mem.out
10*c5c4113dSnw141292#     awk -f ../sqlite/tool/memleak2.awk mem.out | ./sqlite :memory:
11*c5c4113dSnw141292#
12*c5c4113dSnw141292# The job performed by this script is the same as that done by memleak.awk.
13*c5c4113dSnw141292# The difference is that this script uses much less memory when the size
14*c5c4113dSnw141292# of the mem.out file is huge.
15*c5c4113dSnw141292#
16*c5c4113dSnw141292BEGIN {
17*c5c4113dSnw141292  print "CREATE TABLE mem(loc INTEGER PRIMARY KEY, src);"
18*c5c4113dSnw141292}
19*c5c4113dSnw141292/[0-9]+ malloc / {
20*c5c4113dSnw141292  print "INSERT INTO mem VALUES(" strtonum($6) ",'" $0 "');"
21*c5c4113dSnw141292}
22*c5c4113dSnw141292/[0-9]+ realloc / {
23*c5c4113dSnw141292  print "INSERT INTO mem VALUES(" strtonum($10) \
24*c5c4113dSnw141292           ",(SELECT src FROM mem WHERE loc=" strtonum($8) "));"
25*c5c4113dSnw141292  print "DELETE FROM mem WHERE loc=" strtonum($8) ";"
26*c5c4113dSnw141292}
27*c5c4113dSnw141292/[0-9]+ free / {
28*c5c4113dSnw141292  print "DELETE FROM mem WHERE loc=" strtonum($6) ";"
29*c5c4113dSnw141292}
30*c5c4113dSnw141292END {
31*c5c4113dSnw141292  print "SELECT src FROM mem;"
32*c5c4113dSnw141292}
33