Skip to content

Commit 5ad4885

Browse files
authored
Merge pull request #1028 from lightpanda-io/wpt_runner_tweak
Try to address WPT running OOM
2 parents 2ed8a1c + 0aa1e02 commit 5ad4885

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

.github/workflows/wpt.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ env:
55
AWS_SECRET_ACCESS_KEY: ${{ secrets.LPD_PERF_AWS_SECRET_ACCESS_KEY }}
66
AWS_BUCKET: ${{ vars.LPD_PERF_AWS_BUCKET }}
77
AWS_REGION: ${{ vars.LPD_PERF_AWS_REGION }}
8+
LIGHTPANDA_DISABLE_TELEMETRY: true
89

910
on:
1011
schedule:
@@ -30,7 +31,7 @@ jobs:
3031
- uses: ./.github/actions/install
3132

3233
- name: json output
33-
run: zig build wpt -- --json > wpt.json
34+
run: zig build -Doptimize=ReleaseFast wpt -- --json > wpt.json
3435

3536
- name: write commit
3637
run: |

src/TestHTTPServer.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub fn sendFile(req: *std.http.Server.Request, file_path: []const u8) !void {
7474
error.FileNotFound => return req.respond("server error", .{ .status = .not_found }),
7575
else => return err,
7676
};
77+
defer file.close();
7778

7879
const stat = try file.stat();
7980
var send_buffer: [4096]u8 = undefined;

src/main_wpt.zig

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const ArenaAllocator = std.heap.ArenaAllocator;
2525
const App = @import("app.zig").App;
2626
const Env = @import("browser/env.zig").Env;
2727
const Browser = @import("browser/browser.zig").Browser;
28-
const Session = @import("browser/session.zig").Session;
2928
const TestHTTPServer = @import("TestHTTPServer.zig");
3029

3130
const parser = @import("browser/netsurf.zig");
@@ -75,15 +74,15 @@ pub fn main() !void {
7574

7675
var browser = try Browser.init(app);
7776
defer browser.deinit();
78-
const session = try browser.newSession();
7977

78+
var i: usize = 0;
8079
while (try it.next()) |test_file| {
8180
defer _ = test_arena.reset(.retain_capacity);
8281

8382
var err_out: ?[]const u8 = null;
8483
const result = run(
8584
test_arena.allocator(),
86-
session,
85+
&browser,
8786
test_file,
8887
&err_out,
8988
) catch |err| blk: {
@@ -93,16 +92,24 @@ pub fn main() !void {
9392
break :blk null;
9493
};
9594
try writer.process(test_file, result, err_out);
95+
// if (@mod(i, 10) == 0) {
96+
// std.debug.print("\n\n=== V8 Memory {d}===\n", .{i});
97+
// browser.env.dumpMemoryStats();
98+
// }
99+
i += 1;
96100
}
97101
try writer.finalize();
98102
}
99103

100104
fn run(
101105
arena: Allocator,
102-
session: *Session,
106+
browser: *Browser,
103107
test_file: []const u8,
104108
err_out: *?[]const u8,
105109
) ![]const u8 {
110+
const session = try browser.newSession();
111+
defer browser.closeSession();
112+
106113
const page = try session.createPage();
107114
defer session.removePage();
108115

@@ -141,11 +148,7 @@ const Writer = struct {
141148
writer: std.fs.File.Writer,
142149
cases: std.ArrayListUnmanaged(Case) = .{},
143150

144-
const Format = enum {
145-
json,
146-
text,
147-
summary,
148-
};
151+
const Format = enum { json, text, summary, quiet };
149152

150153
fn init(allocator: Allocator, format: Format) !Writer {
151154
const out = std.fs.File.stdout();
@@ -200,6 +203,7 @@ const Writer = struct {
200203
}, .{ .whitespace = .indent_2 }, writer);
201204
return writer.writeByte(',');
202205
},
206+
.quiet => {},
203207
}
204208
// just make sure we didn't fall through by mistake
205209
unreachable;
@@ -289,6 +293,7 @@ const Writer = struct {
289293
// separator, see `finalize` for the hack we use to terminate this
290294
try writer.writeByte(',');
291295
},
296+
.quiet => {},
292297
}
293298
}
294299

@@ -309,7 +314,8 @@ fn parseArgs(arena: Allocator) !Command {
309314
\\
310315
\\ -h, --help Print this help message and exit.
311316
\\ --json result is formatted in JSON.
312-
\\ --summary print a summary result. Incompatible w/ --json
317+
\\ --summary print a summary result. Incompatible w/ --json or --quiet
318+
\\ --quiet No output. Incompatible w/ --json or --summary
313319
\\
314320
;
315321

@@ -331,6 +337,8 @@ fn parseArgs(arena: Allocator) !Command {
331337
format = .json;
332338
} else if (std.mem.eql(u8, "--summary", arg)) {
333339
format = .summary;
340+
} else if (std.mem.eql(u8, "--quiet", arg)) {
341+
format = .quiet;
334342
} else {
335343
try filters.append(arena, arg);
336344
}

src/runtime/js.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,27 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
329329
self.isolate.lowMemoryNotification();
330330
}
331331

332+
pub fn dumpMemoryStats(self: *Self) void {
333+
const stats = self.isolate.getHeapStatistics();
334+
std.debug.print(
335+
\\ Total Heap Size: {d}
336+
\\ Total Heap Size Executable: {d}
337+
\\ Total Physical Size: {d}
338+
\\ Total Available Size: {d}
339+
\\ Used Heap Size: {d}
340+
\\ Heap Size Limit: {d}
341+
\\ Malloced Memory: {d}
342+
\\ External Memory: {d}
343+
\\ Peak Malloced Memory: {d}
344+
\\ Number Of Native Contexts: {d}
345+
\\ Number Of Detached Contexts: {d}
346+
\\ Total Global Handles Size: {d}
347+
\\ Used Global Handles Size: {d}
348+
\\ Zap Garbage: {any}
349+
\\
350+
, .{stats.total_heap_size, stats.total_heap_size_executable, stats.total_physical_size, stats.total_available_size, stats.used_heap_size, stats.heap_size_limit, stats.malloced_memory, stats.external_memory, stats.peak_malloced_memory, stats.number_of_native_contexts, stats.number_of_detached_contexts, stats.total_global_handles_size, stats.used_global_handles_size, stats.does_zap_garbage});
351+
}
352+
332353
fn promiseRejectCallback(v8_msg: v8.C_PromiseRejectMessage) callconv(.c) void {
333354
const msg = v8.PromiseRejectMessage.initFromC(v8_msg);
334355
const isolate = msg.getPromise().toObject().getIsolate();

0 commit comments

Comments
 (0)