devtools/actors/
memory.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
5use malloc_size_of_derive::MallocSizeOf;
6use serde::Serialize;
7
8use crate::actor::{Actor, ActorRegistry};
9
10#[derive(Serialize)]
11#[serde(rename_all = "camelCase")]
12pub(crate) struct TimelineMemoryReply {
13    js_object_size: u64,
14    js_string_size: u64,
15    js_other_size: u64,
16    dom_size: u64,
17    style_size: u64,
18    other_size: u64,
19    total_size: u64,
20    js_milliseconds: f64,
21    #[serde(rename = "nonJSMilliseconds")]
22    non_js_milliseconds: f64,
23}
24
25#[derive(MallocSizeOf)]
26pub(crate) struct MemoryActor {
27    name: String,
28}
29
30impl Actor for MemoryActor {
31    fn name(&self) -> String {
32        self.name.clone()
33    }
34}
35
36impl MemoryActor {
37    /// return name of actor
38    pub fn create(registry: &ActorRegistry) -> String {
39        let actor_name = registry.new_name::<Self>();
40        let actor = MemoryActor {
41            name: actor_name.clone(),
42        };
43
44        registry.register(actor);
45        actor_name
46    }
47
48    pub fn measure(&self) -> TimelineMemoryReply {
49        TimelineMemoryReply {
50            js_object_size: 1,
51            js_string_size: 1,
52            js_other_size: 1,
53            dom_size: 1,
54            style_size: 1,
55            other_size: 1,
56            total_size: 1,
57            js_milliseconds: 1.1,
58            non_js_milliseconds: 1.1,
59        }
60    }
61}