Skip to main content

engine_observables_api/
stats.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Arena/table stats shared across engine lanes.
6//!
7//! These are cheap, lane-neutral diagnostic shapes: integer counts and rough
8//! byte estimates, not raw plane internals.
9
10use malloc_size_of_derive::MallocSizeOf;
11use serde::{Deserialize, Serialize};
12
13/// Per-kind live-node counts for a DOM arena.
14#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
15pub struct DomNodeKindStats {
16    pub documents: usize,
17    pub document_fragments: usize,
18    pub doctypes: usize,
19    pub elements: usize,
20    pub text: usize,
21    pub comments: usize,
22    pub processing_instructions: usize,
23}
24
25/// Cheap live stats for a DOM arena.
26#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
27pub struct DomArenaStats {
28    pub live_nodes: usize,
29    pub node_kinds: DomNodeKindStats,
30    pub attribute_count: usize,
31    /// Approximate bytes owned by the arena and its reachable dynamic buffers.
32    pub estimated_bytes: usize,
33}
34
35/// What the last incremental-layout batch did.
36#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
37pub enum LayoutApplyKind {
38    #[default]
39    Unchanged,
40    RepaintOnly,
41    Restyled,
42    Spliced,
43    FullRecompute,
44}
45
46/// Coarse damage class for the last batch.
47#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
48pub enum LayoutDamageClass {
49    #[default]
50    None,
51    PaintOnly,
52    Relayout,
53}
54
55/// Cheap stats for the last incremental-layout batch.
56#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
57pub struct LayoutBatchStats {
58    pub applied: LayoutApplyKind,
59    pub damage: LayoutDamageClass,
60    pub mutations_in: usize,
61    pub coalesced_invalidations: usize,
62    pub restyled_elements: usize,
63    pub boxes_rebuilt: usize,
64    pub fragment_count: usize,
65    /// Present only when the retained box-tree side-table matches the current
66    /// fragment plane. Structural splices deliberately invalidate that side-table.
67    pub box_tree_nodes: Option<usize>,
68}