Skip to content

Commit c0139ac

Browse files
committed
fix fuzzing speed with prior runs
1 parent a4f1daa commit c0139ac

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/build-web/fuzz.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Server timestamp.
22
var start_fuzzing_timestamp: i64 = undefined;
3+
var start_fuzzing_n_runs: u64 = undefined;
34

45
const js = struct {
56
extern "fuzz" fn requestSources() void;
@@ -36,6 +37,7 @@ pub fn sourceIndexMessage(msg_bytes: []u8) error{OutOfMemory}!void {
3637
const source_locations: []const Coverage.SourceLocation = @alignCast(std.mem.bytesAsSlice(Coverage.SourceLocation, msg_bytes[source_locations_start..source_locations_end]));
3738

3839
start_fuzzing_timestamp = header.start_timestamp;
40+
start_fuzzing_n_runs = header.start_n_runs;
3941
try updateCoverageSources(directories, files, source_locations, string_bytes);
4042
js.ready();
4143
}
@@ -270,7 +272,7 @@ fn updateStats() error{OutOfMemory}!void {
270272

271273
const avg_speed: f64 = speed: {
272274
const ns_elapsed: f64 = @floatFromInt(nsSince(start_fuzzing_timestamp));
273-
const n_runs: f64 = @floatFromInt(hdr.n_runs);
275+
const n_runs: f64 = @floatFromInt(hdr.n_runs -% start_fuzzing_n_runs);
274276
break :speed n_runs / (ns_elapsed / std.time.ns_per_s);
275277
};
276278

lib/std/Build/Fuzz.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const CoverageMap = struct {
6767
/// Elements are indexes into `source_locations` pointing to the unit tests that are being fuzz tested.
6868
entry_points: std.ArrayListUnmanaged(u32),
6969
start_timestamp: i64,
70+
start_n_runs: u64,
7071

7172
fn deinit(cm: *CoverageMap, gpa: Allocator) void {
7273
std.posix.munmap(cm.mapped_memory);
@@ -318,6 +319,7 @@ pub fn sendUpdate(
318319
.source_locations_len = @intCast(coverage_map.source_locations.len),
319320
.string_bytes_len = @intCast(coverage_map.coverage.string_bytes.items.len),
320321
.start_timestamp = coverage_map.start_timestamp,
322+
.start_n_runs = coverage_map.start_n_runs,
321323
};
322324
var iovecs: [5][]const u8 = .{
323325
@ptrCast(&header),
@@ -399,6 +401,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO
399401
.source_locations = undefined, // populated below
400402
.entry_points = .{},
401403
.start_timestamp = ws.now(),
404+
.start_n_runs = undefined, // populated below
402405
};
403406
errdefer gop.value_ptr.coverage.deinit(fuzz.gpa);
404407

@@ -468,6 +471,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO
468471

469472
for (sorted_pcs.items(.index), sorted_pcs.items(.sl)) |i, sl| source_locations[i] = sl;
470473
gop.value_ptr.source_locations = source_locations;
474+
gop.value_ptr.start_n_runs = header.n_runs;
471475

472476
ws.notifyUpdate();
473477
}

lib/std/Build/abi.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub const fuzz = struct {
218218
string_bytes_len: u32,
219219
/// When, according to the server, fuzzing started.
220220
start_timestamp: i64 align(4),
221+
start_n_runs: u64 align(4),
221222
};
222223

223224
/// WebSocket server->client.

0 commit comments

Comments
 (0)