Skip to content

Truly independent web browser

Compositor: Log presented frame damage

Andreas Kling9f9b56faef49
diff --git a/Documentation/StatsLog.md b/Documentation/StatsLog.md
index 5b7b8cccffe..fd7a329d8d1 100644
--- a/Documentation/StatsLog.md
+++ b/Documentation/StatsLog.md
@@ -112,6 +112,7 @@ form `namespace:local`, preserving their exact values in floating-point JSON con
| `navigation_start` | Ladybird | `navigable_id` (cross-process ID string), `navigation_id` (string), `url` (string) |
| `DOMContentLoaded` | WebContent | `page_id` (integer), `navigable_id` (cross-process ID string), `document_id` (cross-process ID string), `url` (string) |
| `load` | WebContent | Same fields as `DOMContentLoaded` |
+| `frame` | Compositor | `page_id` (integer), `changed` (boolean), `damage_x`, `damage_y`, `damage_width`, `damage_height` (integer device pixels) |
| `gc` | WebContent or WebWorker | `collection`, `duration_ns`, `pause_duration_ns`, `sweep_duration_ns`, `bytes_before`, `bytes_after`, `live_cell_bytes`, `live_external_bytes` (integers) |
Navigation starts are recorded when the browser admits a navigation. Lifecycle markers are recorded
@@ -124,6 +125,16 @@ GC events are written after sweeping finishes. Durations measure active collecti
idle time between incremental sweep slices. Byte counts describe the heap's existing accounting,
not process RSS.
+The compositor records a frame immediately before publishing its rendered surface to the browser.
+GPU work has completed, or on Metal has been scheduled for the receiving surface to wait on.
+This is a rendered-frame timestamp, not a hardware scanout timestamp. Child surfaces and screenshots
+do not produce separate frame events. Match frames to lifecycle markers by `page_id`.
+
+`changed` is the existing damage rectangle's non-emptiness. Damage is conservative: repainting can
+produce identical colors. No readback or pixel hashing is performed. Fully suppressed frames do not
+produce events. The last changed frame after a bounded quiet period gives a conservative estimate of
+when the page finished painting. Animation and media can keep producing changed frames indefinitely.
+
## Sandboxing and overhead
Each helper opens its own file before installing its sandbox. Linux retains the open descriptor;
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index b1ce9a6d2be..07a1949e2dc 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -10,6 +10,7 @@
#include <Compositor/CanvasHost.h>
#include <Compositor/CompositorState.h>
#include <LibCore/EventLoop.h>
+#include <LibCore/StatsLog.h>
#include <LibCore/Timer.h>
#include <LibMedia/Sinks/DisplayingVideoSink.h>
@@ -1233,6 +1234,17 @@ void CompositorState::deliver_rendered_frame(PendingAsyncPresent& pending_presen
context->presenter().did_finish_gpu_present(pending_present.bitmap_id);
if (context->presents_to_client()) {
VERIFY(m_client);
+ if (auto* log = Core::StatsLog::the(); log && context->page_id().has_value()) {
+ auto const& damage = pending_present.damage_rect;
+ JsonObject data;
+ data.set("page_id"sv, *context->page_id());
+ data.set("changed"sv, !damage.is_empty());
+ data.set("damage_x"sv, damage.x());
+ data.set("damage_y"sv, damage.y());
+ data.set("damage_width"sv, damage.width());
+ data.set("damage_height"sv, damage.height());
+ log->event("frame"sv, move(data));
+ }
m_client->did_present_frame(context_id, pending_present.viewport_rect, pending_present.damage_rect, pending_present.bitmap_id, pending_present.device_pixel_ratio);
}
resize_backing_stores_if_needed(context_id, *context);
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 84e01a15b6f..fa06867945b 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -135,6 +135,7 @@ public:
// Whether the scroll offsets here moved past those of the last frame WebContent presented.
bool scrolled_since_last_frame() const;
bool can_dispatch_input_to_web_content() const { return m_page_id.has_value(); }
+ Optional<u64> page_id() const { return m_page_id; }
bool presents_to_client() const { return m_presenter.presents_to_client(); }
void stop_presenting_to_client();