Skip to main content

js_protocol/profiler/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Profile node. Holds callsite information, execution statistics and child nodes.
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct ProfileNode {
9    /// Unique id of the node.
10
11    pub id: u64,
12    /// Function location.
13
14    pub callFrame: crate::runtime::CallFrame,
15    /// Number of samples where this node was on top of the call stack.
16
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub hitCount: Option<u64>,
19    /// Child node ids.
20
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub children: Option<Vec<i64>>,
23    /// The reason of being not optimized. The function may be deoptimized or marked as don't
24    /// optimize.
25
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub deoptReason: Option<String>,
28    /// An array of source position ticks.
29
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub positionTicks: Option<Vec<PositionTickInfo>>,
32}
33
34/// Profile.
35
36#[derive(Debug, Clone, Serialize, Deserialize, Default)]
37#[serde(rename_all = "camelCase")]
38pub struct Profile {
39    /// The list of profile nodes. First item is the root node.
40
41    pub nodes: Vec<ProfileNode>,
42    /// Profiling start timestamp in microseconds.
43
44    pub startTime: f64,
45    /// Profiling end timestamp in microseconds.
46
47    pub endTime: f64,
48    /// Ids of samples top nodes.
49
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub samples: Option<Vec<i64>>,
52    /// Time intervals between adjacent samples in microseconds. The first delta is relative to the
53    /// profile startTime.
54
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub timeDeltas: Option<Vec<i64>>,
57}
58
59/// Specifies a number of samples attributed to a certain source position.
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct PositionTickInfo {
64    /// Source line number (1-based).
65
66    pub line: i64,
67    /// Number of samples attributed to the source line.
68
69    pub ticks: i64,
70}
71
72/// Coverage data for a source range.
73
74#[derive(Debug, Clone, Serialize, Deserialize, Default)]
75#[serde(rename_all = "camelCase")]
76pub struct CoverageRange {
77    /// JavaScript script source offset for the range start.
78
79    pub startOffset: i32,
80    /// JavaScript script source offset for the range end.
81
82    pub endOffset: i32,
83    /// Collected execution count of the source range.
84
85    pub count: u64,
86}
87
88/// Coverage data for a JavaScript function.
89
90#[derive(Debug, Clone, Serialize, Deserialize, Default)]
91#[serde(rename_all = "camelCase")]
92pub struct FunctionCoverage {
93    /// JavaScript function name.
94
95    pub functionName: String,
96    /// Source ranges inside the function with coverage data.
97
98    pub ranges: Vec<CoverageRange>,
99    /// Whether coverage data for this function has block granularity.
100
101    pub isBlockCoverage: bool,
102}
103
104/// Coverage data for a JavaScript script.
105
106#[derive(Debug, Clone, Serialize, Deserialize, Default)]
107#[serde(rename_all = "camelCase")]
108pub struct ScriptCoverage {
109    /// JavaScript script id.
110
111    pub scriptId: crate::runtime::ScriptId,
112    /// JavaScript script name or url.
113
114    pub url: String,
115    /// Functions contained in the script that has coverage data.
116
117    pub functions: Vec<FunctionCoverage>,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize, Default)]
121pub struct DisableParams {}
122
123impl DisableParams { pub const METHOD: &'static str = "Profiler.disable"; }
124
125impl crate::CdpCommand for DisableParams {
126    const METHOD: &'static str = "Profiler.disable";
127    type Response = crate::EmptyReturns;
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize, Default)]
131pub struct EnableParams {}
132
133impl EnableParams { pub const METHOD: &'static str = "Profiler.enable"; }
134
135impl crate::CdpCommand for EnableParams {
136    const METHOD: &'static str = "Profiler.enable";
137    type Response = crate::EmptyReturns;
138}
139
140/// Collect coverage data for the current isolate. The coverage data may be incomplete due to
141/// garbage collection.
142
143#[derive(Debug, Clone, Serialize, Deserialize, Default)]
144#[serde(rename_all = "camelCase")]
145pub struct GetBestEffortCoverageReturns {
146    /// Coverage data for the current isolate.
147
148    pub result: Vec<ScriptCoverage>,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize, Default)]
152pub struct GetBestEffortCoverageParams {}
153
154impl GetBestEffortCoverageParams { pub const METHOD: &'static str = "Profiler.getBestEffortCoverage"; }
155
156impl crate::CdpCommand for GetBestEffortCoverageParams {
157    const METHOD: &'static str = "Profiler.getBestEffortCoverage";
158    type Response = GetBestEffortCoverageReturns;
159}
160
161/// Changes CPU profiler sampling interval. Must be called before CPU profiles recording started.
162
163#[derive(Debug, Clone, Serialize, Deserialize, Default)]
164#[serde(rename_all = "camelCase")]
165pub struct SetSamplingIntervalParams {
166    /// New sampling interval in microseconds.
167
168    pub interval: i64,
169}
170
171impl SetSamplingIntervalParams { pub const METHOD: &'static str = "Profiler.setSamplingInterval"; }
172
173impl crate::CdpCommand for SetSamplingIntervalParams {
174    const METHOD: &'static str = "Profiler.setSamplingInterval";
175    type Response = crate::EmptyReturns;
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize, Default)]
179pub struct StartParams {}
180
181impl StartParams { pub const METHOD: &'static str = "Profiler.start"; }
182
183impl crate::CdpCommand for StartParams {
184    const METHOD: &'static str = "Profiler.start";
185    type Response = crate::EmptyReturns;
186}
187
188/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
189/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
190/// counters.
191
192#[derive(Debug, Clone, Serialize, Deserialize, Default)]
193#[serde(rename_all = "camelCase")]
194pub struct StartPreciseCoverageParams {
195    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
196
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub callCount: Option<bool>,
199    /// Collect block-based coverage.
200
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub detailed: Option<bool>,
203    /// Allow the backend to send updates on its own initiative
204
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub allowTriggeredUpdates: Option<bool>,
207}
208
209/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
210/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
211/// counters.
212
213#[derive(Debug, Clone, Serialize, Deserialize, Default)]
214#[serde(rename_all = "camelCase")]
215pub struct StartPreciseCoverageReturns {
216    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
217
218    pub timestamp: f64,
219}
220
221impl StartPreciseCoverageParams { pub const METHOD: &'static str = "Profiler.startPreciseCoverage"; }
222
223impl crate::CdpCommand for StartPreciseCoverageParams {
224    const METHOD: &'static str = "Profiler.startPreciseCoverage";
225    type Response = StartPreciseCoverageReturns;
226}
227
228
229#[derive(Debug, Clone, Serialize, Deserialize, Default)]
230#[serde(rename_all = "camelCase")]
231pub struct StopReturns {
232    /// Recorded profile.
233
234    pub profile: Profile,
235}
236
237#[derive(Debug, Clone, Serialize, Deserialize, Default)]
238pub struct StopParams {}
239
240impl StopParams { pub const METHOD: &'static str = "Profiler.stop"; }
241
242impl crate::CdpCommand for StopParams {
243    const METHOD: &'static str = "Profiler.stop";
244    type Response = StopReturns;
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize, Default)]
248pub struct StopPreciseCoverageParams {}
249
250impl StopPreciseCoverageParams { pub const METHOD: &'static str = "Profiler.stopPreciseCoverage"; }
251
252impl crate::CdpCommand for StopPreciseCoverageParams {
253    const METHOD: &'static str = "Profiler.stopPreciseCoverage";
254    type Response = crate::EmptyReturns;
255}
256
257/// Collect coverage data for the current isolate, and resets execution counters. Precise code
258/// coverage needs to have started.
259
260#[derive(Debug, Clone, Serialize, Deserialize, Default)]
261#[serde(rename_all = "camelCase")]
262pub struct TakePreciseCoverageReturns {
263    /// Coverage data for the current isolate.
264
265    pub result: Vec<ScriptCoverage>,
266    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
267
268    pub timestamp: f64,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize, Default)]
272pub struct TakePreciseCoverageParams {}
273
274impl TakePreciseCoverageParams { pub const METHOD: &'static str = "Profiler.takePreciseCoverage"; }
275
276impl crate::CdpCommand for TakePreciseCoverageParams {
277    const METHOD: &'static str = "Profiler.takePreciseCoverage";
278    type Response = TakePreciseCoverageReturns;
279}