/ Hex Artifact Content
Login

Artifact 9cc20c8e8f3c675efac71ea0721ee6874a1566e8:


0000: 23 20 54 68 69 73 20 41 57 4b 20 73 63 72 69 70  # This AWK scrip
0010: 74 20 72 65 61 64 73 20 74 68 65 20 6f 75 74 70  t reads the outp
0020: 75 74 20 6f 66 20 74 65 73 74 66 69 78 74 75 72  ut of testfixtur
0030: 65 20 77 68 65 6e 20 63 6f 6d 70 69 6c 65 64 20  e when compiled 
0040: 66 6f 72 20 6d 65 6d 6f 72 79 0a 23 20 64 65 62  for memory.# deb
0050: 75 67 67 69 6e 67 2e 20 20 49 74 20 67 65 6e 65  ugging.  It gene
0060: 72 61 74 65 73 20 53 51 4c 20 63 6f 6d 6d 61 6e  rates SQL comman
0070: 64 73 20 74 68 61 74 20 63 61 6e 20 62 65 20 66  ds that can be f
0080: 65 64 20 69 6e 74 6f 20 61 6e 20 73 71 6c 69 74  ed into an sqlit
0090: 65 20 0a 23 20 69 6e 73 74 61 6e 63 65 20 74 6f  e .# instance to
00a0: 20 64 65 74 65 72 6d 69 6e 65 20 77 68 61 74 20   determine what 
00b0: 6d 65 6d 6f 72 79 20 69 73 20 6e 65 76 65 72 20  memory is never 
00c0: 66 72 65 65 64 2e 20 20 41 20 74 79 70 69 63 61  freed.  A typica
00d0: 6c 20 75 73 61 67 65 20 77 6f 75 6c 64 0a 23 20  l usage would.# 
00e0: 62 65 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 23  be as follows:.#
00f0: 0a 23 20 20 20 20 20 6d 61 6b 65 20 2d 66 20 6d  .#     make -f m
0100: 65 6d 6c 65 61 6b 2e 6d 6b 20 66 75 6c 6c 74 65  emleak.mk fullte
0110: 73 74 20 32 3e 6d 65 6d 2e 6f 75 74 0a 23 20 20  st 2>mem.out.#  
0120: 20 20 20 61 77 6b 20 2d 66 20 2e 2e 2f 73 71 6c     awk -f ../sql
0130: 69 74 65 2f 74 6f 6f 6c 2f 6d 65 6d 6c 65 61 6b  ite/tool/memleak
0140: 32 2e 61 77 6b 20 6d 65 6d 2e 6f 75 74 20 7c 20  2.awk mem.out | 
0150: 2e 2f 73 71 6c 69 74 65 20 3a 6d 65 6d 6f 72 79  ./sqlite :memory
0160: 3a 0a 23 0a 23 20 54 68 65 20 6a 6f 62 20 70 65  :.#.# The job pe
0170: 72 66 6f 72 6d 65 64 20 62 79 20 74 68 69 73 20  rformed by this 
0180: 73 63 72 69 70 74 20 69 73 20 74 68 65 20 73 61  script is the sa
0190: 6d 65 20 61 73 20 74 68 61 74 20 64 6f 6e 65 20  me as that done 
01a0: 62 79 20 6d 65 6d 6c 65 61 6b 2e 61 77 6b 2e 0a  by memleak.awk..
01b0: 23 20 54 68 65 20 64 69 66 66 65 72 65 6e 63 65  # The difference
01c0: 20 69 73 20 74 68 61 74 20 74 68 69 73 20 73 63   is that this sc
01d0: 72 69 70 74 20 75 73 65 73 20 6d 75 63 68 20 6c  ript uses much l
01e0: 65 73 73 20 6d 65 6d 6f 72 79 20 77 68 65 6e 20  ess memory when 
01f0: 74 68 65 20 73 69 7a 65 0a 23 20 6f 66 20 74 68  the size.# of th
0200: 65 20 6d 65 6d 2e 6f 75 74 20 66 69 6c 65 20 69  e mem.out file i
0210: 73 20 68 75 67 65 2e 0a 23 0a 42 45 47 49 4e 20  s huge..#.BEGIN 
0220: 7b 0a 20 20 70 72 69 6e 74 20 22 43 52 45 41 54  {.  print "CREAT
0230: 45 20 54 41 42 4c 45 20 6d 65 6d 28 6c 6f 63 20  E TABLE mem(loc 
0240: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
0250: 4b 45 59 2c 20 73 72 63 29 3b 22 0a 7d 0a 2f 5b  KEY, src);".}./[
0260: 30 2d 39 5d 2b 20 6d 61 6c 6c 6f 63 20 2f 20 7b  0-9]+ malloc / {
0270: 0a 20 20 70 72 69 6e 74 20 22 49 4e 53 45 52 54  .  print "INSERT
0280: 20 49 4e 54 4f 20 6d 65 6d 20 56 41 4c 55 45 53   INTO mem VALUES
0290: 28 22 20 73 74 72 74 6f 6e 75 6d 28 24 36 29 20  (" strtonum($6) 
02a0: 22 2c 27 22 20 24 30 20 22 27 29 3b 22 0a 7d 0a  ",'" $0 "');".}.
02b0: 2f 5b 30 2d 39 5d 2b 20 72 65 61 6c 6c 6f 63 20  /[0-9]+ realloc 
02c0: 2f 20 7b 0a 20 20 70 72 69 6e 74 20 22 49 4e 53  / {.  print "INS
02d0: 45 52 54 20 49 4e 54 4f 20 6d 65 6d 20 56 41 4c  ERT INTO mem VAL
02e0: 55 45 53 28 22 20 73 74 72 74 6f 6e 75 6d 28 24  UES(" strtonum($
02f0: 31 30 29 20 5c 0a 20 20 20 20 20 20 20 20 20 20  10) \.          
0300: 20 22 2c 28 53 45 4c 45 43 54 20 73 72 63 20 46   ",(SELECT src F
0310: 52 4f 4d 20 6d 65 6d 20 57 48 45 52 45 20 6c 6f  ROM mem WHERE lo
0320: 63 3d 22 20 73 74 72 74 6f 6e 75 6d 28 24 38 29  c=" strtonum($8)
0330: 20 22 29 29 3b 22 0a 20 20 70 72 69 6e 74 20 22   "));".  print "
0340: 44 45 4c 45 54 45 20 46 52 4f 4d 20 6d 65 6d 20  DELETE FROM mem 
0350: 57 48 45 52 45 20 6c 6f 63 3d 22 20 73 74 72 74  WHERE loc=" strt
0360: 6f 6e 75 6d 28 24 38 29 20 22 3b 22 0a 7d 0a 2f  onum($8) ";".}./
0370: 5b 30 2d 39 5d 2b 20 66 72 65 65 20 2f 20 7b 0a  [0-9]+ free / {.
0380: 20 20 70 72 69 6e 74 20 22 44 45 4c 45 54 45 20    print "DELETE 
0390: 46 52 4f 4d 20 6d 65 6d 20 57 48 45 52 45 20 6c  FROM mem WHERE l
03a0: 6f 63 3d 22 20 73 74 72 74 6f 6e 75 6d 28 24 36  oc=" strtonum($6
03b0: 29 20 22 3b 22 0a 7d 0a 45 4e 44 20 7b 0a 20 20  ) ";".}.END {.  
03c0: 70 72 69 6e 74 20 22 53 45 4c 45 43 54 20 73 72  print "SELECT sr
03d0: 63 20 46 52 4f 4d 20 6d 65 6d 3b 22 0a 7d 0a     c FROM mem;".}.