From 38f0fa7bde5d25b3df4c0ecfa6a883e5985dfd6a Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:00:48 +0300 Subject: [PATCH] viz: only send trace duration (#11789) * viz: only send trace duration * can unwrap --- tinygrad/viz/js/index.js | 8 ++++---- tinygrad/viz/serve.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index 43a5b6e09c..deda1d322b 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -151,7 +151,7 @@ async function renderProfiler() { // layout once! if (data != null) return; const profiler = d3.select(".profiler").html(""); - const { layout, st, et } = await (await fetch("/get_profile")).json(); + const { layout, dur } = await (await fetch("/get_profile")).json(); // place devices on the y axis and set vertical positions const [tickSize, padding] = [10, 8]; const deviceList = profiler.append("div").attr("id", "device-list").style("padding-top", tickSize+padding+"px"); @@ -162,7 +162,7 @@ async function renderProfiler() { const canvasTop = rect(canvas).top; // color by key (name/category/device) const colorMap = new Map(); - data = {tracks:new Map(), axes:{}, st, et}; + data = {tracks:new Map(), axes:{}}; const heightScale = d3.scaleLinear().domain([0, Object.entries(layout).reduce((peak, [_,d]) => Math.max(peak, d.peak||0), 0)]).range([4,maxheight=100]); for (const [k, v] of Object.entries(layout)) { if (v.shapes.length === 0) continue; @@ -225,7 +225,7 @@ async function renderProfiler() { ctx.save(); ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight); // rescale to match current zoom - const xscale = d3.scaleLinear().domain([0, et-st]).range([0, canvas.clientWidth]); + const xscale = d3.scaleLinear().domain([0, dur]).range([0, canvas.clientWidth]); xscale.domain(xscale.range().map(zoomLevel.invertX, zoomLevel).map(xscale.invert, xscale)); const zoomDomain = transform != null ? xscale.domain() : null; let yscale = null; @@ -289,7 +289,7 @@ async function renderProfiler() { // tick label ctx.textBaseline = "top"; ctx.textAlign = "left"; - ctx.fillText(formatTime(tick, et-st), x+ctx.lineWidth+2, tickSize); + ctx.fillText(formatTime(tick, dur), x+ctx.lineWidth+2, tickSize); } if (yscale != null) { drawLine(ctx, [0, 0], yscale.range()); diff --git a/tinygrad/viz/serve.py b/tinygrad/viz/serve.py index f1969f14c2..e391b2ecba 100755 --- a/tinygrad/viz/serve.py +++ b/tinygrad/viz/serve.py @@ -194,7 +194,7 @@ def get_profile(profile:list[ProfileEvent]) -> bytes|None: v.sort(key=lambda e:e[0]) layout[k] = timeline_layout(v, start_ts) layout[f"{k} Memory"] = mem_layout(v, start_ts, unwrap(end_ts)) - return json.dumps({"layout":layout, "st":start_ts, "et":end_ts}).encode("utf-8") + return json.dumps({"layout":layout, "dur":unwrap(end_ts)-start_ts}).encode("utf-8") def get_runtime_stats(key) -> list[dict]: ret:list[dict] = []