mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-14 15:03:27 -04:00
Merge pull request #3508 from lightpanda-io/improve-js-memory-metric
ops: improve v8 memory metric reporting
This commit is contained in:
3 files changed
+17
-13
No files matched your search
@@ -55,6 +55,7 @@ arena_account: lp.Arena.Account = .{},
|
||||
|
||||
// Our isolate's heap size as of the last reportJsHeap().
|
||||
last_reported_js_bytes: usize = 0,
|
||||
last_js_heap_sample_ms: u64 = 0,
|
||||
|
||||
// Permission state set via CDP Browser.grantPermissions / setPermission /
|
||||
// resetPermissions, keyed by permission name (e.g. "geolocation"). Read back
|
||||
@@ -236,6 +237,18 @@ pub fn reportJsHeap(self: *Browser) void {
|
||||
self.last_reported_js_bytes = bytes;
|
||||
}
|
||||
|
||||
// Called every Runner tick
|
||||
pub fn sampleJsHeap(self: *Browser) void {
|
||||
const now = lp.datetime.milliTimestamp(.boot);
|
||||
if (now - self.last_js_heap_sample_ms < 1000) {
|
||||
// a busy page ticks often, we don't need to track this more than once
|
||||
// per second
|
||||
return;
|
||||
}
|
||||
self.last_js_heap_sample_ms = now;
|
||||
self.reportJsHeap();
|
||||
}
|
||||
|
||||
pub fn runMicrotasks(self: *Browser) void {
|
||||
self.env.runMicrotasks();
|
||||
}
|
||||
|
||||
@@ -498,11 +498,6 @@ pub fn init(self: *Frame, frame_id: u32, page: *Page, opts: InitOpts) !void {
|
||||
}.runIdleTasks, 200, .{ .name = "frame.runIdleTasks", .blocks_done = false });
|
||||
}
|
||||
}
|
||||
|
||||
if (parent == null) {
|
||||
// no point reporting this for each child page
|
||||
session.browser.reportJsHeap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Frame) void {
|
||||
@@ -576,9 +571,6 @@ pub fn deinit(self: *Frame) void {
|
||||
const browser = page.session.browser;
|
||||
|
||||
browser.http_client.abortOwner(&self._http_owner);
|
||||
if (self.parent == null) {
|
||||
browser.reportJsHeap();
|
||||
}
|
||||
|
||||
// fired the last moment the js context is still alive
|
||||
page.session.notification.dispatch(.frame_destroyed, self);
|
||||
@@ -1313,10 +1305,6 @@ pub fn documentIsComplete(self: *Frame) void {
|
||||
self._maybe_meta_refresh = false;
|
||||
self.metaRefreshOnLoad();
|
||||
}
|
||||
|
||||
if (self.parent == null) {
|
||||
self._session.browser.reportJsHeap();
|
||||
}
|
||||
}
|
||||
|
||||
fn _documentIsComplete(self: *Frame) !void {
|
||||
|
||||
@@ -204,7 +204,10 @@ fn _tick(self: *Runner, comptime is_cdp: bool, timeout_ms: u32, conditions: []Wa
|
||||
const session = self.session;
|
||||
const browser = self.browser;
|
||||
const http_client = self.http_client;
|
||||
defer browser.flushArenaMemory();
|
||||
defer {
|
||||
browser.flushArenaMemory();
|
||||
browser.sampleJsHeap();
|
||||
}
|
||||
|
||||
// Arms the watchdog (and proves liveness): a stall anywhere in this tick
|
||||
// ages this stamp until the watchdog fires.
|
||||
|
||||
Reference in new issue
Block a user