diff --git a/emu.js b/emu.js index ad4488a..4c93c6b 100644 --- a/emu.js +++ b/emu.js @@ -51,6 +51,19 @@ class Emulator { document.addEventListener('keydown', (e) => this.handle_keydown(e)); window.addEventListener('resize', () => this.handle_resize()); + this.prof = new Worker("prof.js"); + this.prof.onmessage = (e) => { + const blob = new Blob( + [JSON.stringify(e.data)], + { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = "wipforth-profile.json"; + a.click(); + URL.revokeObjectURL(url); + }; + this.print("Assembling kernel "); const dots = setInterval(() => this.print("."), DOT_INTERVAL_MS); this.worker = new Worker('boot.js', { type: 'module' }); @@ -59,6 +72,7 @@ class Emulator { clearInterval(dots); this.print(" done\n"); this.worker.postMessage({ type: "boot" }); + this.prof.postMessage({ type: "start", mem: this.mem }); }; fetch('prelude.f') @@ -85,6 +99,7 @@ class Emulator { if (!this.input_enable) { const sysready = Atomics.load(this.mem_u8, SYSREADY); if (sysready != 0) { + this.prof.postMessage({ type: "stop" }); this.input_enable = true; this.flush_output(); document.getElementById('cursor').classList.add('blinking');