mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Add libdom RSS and v8 total_physical_size to testing --json output
https://github.com/lightpanda-io/browser/issues/1057
This commit is contained in:
@@ -40,6 +40,45 @@ pub fn destroy() void {
|
||||
heap = null;
|
||||
}
|
||||
|
||||
pub fn getRSS() i64 {
|
||||
if (@import("builtin").mode != .Debug) {
|
||||
// just don't trust my implementation, plus a caller might not know
|
||||
// that this requires parsing some unstructured data
|
||||
@compileError("Only available in debug builds");
|
||||
}
|
||||
var buf: [4096]u8 = undefined;
|
||||
var fba = std.heap.FixedBufferAllocator.init(&buf);
|
||||
var writer = std.Io.Writer.Allocating.init(fba.allocator());
|
||||
|
||||
c.mi_stats_print_out(struct {
|
||||
fn print(msg: [*c]const u8, data: ?*anyopaque) callconv(.c) void {
|
||||
const w: *std.Io.Writer = @ptrCast(@alignCast(data.?));
|
||||
w.writeAll(std.mem.span(msg)) catch |err| {
|
||||
std.debug.print("Failed to write mimalloc data: {}", .{err});
|
||||
};
|
||||
}
|
||||
}.print, &writer.writer);
|
||||
|
||||
const data = writer.written();
|
||||
const index = std.mem.indexOf(u8, data, "rss: ") orelse return -1;
|
||||
const sep = std.mem.indexOfScalarPos(u8, data, index + 5, ' ') orelse return -2;
|
||||
const value = std.fmt.parseFloat(f64, data[index+5..sep]) catch return -3;
|
||||
const unit = data[sep+1..];
|
||||
if (std.mem.startsWith(u8, unit, "KiB,")) {
|
||||
return @as(i64, @intFromFloat(value)) * 1024;
|
||||
}
|
||||
|
||||
if (std.mem.startsWith(u8, unit, "MiB,")) {
|
||||
return @as(i64, @intFromFloat(value)) * 1024 * 1024;
|
||||
}
|
||||
|
||||
if (std.mem.startsWith(u8, unit, "GiB,")) {
|
||||
return @as(i64, @intFromFloat(value)) * 1024 * 1024 * 1024;
|
||||
}
|
||||
|
||||
return -4;
|
||||
}
|
||||
|
||||
pub export fn m_alloc(size: usize) callconv(.c) ?*anyopaque {
|
||||
std.debug.assert(heap != null);
|
||||
return c.mi_heap_malloc(heap.?, size);
|
||||
|
||||
@@ -35,6 +35,8 @@ pub const std_options = std.Options{
|
||||
};
|
||||
|
||||
pub var js_runner_duration: usize = 0;
|
||||
pub var v8_peak_memory: usize = 0;
|
||||
pub var libdom_memory: i64 = 0;
|
||||
pub var tracking_allocator: Allocator = undefined;
|
||||
|
||||
pub fn main() !void {
|
||||
@@ -194,13 +196,13 @@ pub fn main() !void {
|
||||
.duration = js_runner_duration,
|
||||
.alloc_nb = 0,
|
||||
.realloc_nb = 0,
|
||||
.alloc_size = 0,
|
||||
.alloc_size = libdom_memory,
|
||||
} },
|
||||
.{ .name = "v8", .bench = .{
|
||||
.duration = js_runner_duration,
|
||||
.alloc_nb = 0,
|
||||
.realloc_nb = 0,
|
||||
.alloc_size = 0,
|
||||
.alloc_size = v8_peak_memory,
|
||||
} },
|
||||
.{ .name = "main", .bench = .{
|
||||
.duration = js_runner_duration,
|
||||
|
||||
@@ -379,6 +379,8 @@ pub fn setup() !void {
|
||||
test_session = try test_browser.newSession();
|
||||
}
|
||||
pub fn shutdown() void {
|
||||
@import("root").v8_peak_memory = test_browser.env.isolate.getHeapStatistics().total_physical_size;
|
||||
@import("root").libdom_memory = @import("browser/mimalloc.zig").getRSS();
|
||||
test_browser.deinit();
|
||||
test_app.deinit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user