xref: /aosp_15_r20/external/e2fsprogs/e2fsck/mtrace.awk (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker#!/usr/bin/awk -f
2*6a54128fSAndroid Build Coastguard Worker#
3*6a54128fSAndroid Build Coastguard Worker#  Awk program to analyze mtrace.c output.
4*6a54128fSAndroid Build Coastguard Worker#
5*6a54128fSAndroid Build Coastguard Worker$1 == "+"	{ if (allocated[$2] != "")
6*6a54128fSAndroid Build Coastguard Worker		    print "+", $2, "Alloc", NR, "duplicate:", allocated[$2];
7*6a54128fSAndroid Build Coastguard Worker		  else
8*6a54128fSAndroid Build Coastguard Worker		    allocated[$2] = $3;
9*6a54128fSAndroid Build Coastguard Worker		}
10*6a54128fSAndroid Build Coastguard Worker$1 == "-"	{ if (allocated[$2] != "") {
11*6a54128fSAndroid Build Coastguard Worker		    allocated[$2] = "";
12*6a54128fSAndroid Build Coastguard Worker		    if (allocated[$2] != "")
13*6a54128fSAndroid Build Coastguard Worker			print "DELETE FAILED", $2, allocated[$2];
14*6a54128fSAndroid Build Coastguard Worker		  } else
15*6a54128fSAndroid Build Coastguard Worker		    print "-", $2, "Free", NR, "was never alloc'd";
16*6a54128fSAndroid Build Coastguard Worker		}
17*6a54128fSAndroid Build Coastguard Worker$1 == "<"	{ if (allocated[$2] != "")
18*6a54128fSAndroid Build Coastguard Worker		    allocated[$2] = "";
19*6a54128fSAndroid Build Coastguard Worker		  else
20*6a54128fSAndroid Build Coastguard Worker		    print "-", $2, "Realloc", NR, "was never alloc'd";
21*6a54128fSAndroid Build Coastguard Worker		}
22*6a54128fSAndroid Build Coastguard Worker$1 == ">"	{ if (allocated[$2] != "")
23*6a54128fSAndroid Build Coastguard Worker		    print "+", $2, "Realloc", NR, "duplicate:", allocated[$2];
24*6a54128fSAndroid Build Coastguard Worker		  else
25*6a54128fSAndroid Build Coastguard Worker		    allocated[$2] = $3;
26*6a54128fSAndroid Build Coastguard Worker		}
27*6a54128fSAndroid Build Coastguard Worker
28*6a54128fSAndroid Build Coastguard Worker# Ignore "= Start"
29*6a54128fSAndroid Build Coastguard Worker$1 == "="	{ }
30*6a54128fSAndroid Build Coastguard Worker# Ignore failed realloc attempts for now
31*6a54128fSAndroid Build Coastguard Worker$1 == "!"	{ }
32*6a54128fSAndroid Build Coastguard Worker
33*6a54128fSAndroid Build Coastguard Worker
34*6a54128fSAndroid Build Coastguard WorkerEND		{ for (x in allocated)
35*6a54128fSAndroid Build Coastguard Worker		    if (allocated[x] != "")
36*6a54128fSAndroid Build Coastguard Worker		      print "+", x, allocated[x];
37*6a54128fSAndroid Build Coastguard Worker		}
38