Skip to main content

js_protocol/profiler/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5/// Profile node. Holds callsite information, execution statistics and child nodes.
6
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct ProfileNode<'a> {
10    /// Unique id of the node.
11    id: u64,
12    /// Function location.
13    #[serde(rename = "callFrame")]
14    call_frame: crate::runtime::CallFrame<'a>,
15    /// Number of samples where this node was on top of the call stack.
16    #[serde(skip_serializing_if = "Option::is_none", rename = "hitCount")]
17    hit_count: Option<u64>,
18    /// Child node ids.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    children: Option<Vec<i64>>,
21    /// The reason of being not optimized. The function may be deoptimized or marked as don't
22    /// optimize.
23    #[serde(skip_serializing_if = "Option::is_none", rename = "deoptReason")]
24    deopt_reason: Option<Cow<'a, str>>,
25    /// An array of source position ticks.
26    #[serde(skip_serializing_if = "Option::is_none", rename = "positionTicks")]
27    position_ticks: Option<Vec<PositionTickInfo>>,
28}
29
30impl<'a> ProfileNode<'a> {
31    /// Creates a builder for this type with the required parameters:
32    /// * `id`: Unique id of the node.
33    /// * `call_frame`: Function location.
34    pub fn builder(id: u64, call_frame: crate::runtime::CallFrame<'a>) -> ProfileNodeBuilder<'a> {
35        ProfileNodeBuilder {
36            id: id,
37            call_frame: call_frame,
38            hit_count: None,
39            children: None,
40            deopt_reason: None,
41            position_ticks: None,
42        }
43    }
44    /// Unique id of the node.
45    pub fn id(&self) -> u64 { self.id }
46    /// Function location.
47    pub fn call_frame(&self) -> &crate::runtime::CallFrame<'a> { &self.call_frame }
48    /// Number of samples where this node was on top of the call stack.
49    pub fn hit_count(&self) -> Option<u64> { self.hit_count }
50    /// Child node ids.
51    pub fn children(&self) -> Option<&[i64]> { self.children.as_deref() }
52    /// The reason of being not optimized. The function may be deoptimized or marked as don't
53    /// optimize.
54    pub fn deopt_reason(&self) -> Option<&str> { self.deopt_reason.as_deref() }
55    /// An array of source position ticks.
56    pub fn position_ticks(&self) -> Option<&[PositionTickInfo]> { self.position_ticks.as_deref() }
57}
58
59
60pub struct ProfileNodeBuilder<'a> {
61    id: u64,
62    call_frame: crate::runtime::CallFrame<'a>,
63    hit_count: Option<u64>,
64    children: Option<Vec<i64>>,
65    deopt_reason: Option<Cow<'a, str>>,
66    position_ticks: Option<Vec<PositionTickInfo>>,
67}
68
69impl<'a> ProfileNodeBuilder<'a> {
70    /// Number of samples where this node was on top of the call stack.
71    pub fn hit_count(mut self, hit_count: u64) -> Self { self.hit_count = Some(hit_count); self }
72    /// Child node ids.
73    pub fn children(mut self, children: Vec<i64>) -> Self { self.children = Some(children); self }
74    /// The reason of being not optimized. The function may be deoptimized or marked as don't
75    /// optimize.
76    pub fn deopt_reason(mut self, deopt_reason: impl Into<Cow<'a, str>>) -> Self { self.deopt_reason = Some(deopt_reason.into()); self }
77    /// An array of source position ticks.
78    pub fn position_ticks(mut self, position_ticks: Vec<PositionTickInfo>) -> Self { self.position_ticks = Some(position_ticks); self }
79    pub fn build(self) -> ProfileNode<'a> {
80        ProfileNode {
81            id: self.id,
82            call_frame: self.call_frame,
83            hit_count: self.hit_count,
84            children: self.children,
85            deopt_reason: self.deopt_reason,
86            position_ticks: self.position_ticks,
87        }
88    }
89}
90
91/// Profile.
92
93#[derive(Debug, Clone, Serialize, Deserialize, Default)]
94#[serde(rename_all = "camelCase")]
95pub struct Profile<'a> {
96    /// The list of profile nodes. First item is the root node.
97    nodes: Vec<ProfileNode<'a>>,
98    /// Profiling start timestamp in microseconds.
99    #[serde(rename = "startTime")]
100    start_time: f64,
101    /// Profiling end timestamp in microseconds.
102    #[serde(rename = "endTime")]
103    end_time: f64,
104    /// Ids of samples top nodes.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    samples: Option<Vec<i64>>,
107    /// Time intervals between adjacent samples in microseconds. The first delta is relative to the
108    /// profile startTime.
109    #[serde(skip_serializing_if = "Option::is_none", rename = "timeDeltas")]
110    time_deltas: Option<Vec<i64>>,
111}
112
113impl<'a> Profile<'a> {
114    /// Creates a builder for this type with the required parameters:
115    /// * `nodes`: The list of profile nodes. First item is the root node.
116    /// * `start_time`: Profiling start timestamp in microseconds.
117    /// * `end_time`: Profiling end timestamp in microseconds.
118    pub fn builder(nodes: Vec<ProfileNode<'a>>, start_time: f64, end_time: f64) -> ProfileBuilder<'a> {
119        ProfileBuilder {
120            nodes: nodes,
121            start_time: start_time,
122            end_time: end_time,
123            samples: None,
124            time_deltas: None,
125        }
126    }
127    /// The list of profile nodes. First item is the root node.
128    pub fn nodes(&self) -> &[ProfileNode<'a>] { &self.nodes }
129    /// Profiling start timestamp in microseconds.
130    pub fn start_time(&self) -> f64 { self.start_time }
131    /// Profiling end timestamp in microseconds.
132    pub fn end_time(&self) -> f64 { self.end_time }
133    /// Ids of samples top nodes.
134    pub fn samples(&self) -> Option<&[i64]> { self.samples.as_deref() }
135    /// Time intervals between adjacent samples in microseconds. The first delta is relative to the
136    /// profile startTime.
137    pub fn time_deltas(&self) -> Option<&[i64]> { self.time_deltas.as_deref() }
138}
139
140
141pub struct ProfileBuilder<'a> {
142    nodes: Vec<ProfileNode<'a>>,
143    start_time: f64,
144    end_time: f64,
145    samples: Option<Vec<i64>>,
146    time_deltas: Option<Vec<i64>>,
147}
148
149impl<'a> ProfileBuilder<'a> {
150    /// Ids of samples top nodes.
151    pub fn samples(mut self, samples: Vec<i64>) -> Self { self.samples = Some(samples); self }
152    /// Time intervals between adjacent samples in microseconds. The first delta is relative to the
153    /// profile startTime.
154    pub fn time_deltas(mut self, time_deltas: Vec<i64>) -> Self { self.time_deltas = Some(time_deltas); self }
155    pub fn build(self) -> Profile<'a> {
156        Profile {
157            nodes: self.nodes,
158            start_time: self.start_time,
159            end_time: self.end_time,
160            samples: self.samples,
161            time_deltas: self.time_deltas,
162        }
163    }
164}
165
166/// Specifies a number of samples attributed to a certain source position.
167
168#[derive(Debug, Clone, Serialize, Deserialize, Default)]
169#[serde(rename_all = "camelCase")]
170pub struct PositionTickInfo {
171    /// Source line number (1-based).
172    line: i64,
173    /// Number of samples attributed to the source line.
174    ticks: i64,
175}
176
177impl PositionTickInfo {
178    /// Creates a builder for this type with the required parameters:
179    /// * `line`: Source line number (1-based).
180    /// * `ticks`: Number of samples attributed to the source line.
181    pub fn builder(line: i64, ticks: i64) -> PositionTickInfoBuilder {
182        PositionTickInfoBuilder {
183            line: line,
184            ticks: ticks,
185        }
186    }
187    /// Source line number (1-based).
188    pub fn line(&self) -> i64 { self.line }
189    /// Number of samples attributed to the source line.
190    pub fn ticks(&self) -> i64 { self.ticks }
191}
192
193
194pub struct PositionTickInfoBuilder {
195    line: i64,
196    ticks: i64,
197}
198
199impl PositionTickInfoBuilder {
200    pub fn build(self) -> PositionTickInfo {
201        PositionTickInfo {
202            line: self.line,
203            ticks: self.ticks,
204        }
205    }
206}
207
208/// Coverage data for a source range.
209
210#[derive(Debug, Clone, Serialize, Deserialize, Default)]
211#[serde(rename_all = "camelCase")]
212pub struct CoverageRange {
213    /// JavaScript script source offset for the range start.
214    #[serde(rename = "startOffset")]
215    start_offset: i32,
216    /// JavaScript script source offset for the range end.
217    #[serde(rename = "endOffset")]
218    end_offset: i32,
219    /// Collected execution count of the source range.
220    count: u64,
221}
222
223impl CoverageRange {
224    /// Creates a builder for this type with the required parameters:
225    /// * `start_offset`: JavaScript script source offset for the range start.
226    /// * `end_offset`: JavaScript script source offset for the range end.
227    /// * `count`: Collected execution count of the source range.
228    pub fn builder(start_offset: i32, end_offset: i32, count: u64) -> CoverageRangeBuilder {
229        CoverageRangeBuilder {
230            start_offset: start_offset,
231            end_offset: end_offset,
232            count: count,
233        }
234    }
235    /// JavaScript script source offset for the range start.
236    pub fn start_offset(&self) -> i32 { self.start_offset }
237    /// JavaScript script source offset for the range end.
238    pub fn end_offset(&self) -> i32 { self.end_offset }
239    /// Collected execution count of the source range.
240    pub fn count(&self) -> u64 { self.count }
241}
242
243
244pub struct CoverageRangeBuilder {
245    start_offset: i32,
246    end_offset: i32,
247    count: u64,
248}
249
250impl CoverageRangeBuilder {
251    pub fn build(self) -> CoverageRange {
252        CoverageRange {
253            start_offset: self.start_offset,
254            end_offset: self.end_offset,
255            count: self.count,
256        }
257    }
258}
259
260/// Coverage data for a JavaScript function.
261
262#[derive(Debug, Clone, Serialize, Deserialize, Default)]
263#[serde(rename_all = "camelCase")]
264pub struct FunctionCoverage<'a> {
265    /// JavaScript function name.
266    #[serde(rename = "functionName")]
267    function_name: Cow<'a, str>,
268    /// Source ranges inside the function with coverage data.
269    ranges: Vec<CoverageRange>,
270    /// Whether coverage data for this function has block granularity.
271    #[serde(rename = "isBlockCoverage")]
272    is_block_coverage: bool,
273}
274
275impl<'a> FunctionCoverage<'a> {
276    /// Creates a builder for this type with the required parameters:
277    /// * `function_name`: JavaScript function name.
278    /// * `ranges`: Source ranges inside the function with coverage data.
279    /// * `is_block_coverage`: Whether coverage data for this function has block granularity.
280    pub fn builder(function_name: impl Into<Cow<'a, str>>, ranges: Vec<CoverageRange>, is_block_coverage: bool) -> FunctionCoverageBuilder<'a> {
281        FunctionCoverageBuilder {
282            function_name: function_name.into(),
283            ranges: ranges,
284            is_block_coverage: is_block_coverage,
285        }
286    }
287    /// JavaScript function name.
288    pub fn function_name(&self) -> &str { self.function_name.as_ref() }
289    /// Source ranges inside the function with coverage data.
290    pub fn ranges(&self) -> &[CoverageRange] { &self.ranges }
291    /// Whether coverage data for this function has block granularity.
292    pub fn is_block_coverage(&self) -> bool { self.is_block_coverage }
293}
294
295
296pub struct FunctionCoverageBuilder<'a> {
297    function_name: Cow<'a, str>,
298    ranges: Vec<CoverageRange>,
299    is_block_coverage: bool,
300}
301
302impl<'a> FunctionCoverageBuilder<'a> {
303    pub fn build(self) -> FunctionCoverage<'a> {
304        FunctionCoverage {
305            function_name: self.function_name,
306            ranges: self.ranges,
307            is_block_coverage: self.is_block_coverage,
308        }
309    }
310}
311
312/// Coverage data for a JavaScript script.
313
314#[derive(Debug, Clone, Serialize, Deserialize, Default)]
315#[serde(rename_all = "camelCase")]
316pub struct ScriptCoverage<'a> {
317    /// JavaScript script id.
318    #[serde(rename = "scriptId")]
319    script_id: crate::runtime::ScriptId<'a>,
320    /// JavaScript script name or url.
321    url: Cow<'a, str>,
322    /// Functions contained in the script that has coverage data.
323    functions: Vec<FunctionCoverage<'a>>,
324}
325
326impl<'a> ScriptCoverage<'a> {
327    /// Creates a builder for this type with the required parameters:
328    /// * `script_id`: JavaScript script id.
329    /// * `url`: JavaScript script name or url.
330    /// * `functions`: Functions contained in the script that has coverage data.
331    pub fn builder(script_id: crate::runtime::ScriptId<'a>, url: impl Into<Cow<'a, str>>, functions: Vec<FunctionCoverage<'a>>) -> ScriptCoverageBuilder<'a> {
332        ScriptCoverageBuilder {
333            script_id: script_id,
334            url: url.into(),
335            functions: functions,
336        }
337    }
338    /// JavaScript script id.
339    pub fn script_id(&self) -> &crate::runtime::ScriptId<'a> { &self.script_id }
340    /// JavaScript script name or url.
341    pub fn url(&self) -> &str { self.url.as_ref() }
342    /// Functions contained in the script that has coverage data.
343    pub fn functions(&self) -> &[FunctionCoverage<'a>] { &self.functions }
344}
345
346
347pub struct ScriptCoverageBuilder<'a> {
348    script_id: crate::runtime::ScriptId<'a>,
349    url: Cow<'a, str>,
350    functions: Vec<FunctionCoverage<'a>>,
351}
352
353impl<'a> ScriptCoverageBuilder<'a> {
354    pub fn build(self) -> ScriptCoverage<'a> {
355        ScriptCoverage {
356            script_id: self.script_id,
357            url: self.url,
358            functions: self.functions,
359        }
360    }
361}
362
363#[derive(Debug, Clone, Serialize, Deserialize, Default)]
364pub struct DisableParams {}
365
366impl DisableParams { pub const METHOD: &'static str = "Profiler.disable"; }
367
368impl<'a> crate::CdpCommand<'a> for DisableParams {
369    const METHOD: &'static str = "Profiler.disable";
370    type Response = crate::EmptyReturns;
371}
372
373#[derive(Debug, Clone, Serialize, Deserialize, Default)]
374pub struct EnableParams {}
375
376impl EnableParams { pub const METHOD: &'static str = "Profiler.enable"; }
377
378impl<'a> crate::CdpCommand<'a> for EnableParams {
379    const METHOD: &'static str = "Profiler.enable";
380    type Response = crate::EmptyReturns;
381}
382
383/// Collect coverage data for the current isolate. The coverage data may be incomplete due to
384/// garbage collection.
385
386#[derive(Debug, Clone, Serialize, Deserialize, Default)]
387#[serde(rename_all = "camelCase")]
388pub struct GetBestEffortCoverageReturns<'a> {
389    /// Coverage data for the current isolate.
390    result: Vec<ScriptCoverage<'a>>,
391}
392
393impl<'a> GetBestEffortCoverageReturns<'a> {
394    /// Creates a builder for this type with the required parameters:
395    /// * `result`: Coverage data for the current isolate.
396    pub fn builder(result: Vec<ScriptCoverage<'a>>) -> GetBestEffortCoverageReturnsBuilder<'a> {
397        GetBestEffortCoverageReturnsBuilder {
398            result: result,
399        }
400    }
401    /// Coverage data for the current isolate.
402    pub fn result(&self) -> &[ScriptCoverage<'a>] { &self.result }
403}
404
405
406pub struct GetBestEffortCoverageReturnsBuilder<'a> {
407    result: Vec<ScriptCoverage<'a>>,
408}
409
410impl<'a> GetBestEffortCoverageReturnsBuilder<'a> {
411    pub fn build(self) -> GetBestEffortCoverageReturns<'a> {
412        GetBestEffortCoverageReturns {
413            result: self.result,
414        }
415    }
416}
417
418#[derive(Debug, Clone, Serialize, Deserialize, Default)]
419pub struct GetBestEffortCoverageParams {}
420
421impl GetBestEffortCoverageParams { pub const METHOD: &'static str = "Profiler.getBestEffortCoverage"; }
422
423impl<'a> crate::CdpCommand<'a> for GetBestEffortCoverageParams {
424    const METHOD: &'static str = "Profiler.getBestEffortCoverage";
425    type Response = GetBestEffortCoverageReturns<'a>;
426}
427
428/// Changes CPU profiler sampling interval. Must be called before CPU profiles recording started.
429
430#[derive(Debug, Clone, Serialize, Deserialize, Default)]
431#[serde(rename_all = "camelCase")]
432pub struct SetSamplingIntervalParams {
433    /// New sampling interval in microseconds.
434    interval: i64,
435}
436
437impl SetSamplingIntervalParams {
438    /// Creates a builder for this type with the required parameters:
439    /// * `interval`: New sampling interval in microseconds.
440    pub fn builder(interval: i64) -> SetSamplingIntervalParamsBuilder {
441        SetSamplingIntervalParamsBuilder {
442            interval: interval,
443        }
444    }
445    /// New sampling interval in microseconds.
446    pub fn interval(&self) -> i64 { self.interval }
447}
448
449
450pub struct SetSamplingIntervalParamsBuilder {
451    interval: i64,
452}
453
454impl SetSamplingIntervalParamsBuilder {
455    pub fn build(self) -> SetSamplingIntervalParams {
456        SetSamplingIntervalParams {
457            interval: self.interval,
458        }
459    }
460}
461
462impl SetSamplingIntervalParams { pub const METHOD: &'static str = "Profiler.setSamplingInterval"; }
463
464impl<'a> crate::CdpCommand<'a> for SetSamplingIntervalParams {
465    const METHOD: &'static str = "Profiler.setSamplingInterval";
466    type Response = crate::EmptyReturns;
467}
468
469#[derive(Debug, Clone, Serialize, Deserialize, Default)]
470pub struct StartParams {}
471
472impl StartParams { pub const METHOD: &'static str = "Profiler.start"; }
473
474impl<'a> crate::CdpCommand<'a> for StartParams {
475    const METHOD: &'static str = "Profiler.start";
476    type Response = crate::EmptyReturns;
477}
478
479/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
480/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
481/// counters.
482
483#[derive(Debug, Clone, Serialize, Deserialize, Default)]
484#[serde(rename_all = "camelCase")]
485pub struct StartPreciseCoverageParams {
486    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
487    #[serde(skip_serializing_if = "Option::is_none", rename = "callCount")]
488    call_count: Option<bool>,
489    /// Collect block-based coverage.
490    #[serde(skip_serializing_if = "Option::is_none")]
491    detailed: Option<bool>,
492    /// Allow the backend to send updates on its own initiative
493    #[serde(skip_serializing_if = "Option::is_none", rename = "allowTriggeredUpdates")]
494    allow_triggered_updates: Option<bool>,
495}
496
497impl StartPreciseCoverageParams {
498    /// Creates a builder for this type.
499    pub fn builder() -> StartPreciseCoverageParamsBuilder {
500        StartPreciseCoverageParamsBuilder {
501            call_count: None,
502            detailed: None,
503            allow_triggered_updates: None,
504        }
505    }
506    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
507    pub fn call_count(&self) -> Option<bool> { self.call_count }
508    /// Collect block-based coverage.
509    pub fn detailed(&self) -> Option<bool> { self.detailed }
510    /// Allow the backend to send updates on its own initiative
511    pub fn allow_triggered_updates(&self) -> Option<bool> { self.allow_triggered_updates }
512}
513
514#[derive(Default)]
515pub struct StartPreciseCoverageParamsBuilder {
516    call_count: Option<bool>,
517    detailed: Option<bool>,
518    allow_triggered_updates: Option<bool>,
519}
520
521impl StartPreciseCoverageParamsBuilder {
522    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
523    pub fn call_count(mut self, call_count: bool) -> Self { self.call_count = Some(call_count); self }
524    /// Collect block-based coverage.
525    pub fn detailed(mut self, detailed: bool) -> Self { self.detailed = Some(detailed); self }
526    /// Allow the backend to send updates on its own initiative
527    pub fn allow_triggered_updates(mut self, allow_triggered_updates: bool) -> Self { self.allow_triggered_updates = Some(allow_triggered_updates); self }
528    pub fn build(self) -> StartPreciseCoverageParams {
529        StartPreciseCoverageParams {
530            call_count: self.call_count,
531            detailed: self.detailed,
532            allow_triggered_updates: self.allow_triggered_updates,
533        }
534    }
535}
536
537/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
538/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
539/// counters.
540
541#[derive(Debug, Clone, Serialize, Deserialize, Default)]
542#[serde(rename_all = "camelCase")]
543pub struct StartPreciseCoverageReturns {
544    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
545    timestamp: f64,
546}
547
548impl StartPreciseCoverageReturns {
549    /// Creates a builder for this type with the required parameters:
550    /// * `timestamp`: Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
551    pub fn builder(timestamp: f64) -> StartPreciseCoverageReturnsBuilder {
552        StartPreciseCoverageReturnsBuilder {
553            timestamp: timestamp,
554        }
555    }
556    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
557    pub fn timestamp(&self) -> f64 { self.timestamp }
558}
559
560
561pub struct StartPreciseCoverageReturnsBuilder {
562    timestamp: f64,
563}
564
565impl StartPreciseCoverageReturnsBuilder {
566    pub fn build(self) -> StartPreciseCoverageReturns {
567        StartPreciseCoverageReturns {
568            timestamp: self.timestamp,
569        }
570    }
571}
572
573impl StartPreciseCoverageParams { pub const METHOD: &'static str = "Profiler.startPreciseCoverage"; }
574
575impl<'a> crate::CdpCommand<'a> for StartPreciseCoverageParams {
576    const METHOD: &'static str = "Profiler.startPreciseCoverage";
577    type Response = StartPreciseCoverageReturns;
578}
579
580
581#[derive(Debug, Clone, Serialize, Deserialize, Default)]
582#[serde(rename_all = "camelCase")]
583pub struct StopReturns<'a> {
584    /// Recorded profile.
585    profile: Profile<'a>,
586}
587
588impl<'a> StopReturns<'a> {
589    /// Creates a builder for this type with the required parameters:
590    /// * `profile`: Recorded profile.
591    pub fn builder(profile: Profile<'a>) -> StopReturnsBuilder<'a> {
592        StopReturnsBuilder {
593            profile: profile,
594        }
595    }
596    /// Recorded profile.
597    pub fn profile(&self) -> &Profile<'a> { &self.profile }
598}
599
600
601pub struct StopReturnsBuilder<'a> {
602    profile: Profile<'a>,
603}
604
605impl<'a> StopReturnsBuilder<'a> {
606    pub fn build(self) -> StopReturns<'a> {
607        StopReturns {
608            profile: self.profile,
609        }
610    }
611}
612
613#[derive(Debug, Clone, Serialize, Deserialize, Default)]
614pub struct StopParams {}
615
616impl StopParams { pub const METHOD: &'static str = "Profiler.stop"; }
617
618impl<'a> crate::CdpCommand<'a> for StopParams {
619    const METHOD: &'static str = "Profiler.stop";
620    type Response = StopReturns<'a>;
621}
622
623#[derive(Debug, Clone, Serialize, Deserialize, Default)]
624pub struct StopPreciseCoverageParams {}
625
626impl StopPreciseCoverageParams { pub const METHOD: &'static str = "Profiler.stopPreciseCoverage"; }
627
628impl<'a> crate::CdpCommand<'a> for StopPreciseCoverageParams {
629    const METHOD: &'static str = "Profiler.stopPreciseCoverage";
630    type Response = crate::EmptyReturns;
631}
632
633/// Collect coverage data for the current isolate, and resets execution counters. Precise code
634/// coverage needs to have started.
635
636#[derive(Debug, Clone, Serialize, Deserialize, Default)]
637#[serde(rename_all = "camelCase")]
638pub struct TakePreciseCoverageReturns<'a> {
639    /// Coverage data for the current isolate.
640    result: Vec<ScriptCoverage<'a>>,
641    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
642    timestamp: f64,
643}
644
645impl<'a> TakePreciseCoverageReturns<'a> {
646    /// Creates a builder for this type with the required parameters:
647    /// * `result`: Coverage data for the current isolate.
648    /// * `timestamp`: Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
649    pub fn builder(result: Vec<ScriptCoverage<'a>>, timestamp: f64) -> TakePreciseCoverageReturnsBuilder<'a> {
650        TakePreciseCoverageReturnsBuilder {
651            result: result,
652            timestamp: timestamp,
653        }
654    }
655    /// Coverage data for the current isolate.
656    pub fn result(&self) -> &[ScriptCoverage<'a>] { &self.result }
657    /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
658    pub fn timestamp(&self) -> f64 { self.timestamp }
659}
660
661
662pub struct TakePreciseCoverageReturnsBuilder<'a> {
663    result: Vec<ScriptCoverage<'a>>,
664    timestamp: f64,
665}
666
667impl<'a> TakePreciseCoverageReturnsBuilder<'a> {
668    pub fn build(self) -> TakePreciseCoverageReturns<'a> {
669        TakePreciseCoverageReturns {
670            result: self.result,
671            timestamp: self.timestamp,
672        }
673    }
674}
675
676#[derive(Debug, Clone, Serialize, Deserialize, Default)]
677pub struct TakePreciseCoverageParams {}
678
679impl TakePreciseCoverageParams { pub const METHOD: &'static str = "Profiler.takePreciseCoverage"; }
680
681impl<'a> crate::CdpCommand<'a> for TakePreciseCoverageParams {
682    const METHOD: &'static str = "Profiler.takePreciseCoverage";
683    type Response = TakePreciseCoverageReturns<'a>;
684}