Skip to main content

cdp_driver/protocol/
profiler.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! The `Profiler` domain.
5//!
6//! Types, command parameters and event payloads for the `Profiler`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9
10use serde::{Deserialize, Serialize};
11
12/// Profile node. Holds callsite information, execution statistics and child
13/// nodes.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct ProfileNode {
16    /// Unique id of the node.
17    pub id: i64,
18    /// Function location.
19    #[serde(rename = "callFrame")]
20    pub call_frame: crate::protocol::runtime::CallFrame,
21    /// Number of samples where this node was on top of the call stack.
22    #[serde(rename = "hitCount", default, skip_serializing_if = "Option::is_none")]
23    pub hit_count: Option<i64>,
24    /// Child node ids.
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub children: Option<Vec<i64>>,
27    /// The reason of being not optimized. The function may be deoptimized or
28    /// marked as don't optimize.
29    #[serde(
30        rename = "deoptReason",
31        default,
32        skip_serializing_if = "Option::is_none"
33    )]
34    pub deopt_reason: Option<String>,
35    /// An array of source position ticks.
36    #[serde(
37        rename = "positionTicks",
38        default,
39        skip_serializing_if = "Option::is_none"
40    )]
41    pub position_ticks: Option<Vec<PositionTickInfo>>,
42}
43
44/// Profile.
45#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
46pub struct Profile {
47    /// The list of profile nodes. First item is the root node.
48    pub nodes: Vec<ProfileNode>,
49    /// Profiling start timestamp in microseconds.
50    #[serde(rename = "startTime")]
51    pub start_time: f64,
52    /// Profiling end timestamp in microseconds.
53    #[serde(rename = "endTime")]
54    pub end_time: f64,
55    /// Ids of samples top nodes.
56    #[serde(default, skip_serializing_if = "Option::is_none")]
57    pub samples: Option<Vec<i64>>,
58    /// Time intervals between adjacent samples in microseconds. The first delta
59    /// is relative to the profile startTime.
60    #[serde(
61        rename = "timeDeltas",
62        default,
63        skip_serializing_if = "Option::is_none"
64    )]
65    pub time_deltas: Option<Vec<i64>>,
66}
67
68/// Specifies a number of samples attributed to a certain source position.
69#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
70pub struct PositionTickInfo {
71    /// Source line number (1-based).
72    pub line: i64,
73    /// Number of samples attributed to the source line.
74    pub ticks: i64,
75}
76
77/// Coverage data for a source range.
78#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
79pub struct CoverageRange {
80    /// JavaScript script source offset for the range start.
81    #[serde(rename = "startOffset")]
82    pub start_offset: i64,
83    /// JavaScript script source offset for the range end.
84    #[serde(rename = "endOffset")]
85    pub end_offset: i64,
86    /// Collected execution count of the source range.
87    pub count: i64,
88}
89
90/// Coverage data for a JavaScript function.
91#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
92pub struct FunctionCoverage {
93    /// JavaScript function name.
94    #[serde(rename = "functionName")]
95    pub function_name: String,
96    /// Source ranges inside the function with coverage data.
97    pub ranges: Vec<CoverageRange>,
98    /// Whether coverage data for this function has block granularity.
99    #[serde(rename = "isBlockCoverage")]
100    pub is_block_coverage: bool,
101}
102
103/// Coverage data for a JavaScript script.
104#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
105pub struct ScriptCoverage {
106    /// JavaScript script id.
107    #[serde(rename = "scriptId")]
108    pub script_id: crate::protocol::runtime::ScriptId,
109    /// JavaScript script name or url.
110    pub url: String,
111    /// Functions contained in the script that has coverage data.
112    pub functions: Vec<FunctionCoverage>,
113}
114
115/// Parameters of `Profiler.disable`.
116#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
117pub struct DisableParams {}
118
119impl crate::typed::Command for DisableParams {
120    const METHOD: &'static str = "Profiler.disable";
121    type Returns = crate::typed::NoReturns;
122}
123
124/// Parameters of `Profiler.enable`.
125#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
126pub struct EnableParams {}
127
128impl crate::typed::Command for EnableParams {
129    const METHOD: &'static str = "Profiler.enable";
130    type Returns = crate::typed::NoReturns;
131}
132
133/// Collect coverage data for the current isolate. The coverage data may be
134/// incomplete due to garbage collection.
135///
136/// Parameters of `Profiler.getBestEffortCoverage`.
137#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
138pub struct GetBestEffortCoverageParams {}
139
140/// What `Profiler.getBestEffortCoverage` answers with.
141#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
142pub struct GetBestEffortCoverageReturns {
143    /// Coverage data for the current isolate.
144    pub result: Vec<ScriptCoverage>,
145}
146
147impl crate::typed::Command for GetBestEffortCoverageParams {
148    const METHOD: &'static str = "Profiler.getBestEffortCoverage";
149    type Returns = GetBestEffortCoverageReturns;
150}
151
152/// Changes CPU profiler sampling interval. Must be called before CPU profiles
153/// recording started.
154///
155/// Parameters of `Profiler.setSamplingInterval`.
156#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
157pub struct SetSamplingIntervalParams {
158    /// New sampling interval in microseconds.
159    pub interval: i64,
160}
161
162impl crate::typed::Command for SetSamplingIntervalParams {
163    const METHOD: &'static str = "Profiler.setSamplingInterval";
164    type Returns = crate::typed::NoReturns;
165}
166
167/// Parameters of `Profiler.start`.
168#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
169pub struct StartParams {}
170
171impl crate::typed::Command for StartParams {
172    const METHOD: &'static str = "Profiler.start";
173    type Returns = crate::typed::NoReturns;
174}
175
176/// Enable precise code coverage. Coverage data for JavaScript executed before
177/// enabling precise code coverage may be incomplete. Enabling prevents
178/// running optimized code and resets execution counters.
179///
180/// Parameters of `Profiler.startPreciseCoverage`.
181#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
182pub struct StartPreciseCoverageParams {
183    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
184    #[serde(rename = "callCount", default, skip_serializing_if = "Option::is_none")]
185    pub call_count: Option<bool>,
186    /// Collect block-based coverage.
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub detailed: Option<bool>,
189    /// Allow the backend to send updates on its own initiative
190    #[serde(
191        rename = "allowTriggeredUpdates",
192        default,
193        skip_serializing_if = "Option::is_none"
194    )]
195    pub allow_triggered_updates: Option<bool>,
196}
197
198/// What `Profiler.startPreciseCoverage` answers with.
199#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
200pub struct StartPreciseCoverageReturns {
201    /// Monotonically increasing time (in seconds) when the coverage update was
202    /// taken in the backend.
203    pub timestamp: f64,
204}
205
206impl crate::typed::Command for StartPreciseCoverageParams {
207    const METHOD: &'static str = "Profiler.startPreciseCoverage";
208    type Returns = StartPreciseCoverageReturns;
209}
210
211/// Parameters of `Profiler.stop`.
212#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
213pub struct StopParams {}
214
215/// What `Profiler.stop` answers with.
216#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
217pub struct StopReturns {
218    /// Recorded profile.
219    pub profile: Profile,
220}
221
222impl crate::typed::Command for StopParams {
223    const METHOD: &'static str = "Profiler.stop";
224    type Returns = StopReturns;
225}
226
227/// Disable precise code coverage. Disabling releases unnecessary execution
228/// count records and allows executing optimized code.
229///
230/// Parameters of `Profiler.stopPreciseCoverage`.
231#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
232pub struct StopPreciseCoverageParams {}
233
234impl crate::typed::Command for StopPreciseCoverageParams {
235    const METHOD: &'static str = "Profiler.stopPreciseCoverage";
236    type Returns = crate::typed::NoReturns;
237}
238
239/// Collect coverage data for the current isolate, and resets execution
240/// counters. Precise code coverage needs to have started.
241///
242/// Parameters of `Profiler.takePreciseCoverage`.
243#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
244pub struct TakePreciseCoverageParams {}
245
246/// What `Profiler.takePreciseCoverage` answers with.
247#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
248pub struct TakePreciseCoverageReturns {
249    /// Coverage data for the current isolate.
250    pub result: Vec<ScriptCoverage>,
251    /// Monotonically increasing time (in seconds) when the coverage update was
252    /// taken in the backend.
253    pub timestamp: f64,
254}
255
256impl crate::typed::Command for TakePreciseCoverageParams {
257    const METHOD: &'static str = "Profiler.takePreciseCoverage";
258    type Returns = TakePreciseCoverageReturns;
259}
260
261/// Payload of the `Profiler.consoleProfileFinished` event.
262#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
263pub struct ConsoleProfileFinishedEvent {
264    pub id: String,
265    /// Location of console.profileEnd().
266    pub location: crate::protocol::debugger::Location,
267    pub profile: Profile,
268    /// Profile title passed as an argument to console.profile().
269    #[serde(default, skip_serializing_if = "Option::is_none")]
270    pub title: Option<String>,
271}
272
273impl crate::typed::Event for ConsoleProfileFinishedEvent {
274    const METHOD: &'static str = "Profiler.consoleProfileFinished";
275}
276
277/// Sent when new profile recording is started using console.profile() call.
278///
279/// Payload of the `Profiler.consoleProfileStarted` event.
280#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
281pub struct ConsoleProfileStartedEvent {
282    pub id: String,
283    /// Location of console.profile().
284    pub location: crate::protocol::debugger::Location,
285    /// Profile title passed as an argument to console.profile().
286    #[serde(default, skip_serializing_if = "Option::is_none")]
287    pub title: Option<String>,
288}
289
290impl crate::typed::Event for ConsoleProfileStartedEvent {
291    const METHOD: &'static str = "Profiler.consoleProfileStarted";
292}
293
294/// Reports coverage delta since the last poll (either from an event like
295/// this, or from `takePreciseCoverage` for the current isolate. May only be
296/// sent if precise code coverage has been started. This event can be trigged
297/// by the embedder to, for example, trigger collection of coverage data
298/// immediately at a certain point in time.
299///
300/// Experimental: may change without notice.
301///
302/// Payload of the `Profiler.preciseCoverageDeltaUpdate` event.
303#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
304pub struct PreciseCoverageDeltaUpdateEvent {
305    /// Monotonically increasing time (in seconds) when the coverage update was
306    /// taken in the backend.
307    pub timestamp: f64,
308    /// Identifier for distinguishing coverage events.
309    pub occasion: String,
310    /// Coverage data for the current isolate.
311    pub result: Vec<ScriptCoverage>,
312}
313
314impl crate::typed::Event for PreciseCoverageDeltaUpdateEvent {
315    const METHOD: &'static str = "Profiler.preciseCoverageDeltaUpdate";
316}