Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

updateStats

fuzz.updateStats
fn updateStats() error

File

lib/build-web/fuzz.zig:257

Code

fn updateStats() error{OutOfMemory}!void {
    // No @setFloatMode(.optimized) since some stats may be at zero and lead to divisions by zero

    if (recent_coverage_update.items.len == 0) return;

    const hdr: *abi.fuzz.CoverageUpdateHeader = @ptrCast(@alignCast(
        recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)],
    ));

    const covered_src_locs: usize = n: {
        var n: usize = 0;
        const covered_bits = recent_coverage_update.items[@sizeOf(abi.fuzz.CoverageUpdateHeader)..];
        for (covered_bits) |byte| n += @popCount(byte);
        break :n n;
    };
    const total_src_locs = coverage_source_locations.items.len;

    const avg_speed: f64 = speed: {
        const ns_elapsed: f64 = @floatFromInt(nsSince(start_fuzzing_timestamp));
        const n_runs: f64 = @floatFromInt(hdr.n_runs -% start_fuzzing_n_runs);
        break :speed n_runs / (ns_elapsed / std.time.ns_per_s);
    };

    const html = try std.fmt.allocPrint(gpa,
        \\<span slot="stat-total-runs">{d}</span>
        \\<span slot="stat-unique-runs">{d} ({d:.1}%)</span>
        \\<span slot="stat-coverage">{d} / {d} ({d:.1}%)</span>
        \\<span slot="stat-speed">{d:.0}</span>
    , .{
        hdr.n_runs,
        hdr.unique_runs,
        @as(f64, @floatFromInt(hdr.unique_runs)) / @as(f64, @floatFromInt(hdr.n_runs)) * 100,
        covered_src_locs,
        total_src_locs,
        @as(f64, @floatFromInt(covered_src_locs)) / @as(f64, @floatFromInt(total_src_locs)) * 100,
        avg_speed,
    });
    defer gpa.free(html);

    js.updateStats(html.ptr, html.len);
}