Commit Diff


commit - 601f42667bb4b969a0d85090c28c53c445681b20
commit + a9b4e7601cbf521026dbc67adabc41e54cc9fc50
blob - c7d69705cf53531a05d97d641404660df1c3016e
blob + e5501eed5fb859a9ec85c5172f296884f5716946
--- README.md
+++ README.md
@@ -11,22 +11,77 @@ Run with: `python3 memtrace.py /dev/cu.XXXXX 115200`
 
 The script auto-resets the counts and output looks like:
 ```
-HEAP 0: 
-heap_start : 0x20002950
-heap_end   : 0x20003600
-heap_size  : 3248
-[F:3248] 
-mb_total_free : 3248
+>> RESET HEAP COUNTERS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+   (NUM)    TOTAL [ ADDRESS] CHANGE  (COMMENT)
+[F:3760] 
+mb_total_free : 3760
 mb_total_used : 0
-== (001)       56 [20002954] +56     (malloc: ALLOCATED: 56 [0x20002954])
-== (002)       76 [20002990] +20     (malloc: ALLOCATED: 20 [0x20002990])
-== (003)      124 [200029a8] +48     (malloc: ALLOCATED: 48 [0x200029a8])
-...
-== (032)     1254 [20002e50] -18     (free:   0x20002e50)
-== (031)     1229 [20002ea8] -25     (free:   0x20002ea8)
-== (030)     1209 [20002e90] -20     (free:   0x20002e90)
-...
-Calliope Accelerometer Test v1.0
+== (001)     3704 [20002954] +56     (malloc: ALLOCATED: 56 [0x20002954])
+== (002)     3684 [20002990] +20     (malloc: ALLOCATED: 20 [0x20002990])
+== (003)     3636 [200029a8] +48     (malloc: ALLOCATED: 48 [0x200029a8])
+== (004)     3620 [200029dc] +16     (malloc: ALLOCATED: 16 [0x200029dc])
+== (005)     3580 [200029f0] +40     (malloc: ALLOCATED: 40 [0x200029f0])
+== (006)     3556 [20002a1c] +24     (malloc: ALLOCATED: 24 [0x20002a1c])
+== (007)     3516 [20002a38] +40     (malloc: ALLOCATED: 40 [0x20002a38])
+== (008)     3492 [20002a64] +24     (malloc: ALLOCATED: 24 [0x20002a64])
+== (009)     3484 [20002a80] +8      (malloc: ALLOCATED: 8 [0x20002a80])
+== (010)     3476 [20002a8c] +8      (malloc: ALLOCATED: 8 [0x20002a8c])
+== (011)     3384 [20002a98] +92     (malloc: ALLOCATED: 92 [0x20002a98])
+== (012)     3376 [20002af8] +8      (malloc: ALLOCATED: 8 [0x20002af8])
+== (013)     3368 [20002b04] +8      (malloc: ALLOCATED: 8 [0x20002b04])
+== (014)     3256 [20002b10] +112    (malloc: ALLOCATED: 112 [0x20002b10])
+== (015)     3216 [20002b84] +40     (malloc: ALLOCATED: 40 [0x20002b84])
+== (016)     3192 [20002bb0] +24     (malloc: ALLOCATED: 24 [0x20002bb0])
+== (017)     3179 [20002bcc] +13     (malloc: ALLOCATED: 13 [0x20002bcc])
+== (018)     3087 [20002be0] +92     (malloc: ALLOCATED: 92 [0x20002be0])
+== (019)     2995 [20002c40] +92     (malloc: ALLOCATED: 92 [0x20002c40])
+== (020)     2955 [20002ca0] +40     (malloc: ALLOCATED: 40 [0x20002ca0])
+== (021)     2915 [20002ccc] +40     (malloc: ALLOCATED: 40 [0x20002ccc])
+== (022)     2903 [20002cf8] +12     (malloc: ALLOCATED: 12 [0x20002cf8])
+== (023)     2863 [20002d08] +40     (malloc: ALLOCATED: 40 [0x20002d08])
+== (024)     2839 [20002d34] +24     (malloc: ALLOCATED: 24 [0x20002d34])
+== (025)     2815 [20002d50] +24     (malloc: ALLOCATED: 24 [0x20002d50])
+== (026)     2591 [20002d6c] +224    (malloc: ALLOCATED: 224 [0x20002d6c])
+!! (026) WARN: free(0x0x20002d50)
+== (026)     2591 [       0] -0      (free:   0x20002d50)
+== (026)     2581 [20002d50] +10     (malloc: ALLOCATED: 10 [0x20002d50])
+== (027)     2571 [20002e50] +10     (malloc: ALLOCATED: 10 [0x20002e50])
+== (028)     2561 [20002e60] +10     (malloc: ALLOCATED: 10 [0x20002e60])
+== (029)     2546 [20002e70] +15     (malloc: ALLOCATED: 15 [0x20002e70])
+!! (029) WARN: free(0x0x20002e60)
+== (029)     2546 [       0] -0      (free:   0x20002e60)
+!! (029) WARN: free(0x0x20002e50)
+== (029)     2546 [       0] -0      (free:   0x20002e50)
+== (029)     2528 [20002e50] +18     (malloc: ALLOCATED: 18 [0x20002e50])
+== (030)     2521 [20002d60] +7      (malloc: ALLOCATED: 7 [0x20002d60])
+== (031)     2515 [20002e84] +6      (malloc: ALLOCATED: 6 [0x20002e84])
+== (032)     2495 [20002e90] +20     (malloc: ALLOCATED: 20 [0x20002e90])
+== (033)     2470 [20002ea8] +25     (malloc: ALLOCATED: 25 [0x20002ea8])
+== (034)     2444 [20002ec8] +26     (malloc: ALLOCATED: 26 [0x20002ec8])
+!! (034) WARN: free(0x0x20002e50)
+== (034)     2444 [       0] -0      (free:   0x20002e50)
+!! (034) WARN: free(0x0x20002ea8)
+== (034)     2444 [       0] -0      (free:   0x20002ea8)
+!! (034) WARN: free(0x0x20002e90)
+== (034)     2444 [       0] -0      (free:   0x20002e90)
+== (034)     2436 [20002e50] +8      (malloc: ALLOCATED: 8 [0x20002e50])
+== (035)     2116 [20002ee8] +320    (malloc: ALLOCATED: 320 [0x20002ee8])
+== (036)     2108 [20002e5c] +8      (malloc: ALLOCATED: 8 [0x20002e5c])
+== (036)     2088 [20002e90] +20     (malloc: ALLOCATED: 20 [0x20002e90])
+== (037)     1476 [2000302c] +612    (malloc: ALLOCATED: 612 [0x2000302c])
+== (037)     1456 [20002ea8] +20     (malloc: ALLOCATED: 20 [0x20002ea8])
+== (038)     1436 [20003294] +20     (malloc: ALLOCATED: 20 [0x20003294])
+== (039)     1400 [200032ac] +36     (malloc: ALLOCATED: 36 [0x200032ac])
+!! (039) WARN: free(0x0x20002e84)
+== (039)     1400 [       0] -0      (free:   0x20002e84)
+!! (039) WARN: free(0x0x20002d60)
+== (039)     1400 [       0] -0      (free:   0x20002d60)
+!! (039) WARN: free(0x0x20002ec8)
+== (039)     1400 [       0] -0      (free:   0x20002ec8)
+!! (039) WARN: free(0x0x20002e70)
+== (039)     1400 [       0] -0      (free:   0x20002e70)
+== (040)     1365 [20002e68] +35     (malloc: ALLOCATED: 35 [0x20002e68])
+== (041)     1344 [20002ec0] +21     (malloc: ALLOCATED: 21 [0x20002ec0])
 ```
 
 ## License
