Skip to main content

browser_protocol/memory/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Memory pressure level.
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
7pub enum PressureLevel {
8    #[default]
9    Moderate,
10    Critical,
11}
12
13/// Heap profile sample.
14
15#[derive(Debug, Clone, Serialize, Deserialize, Default)]
16#[serde(rename_all = "camelCase")]
17pub struct SamplingProfileNode {
18    /// Size of the sampled allocation.
19
20    pub size: f64,
21    /// Total bytes attributed to this sample.
22
23    pub total: f64,
24    /// Execution stack at the point of allocation.
25
26    pub stack: Vec<String>,
27}
28
29/// Array of heap profile samples.
30
31#[derive(Debug, Clone, Serialize, Deserialize, Default)]
32#[serde(rename_all = "camelCase")]
33pub struct SamplingProfile {
34
35    pub samples: Vec<SamplingProfileNode>,
36
37    pub modules: Vec<Module>,
38}
39
40/// Executable module information
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct Module {
45    /// Name of the module.
46
47    pub name: String,
48    /// UUID of the module.
49
50    pub uuid: String,
51    /// Base address where the module is loaded into memory. Encoded as a decimal
52    /// or hexadecimal (0x prefixed) string.
53
54    pub baseAddress: String,
55    /// Size of the module in bytes.
56
57    pub size: f64,
58}
59
60/// DOM object counter data.
61
62#[derive(Debug, Clone, Serialize, Deserialize, Default)]
63#[serde(rename_all = "camelCase")]
64pub struct DOMCounter {
65    /// Object name. Note: object names should be presumed volatile and clients should not expect
66    /// the returned names to be consistent across runs.
67
68    pub name: String,
69    /// Object count.
70
71    pub count: u64,
72}
73
74/// Retruns current DOM object counters.
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default)]
77#[serde(rename_all = "camelCase")]
78pub struct GetDOMCountersReturns {
79
80    pub documents: i64,
81
82    pub nodes: i64,
83
84    pub jsEventListeners: i64,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize, Default)]
88pub struct GetDOMCountersParams {}
89
90impl GetDOMCountersParams { pub const METHOD: &'static str = "Memory.getDOMCounters"; }
91
92impl crate::CdpCommand for GetDOMCountersParams {
93    const METHOD: &'static str = "Memory.getDOMCounters";
94    type Response = GetDOMCountersReturns;
95}
96
97/// Retruns DOM object counters after preparing renderer for leak detection.
98
99#[derive(Debug, Clone, Serialize, Deserialize, Default)]
100#[serde(rename_all = "camelCase")]
101pub struct GetDOMCountersForLeakDetectionReturns {
102    /// DOM object counters.
103
104    pub counters: Vec<DOMCounter>,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize, Default)]
108pub struct GetDOMCountersForLeakDetectionParams {}
109
110impl GetDOMCountersForLeakDetectionParams { pub const METHOD: &'static str = "Memory.getDOMCountersForLeakDetection"; }
111
112impl crate::CdpCommand for GetDOMCountersForLeakDetectionParams {
113    const METHOD: &'static str = "Memory.getDOMCountersForLeakDetection";
114    type Response = GetDOMCountersForLeakDetectionReturns;
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize, Default)]
118pub struct PrepareForLeakDetectionParams {}
119
120impl PrepareForLeakDetectionParams { pub const METHOD: &'static str = "Memory.prepareForLeakDetection"; }
121
122impl crate::CdpCommand for PrepareForLeakDetectionParams {
123    const METHOD: &'static str = "Memory.prepareForLeakDetection";
124    type Response = crate::EmptyReturns;
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, Default)]
128pub struct ForciblyPurgeJavaScriptMemoryParams {}
129
130impl ForciblyPurgeJavaScriptMemoryParams { pub const METHOD: &'static str = "Memory.forciblyPurgeJavaScriptMemory"; }
131
132impl crate::CdpCommand for ForciblyPurgeJavaScriptMemoryParams {
133    const METHOD: &'static str = "Memory.forciblyPurgeJavaScriptMemory";
134    type Response = crate::EmptyReturns;
135}
136
137/// Enable/disable suppressing memory pressure notifications in all processes.
138
139#[derive(Debug, Clone, Serialize, Deserialize, Default)]
140#[serde(rename_all = "camelCase")]
141pub struct SetPressureNotificationsSuppressedParams {
142    /// If true, memory pressure notifications will be suppressed.
143
144    pub suppressed: bool,
145}
146
147impl SetPressureNotificationsSuppressedParams { pub const METHOD: &'static str = "Memory.setPressureNotificationsSuppressed"; }
148
149impl crate::CdpCommand for SetPressureNotificationsSuppressedParams {
150    const METHOD: &'static str = "Memory.setPressureNotificationsSuppressed";
151    type Response = crate::EmptyReturns;
152}
153
154/// Simulate a memory pressure notification in all processes.
155
156#[derive(Debug, Clone, Serialize, Deserialize, Default)]
157#[serde(rename_all = "camelCase")]
158pub struct SimulatePressureNotificationParams {
159    /// Memory pressure level of the notification.
160
161    pub level: PressureLevel,
162}
163
164impl SimulatePressureNotificationParams { pub const METHOD: &'static str = "Memory.simulatePressureNotification"; }
165
166impl crate::CdpCommand for SimulatePressureNotificationParams {
167    const METHOD: &'static str = "Memory.simulatePressureNotification";
168    type Response = crate::EmptyReturns;
169}
170
171/// Start collecting native memory profile.
172
173#[derive(Debug, Clone, Serialize, Deserialize, Default)]
174#[serde(rename_all = "camelCase")]
175pub struct StartSamplingParams {
176    /// Average number of bytes between samples.
177
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub samplingInterval: Option<i64>,
180    /// Do not randomize intervals between samples.
181
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub suppressRandomness: Option<bool>,
184}
185
186impl StartSamplingParams { pub const METHOD: &'static str = "Memory.startSampling"; }
187
188impl crate::CdpCommand for StartSamplingParams {
189    const METHOD: &'static str = "Memory.startSampling";
190    type Response = crate::EmptyReturns;
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize, Default)]
194pub struct StopSamplingParams {}
195
196impl StopSamplingParams { pub const METHOD: &'static str = "Memory.stopSampling"; }
197
198impl crate::CdpCommand for StopSamplingParams {
199    const METHOD: &'static str = "Memory.stopSampling";
200    type Response = crate::EmptyReturns;
201}
202
203/// Retrieve native memory allocations profile
204/// collected since renderer process startup.
205
206#[derive(Debug, Clone, Serialize, Deserialize, Default)]
207#[serde(rename_all = "camelCase")]
208pub struct GetAllTimeSamplingProfileReturns {
209
210    pub profile: SamplingProfile,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize, Default)]
214pub struct GetAllTimeSamplingProfileParams {}
215
216impl GetAllTimeSamplingProfileParams { pub const METHOD: &'static str = "Memory.getAllTimeSamplingProfile"; }
217
218impl crate::CdpCommand for GetAllTimeSamplingProfileParams {
219    const METHOD: &'static str = "Memory.getAllTimeSamplingProfile";
220    type Response = GetAllTimeSamplingProfileReturns;
221}
222
223/// Retrieve native memory allocations profile
224/// collected since browser process startup.
225
226#[derive(Debug, Clone, Serialize, Deserialize, Default)]
227#[serde(rename_all = "camelCase")]
228pub struct GetBrowserSamplingProfileReturns {
229
230    pub profile: SamplingProfile,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize, Default)]
234pub struct GetBrowserSamplingProfileParams {}
235
236impl GetBrowserSamplingProfileParams { pub const METHOD: &'static str = "Memory.getBrowserSamplingProfile"; }
237
238impl crate::CdpCommand for GetBrowserSamplingProfileParams {
239    const METHOD: &'static str = "Memory.getBrowserSamplingProfile";
240    type Response = GetBrowserSamplingProfileReturns;
241}
242
243/// Retrieve native memory allocations profile collected since last
244/// 'startSampling' call.
245
246#[derive(Debug, Clone, Serialize, Deserialize, Default)]
247#[serde(rename_all = "camelCase")]
248pub struct GetSamplingProfileReturns {
249
250    pub profile: SamplingProfile,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize, Default)]
254pub struct GetSamplingProfileParams {}
255
256impl GetSamplingProfileParams { pub const METHOD: &'static str = "Memory.getSamplingProfile"; }
257
258impl crate::CdpCommand for GetSamplingProfileParams {
259    const METHOD: &'static str = "Memory.getSamplingProfile";
260    type Response = GetSamplingProfileReturns;
261}