Skip to main content

js_protocol/heapprofiler/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Heap snapshot object id.
5
6pub type HeapSnapshotObjectId = String;
7
8/// Sampling Heap Profile node. Holds callsite information, allocation statistics and child nodes.
9
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct SamplingHeapProfileNode {
13    /// Function location.
14
15    pub callFrame: crate::runtime::CallFrame,
16    /// Allocations size in bytes for the node excluding children.
17
18    pub selfSize: f64,
19    /// Node id. Ids are unique across all profiles collected between startSampling and stopSampling.
20
21    pub id: u64,
22    /// Child nodes.
23
24    pub children: Vec<SamplingHeapProfileNode>,
25}
26
27/// A single sample from a sampling profile.
28
29#[derive(Debug, Clone, Serialize, Deserialize, Default)]
30#[serde(rename_all = "camelCase")]
31pub struct SamplingHeapProfileSample {
32    /// Allocation size in bytes attributed to the sample.
33
34    pub size: f64,
35    /// Id of the corresponding profile tree node.
36
37    pub nodeId: u64,
38    /// Time-ordered sample ordinal number. It is unique across all profiles retrieved
39    /// between startSampling and stopSampling.
40
41    pub ordinal: f64,
42}
43
44/// Sampling profile.
45
46#[derive(Debug, Clone, Serialize, Deserialize, Default)]
47#[serde(rename_all = "camelCase")]
48pub struct SamplingHeapProfile {
49
50    pub head: SamplingHeapProfileNode,
51
52    pub samples: Vec<SamplingHeapProfileSample>,
53}
54
55/// Enables console to refer to the node with given id via $x (see Command Line API for more details
56/// $x functions).
57
58#[derive(Debug, Clone, Serialize, Deserialize, Default)]
59#[serde(rename_all = "camelCase")]
60pub struct AddInspectedHeapObjectParams {
61    /// Heap snapshot object id to be accessible by means of $x command line API.
62
63    pub heapObjectId: HeapSnapshotObjectId,
64}
65
66impl AddInspectedHeapObjectParams { pub const METHOD: &'static str = "HeapProfiler.addInspectedHeapObject"; }
67
68impl crate::CdpCommand for AddInspectedHeapObjectParams {
69    const METHOD: &'static str = "HeapProfiler.addInspectedHeapObject";
70    type Response = crate::EmptyReturns;
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74pub struct CollectGarbageParams {}
75
76impl CollectGarbageParams { pub const METHOD: &'static str = "HeapProfiler.collectGarbage"; }
77
78impl crate::CdpCommand for CollectGarbageParams {
79    const METHOD: &'static str = "HeapProfiler.collectGarbage";
80    type Response = crate::EmptyReturns;
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize, Default)]
84pub struct DisableParams {}
85
86impl DisableParams { pub const METHOD: &'static str = "HeapProfiler.disable"; }
87
88impl crate::CdpCommand for DisableParams {
89    const METHOD: &'static str = "HeapProfiler.disable";
90    type Response = crate::EmptyReturns;
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize, Default)]
94pub struct EnableParams {}
95
96impl EnableParams { pub const METHOD: &'static str = "HeapProfiler.enable"; }
97
98impl crate::CdpCommand for EnableParams {
99    const METHOD: &'static str = "HeapProfiler.enable";
100    type Response = crate::EmptyReturns;
101}
102
103
104#[derive(Debug, Clone, Serialize, Deserialize, Default)]
105#[serde(rename_all = "camelCase")]
106pub struct GetHeapObjectIdParams {
107    /// Identifier of the object to get heap object id for.
108
109    pub objectId: crate::runtime::RemoteObjectId,
110}
111
112
113#[derive(Debug, Clone, Serialize, Deserialize, Default)]
114#[serde(rename_all = "camelCase")]
115pub struct GetHeapObjectIdReturns {
116    /// Id of the heap snapshot object corresponding to the passed remote object id.
117
118    pub heapSnapshotObjectId: HeapSnapshotObjectId,
119}
120
121impl GetHeapObjectIdParams { pub const METHOD: &'static str = "HeapProfiler.getHeapObjectId"; }
122
123impl crate::CdpCommand for GetHeapObjectIdParams {
124    const METHOD: &'static str = "HeapProfiler.getHeapObjectId";
125    type Response = GetHeapObjectIdReturns;
126}
127
128
129#[derive(Debug, Clone, Serialize, Deserialize, Default)]
130#[serde(rename_all = "camelCase")]
131pub struct GetObjectByHeapObjectIdParams {
132
133    pub objectId: HeapSnapshotObjectId,
134    /// Symbolic group name that can be used to release multiple objects.
135
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub objectGroup: Option<String>,
138}
139
140
141#[derive(Debug, Clone, Serialize, Deserialize, Default)]
142#[serde(rename_all = "camelCase")]
143pub struct GetObjectByHeapObjectIdReturns {
144    /// Evaluation result.
145
146    pub result: crate::runtime::RemoteObject,
147}
148
149impl GetObjectByHeapObjectIdParams { pub const METHOD: &'static str = "HeapProfiler.getObjectByHeapObjectId"; }
150
151impl crate::CdpCommand for GetObjectByHeapObjectIdParams {
152    const METHOD: &'static str = "HeapProfiler.getObjectByHeapObjectId";
153    type Response = GetObjectByHeapObjectIdReturns;
154}
155
156
157#[derive(Debug, Clone, Serialize, Deserialize, Default)]
158#[serde(rename_all = "camelCase")]
159pub struct GetSamplingProfileReturns {
160    /// Return the sampling profile being collected.
161
162    pub profile: SamplingHeapProfile,
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize, Default)]
166pub struct GetSamplingProfileParams {}
167
168impl GetSamplingProfileParams { pub const METHOD: &'static str = "HeapProfiler.getSamplingProfile"; }
169
170impl crate::CdpCommand for GetSamplingProfileParams {
171    const METHOD: &'static str = "HeapProfiler.getSamplingProfile";
172    type Response = GetSamplingProfileReturns;
173}
174
175
176#[derive(Debug, Clone, Serialize, Deserialize, Default)]
177#[serde(rename_all = "camelCase")]
178pub struct StartSamplingParams {
179    /// Average sample interval in bytes. Poisson distribution is used for the intervals. The
180    /// default value is 32768 bytes.
181
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub samplingInterval: Option<f64>,
184    /// Maximum stack depth. The default value is 128.
185
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub stackDepth: Option<f64>,
188    /// By default, the sampling heap profiler reports only objects which are
189    /// still alive when the profile is returned via getSamplingProfile or
190    /// stopSampling, which is useful for determining what functions contribute
191    /// the most to steady-state memory usage. This flag instructs the sampling
192    /// heap profiler to also include information about objects discarded by
193    /// major GC, which will show which functions cause large temporary memory
194    /// usage or long GC pauses.
195
196    #[serde(skip_serializing_if = "Option::is_none")]
197    pub includeObjectsCollectedByMajorGC: Option<bool>,
198    /// By default, the sampling heap profiler reports only objects which are
199    /// still alive when the profile is returned via getSamplingProfile or
200    /// stopSampling, which is useful for determining what functions contribute
201    /// the most to steady-state memory usage. This flag instructs the sampling
202    /// heap profiler to also include information about objects discarded by
203    /// minor GC, which is useful when tuning a latency-sensitive application
204    /// for minimal GC activity.
205
206    #[serde(skip_serializing_if = "Option::is_none")]
207    pub includeObjectsCollectedByMinorGC: Option<bool>,
208}
209
210impl StartSamplingParams { pub const METHOD: &'static str = "HeapProfiler.startSampling"; }
211
212impl crate::CdpCommand for StartSamplingParams {
213    const METHOD: &'static str = "HeapProfiler.startSampling";
214    type Response = crate::EmptyReturns;
215}
216
217
218#[derive(Debug, Clone, Serialize, Deserialize, Default)]
219#[serde(rename_all = "camelCase")]
220pub struct StartTrackingHeapObjectsParams {
221
222    #[serde(skip_serializing_if = "Option::is_none")]
223    pub trackAllocations: Option<bool>,
224}
225
226impl StartTrackingHeapObjectsParams { pub const METHOD: &'static str = "HeapProfiler.startTrackingHeapObjects"; }
227
228impl crate::CdpCommand for StartTrackingHeapObjectsParams {
229    const METHOD: &'static str = "HeapProfiler.startTrackingHeapObjects";
230    type Response = crate::EmptyReturns;
231}
232
233
234#[derive(Debug, Clone, Serialize, Deserialize, Default)]
235#[serde(rename_all = "camelCase")]
236pub struct StopSamplingReturns {
237    /// Recorded sampling heap profile.
238
239    pub profile: SamplingHeapProfile,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize, Default)]
243pub struct StopSamplingParams {}
244
245impl StopSamplingParams { pub const METHOD: &'static str = "HeapProfiler.stopSampling"; }
246
247impl crate::CdpCommand for StopSamplingParams {
248    const METHOD: &'static str = "HeapProfiler.stopSampling";
249    type Response = StopSamplingReturns;
250}
251
252
253#[derive(Debug, Clone, Serialize, Deserialize, Default)]
254#[serde(rename_all = "camelCase")]
255pub struct StopTrackingHeapObjectsParams {
256    /// If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken
257    /// when the tracking is stopped.
258
259    #[serde(skip_serializing_if = "Option::is_none")]
260    pub reportProgress: Option<bool>,
261    /// Deprecated in favor of 'exposeInternals'.
262
263    #[serde(skip_serializing_if = "Option::is_none")]
264    pub treatGlobalObjectsAsRoots: Option<bool>,
265    /// If true, numerical values are included in the snapshot
266
267    #[serde(skip_serializing_if = "Option::is_none")]
268    pub captureNumericValue: Option<bool>,
269    /// If true, exposes internals of the snapshot.
270
271    #[serde(skip_serializing_if = "Option::is_none")]
272    pub exposeInternals: Option<bool>,
273}
274
275impl StopTrackingHeapObjectsParams { pub const METHOD: &'static str = "HeapProfiler.stopTrackingHeapObjects"; }
276
277impl crate::CdpCommand for StopTrackingHeapObjectsParams {
278    const METHOD: &'static str = "HeapProfiler.stopTrackingHeapObjects";
279    type Response = crate::EmptyReturns;
280}
281
282
283#[derive(Debug, Clone, Serialize, Deserialize, Default)]
284#[serde(rename_all = "camelCase")]
285pub struct TakeHeapSnapshotParams {
286    /// If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken.
287
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub reportProgress: Option<bool>,
290    /// If true, a raw snapshot without artificial roots will be generated.
291    /// Deprecated in favor of 'exposeInternals'.
292
293    #[serde(skip_serializing_if = "Option::is_none")]
294    pub treatGlobalObjectsAsRoots: Option<bool>,
295    /// If true, numerical values are included in the snapshot
296
297    #[serde(skip_serializing_if = "Option::is_none")]
298    pub captureNumericValue: Option<bool>,
299    /// If true, exposes internals of the snapshot.
300
301    #[serde(skip_serializing_if = "Option::is_none")]
302    pub exposeInternals: Option<bool>,
303}
304
305impl TakeHeapSnapshotParams { pub const METHOD: &'static str = "HeapProfiler.takeHeapSnapshot"; }
306
307impl crate::CdpCommand for TakeHeapSnapshotParams {
308    const METHOD: &'static str = "HeapProfiler.takeHeapSnapshot";
309    type Response = crate::EmptyReturns;
310}