fuzzer web ui: render stats

This commit is contained in:
Andrew Kelley 2024-08-04 15:45:16 -07:00
parent dec7e45f7c
commit f56d113503
3 changed files with 43 additions and 1 deletions

View File

@ -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>

View File

@ -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);

View File

@ -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 {