blob - d7a7cf1684f1ec2a66b6292cd77dbd72d16160c7
blob + d4ab67d6da86298bc692c0f69a87e9b2ddca2d55
--- memtrace_calliope_trns.py
+++ memtrace_calliope_trns.py
@@ -101,15 +101,14 @@ class CalliopeDebugTransform(Transform):
         m = self.r_free.search(line)
         if m:
             out = ""
-            addr = 0
             freed = 0
-            if m.group(1) in self.mem:
-                addr = int(m.group(1), 16)
+            addr = int(m.group(1), 16)
+            if addr in self.mem:
                 freed = self.mem[addr]
                 self.allocated -= freed
                 del self.mem[addr]
             else:
-                out += "\033[33m!! (%03d) WARN: free(0x%s)\033[0m\r\n" % (len(self.mem), m.group(1))
+                out += "\033[33m!! (%03d) WARN: free(0x%x)\033[0m\r\n" % (len(self.mem), addr)
 
             free = self.max - self.allocated
             out += "\033[1m== (%03d) \033[3%sm%8d\033[0m [%8x] \033[92m-%-6d\033[0m (%s)\r\n" % \
@@ -122,23 +121,33 @@ class CalliopeDebugTransform(Transform):
             wanted = int(m.group(1))
             out += "\033[31m!! (%03d) : malloc(): no free block of size %d\033[0m\r\n" % (len(self.mem), wanted)
 
-            out += "HEAP ALLOCATION:\r\n"
 
             mem = ""
             end = 0
             for addr in range(self.heap_start, self.heap_end):
-                if addr in self.mem:
-                    end = addr + self.mem[addr]
+                if addr+4 in self.mem:
+                    start = addr+4
+                    end = addr+4 + self.mem[addr+4]
                 if addr == end:
                     end = 0
                 if end:
-                    mem += "*"
+                    if addr < start: mem += "%"
+                    else: mem += "*"
                 else:
                     mem += "."
 
+            out += "HEAP ALLOCATION (% header | * data | . free)\r\n"
             for a in range(0, self.max, 64):
                 out += "%06d %08x %s\r\n" % (a, self.heap_start + a, mem[a:a+64])
 
+            addr = 0
+            out += "\033[31m== Free blocks: ==\033[0m\r\n"
+            blocks = re.findall("[%*]+|[.]+", mem)
+            for b in blocks:
+                if len(b) > 4 and b[0] == '.':
+                    out += "%08x %d bytes\r\n" % (self.heap_start + addr, len(b))
+                addr += len(b)
+
             return out
 
         # print all other lines as is, so we can still use the log functionality