zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f56d11350313d5e45be0679bd8fab2a96892c40c (tree)
parent dec7e45f7c7e61a3778767bbc7f8e1e9a33b01fa
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun,  4 Aug 2024 15:45:16 -0700

fuzzer web ui: render stats

Diffstat:
Mlib/fuzzer/index.html | 7+++++++
Mlib/fuzzer/main.js | 20+++++++++++++++++++-
Mlib/fuzzer/wasm/main.zig | 17+++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/lib/fuzzer/index.html b/lib/fuzzer/index.html @@ -125,6 +125,13 @@ </head> <body> <p id="status">Loading JavaScript...</p> + <div id="sectStats" class="hidden"> + <ul> + <li>Total Runs: <span id="statTotalRuns"></span></li> + <li>Unique Runs: <span id="statUniqueRuns"></span></li> + <li>Lowest Stack: <span id="statLowestStack"></span></li> + </ul> + </div> <div id="sectSource" class="hidden"> <h2>Source Code</h2> <pre><code id="sourceText"></code></pre> diff --git a/lib/fuzzer/main.js b/lib/fuzzer/main.js @@ -1,7 +1,11 @@ (function() { const domStatus = document.getElementById("status"); const domSectSource = document.getElementById("sectSource"); + const domSectStats = document.getElementById("sectStats"); const domSourceText = document.getElementById("sourceText"); + const domStatTotalRuns = document.getElementById("statTotalRuns"); + const domStatUniqueRuns = document.getElementById("statUniqueRuns"); + const domStatLowestStack = document.getElementById("statLowestStack"); let wasm_promise = fetch("main.wasm"); let sources_promise = fetch("sources.tar").then(function(response) { @@ -94,7 +98,7 @@ } function onCoverageUpdate() { - console.log("coverage update"); + renderStats(); } function render() { @@ -105,6 +109,20 @@ renderSource("/home/andy/dev/zig/lib/std/zig/tokenizer.zig"); } + function renderStats() { + const totalRuns = wasm_exports.totalRuns(); + const uniqueRuns = wasm_exports.uniqueRuns(); + domStatTotalRuns.innerText = totalRuns; + domStatUniqueRuns.innerText = uniqueRuns + " (" + percent(uniqueRuns, totalRuns) + "%)"; + domStatLowestStack.innerText = unwrapString(wasm_exports.lowestStack()); + + domSectStats.classList.remove("hidden"); + } + + function percent(a, b) { + return ((Number(a) / Number(b)) * 100).toFixed(1); + } + function renderSource(path) { const decl_index = findFileRoot(path); if (decl_index == null) throw new Error("file not found: " + path); diff --git a/lib/fuzzer/wasm/main.zig b/lib/fuzzer/wasm/main.zig @@ -103,6 +103,23 @@ export fn decl_source_html(decl_index: Decl.Index) String { return String.init(string_result.items); } +export fn lowestStack() String { + const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]); + string_result.clearRetainingCapacity(); + string_result.writer(gpa).print("0x{d}", .{header.lowest_stack}) catch @panic("OOM"); + return String.init(string_result.items); +} + +export fn totalRuns() u64 { + const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]); + return header.n_runs; +} + +export fn uniqueRuns() u64 { + const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]); + return header.unique_runs; +} + const String = Slice(u8); fn Slice(T: type) type {