viz: fix memory graph total nbytes (#12622)

* viz: fix memory graph total nbytes

* post increment

* simple regression test

* loop with markers + slightly off text baseline

* cpu events clear
This commit is contained in:
qazal
2025-10-12 14:32:46 +03:00
committed by GitHub
parent 822eab057f
commit b5afa3848e
2 changed files with 20 additions and 2 deletions
+17
View File
@@ -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()
+3 -2
View File
@@ -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 });