diff --git a/test/unit/test_viz.py b/test/unit/test_viz.py index fbfc37e76f..5ba00735eb 100644 --- a/test/unit/test_viz.py +++ b/test/unit/test_viz.py @@ -30,6 +30,7 @@ class BaseTestViz(unittest.TestCase): # clear the global context for lst in [tracked_keys, tracked_ctxs, active_rewrites, _name_cnt]: lst.clear() Buffer.profile_events.clear() + cpu_events.clear() self.tms = TRACK_MATCH_STATS.value self.profile = PROFILE.value TRACK_MATCH_STATS.value = 2 @@ -462,5 +463,21 @@ class TestVizMemoryLayout(BaseTestViz): self.assertEqual(ret["peak"], 2) self.assertEqual(len(ret["events"]), 4) + def test_free_last(self): + bufs = [] + for _ in range(3): + bufs.append(_alloc(1)) + profile_marker("alloc") + device = bufs[0].device + while bufs: + b = bufs.pop() + del b + profile_marker("free") + profile = load_profile(cpu_events+Buffer.profile_events) + ret = profile["layout"][f"{device} Memory"] + self.assertEqual(ret["peak"], 3) + self.assertEqual(len(ret["events"]), 6) + self.assertEqual(len(profile["markers"]), 6) + if __name__ == "__main__": unittest.main() diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index e120bac281..c5598fcd7f 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -257,8 +257,8 @@ async function renderProfiler() { x += 1; y += nbytes; valueMap.set(ts, y); } else { const free = buf_shapes.get(key); - timestamps.push(ts); - x += 1; y -= free.nbytes; valueMap.set(ts, y); + timestamps.push(ts); valueMap.set(ts, y); + x += 1; y -= free.nbytes; free.x.push(x); free.y.push(free.y.at(-1)); temp.delete(key); @@ -401,6 +401,7 @@ async function renderProfiler() { } } // draw markers + ctx.textBaseline = "top"; for (const m of markers) { const x = xscale(m.ts); drawLine(ctx, [x, x], [0, canvas.clientHeight], { color:m.color });