1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct ProfileNode<'a> {
10 id: u64,
12 #[serde(rename = "callFrame")]
14 call_frame: crate::runtime::CallFrame<'a>,
15 #[serde(skip_serializing_if = "Option::is_none", rename = "hitCount")]
17 hit_count: Option<u64>,
18 #[serde(skip_serializing_if = "Option::is_none")]
20 children: Option<Vec<i64>>,
21 #[serde(skip_serializing_if = "Option::is_none", rename = "deoptReason")]
24 deopt_reason: Option<Cow<'a, str>>,
25 #[serde(skip_serializing_if = "Option::is_none", rename = "positionTicks")]
27 position_ticks: Option<Vec<PositionTickInfo>>,
28}
29
30impl<'a> ProfileNode<'a> {
31 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 pub fn id(&self) -> u64 { self.id }
46 pub fn call_frame(&self) -> &crate::runtime::CallFrame<'a> { &self.call_frame }
48 pub fn hit_count(&self) -> Option<u64> { self.hit_count }
50 pub fn children(&self) -> Option<&[i64]> { self.children.as_deref() }
52 pub fn deopt_reason(&self) -> Option<&str> { self.deopt_reason.as_deref() }
55 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 pub fn hit_count(mut self, hit_count: u64) -> Self { self.hit_count = Some(hit_count); self }
72 pub fn children(mut self, children: Vec<i64>) -> Self { self.children = Some(children); self }
74 pub fn deopt_reason(mut self, deopt_reason: impl Into<Cow<'a, str>>) -> Self { self.deopt_reason = Some(deopt_reason.into()); self }
77 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
94#[serde(rename_all = "camelCase")]
95pub struct Profile<'a> {
96 nodes: Vec<ProfileNode<'a>>,
98 #[serde(rename = "startTime")]
100 start_time: f64,
101 #[serde(rename = "endTime")]
103 end_time: f64,
104 #[serde(skip_serializing_if = "Option::is_none")]
106 samples: Option<Vec<i64>>,
107 #[serde(skip_serializing_if = "Option::is_none", rename = "timeDeltas")]
110 time_deltas: Option<Vec<i64>>,
111}
112
113impl<'a> Profile<'a> {
114 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 pub fn nodes(&self) -> &[ProfileNode<'a>] { &self.nodes }
129 pub fn start_time(&self) -> f64 { self.start_time }
131 pub fn end_time(&self) -> f64 { self.end_time }
133 pub fn samples(&self) -> Option<&[i64]> { self.samples.as_deref() }
135 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 pub fn samples(mut self, samples: Vec<i64>) -> Self { self.samples = Some(samples); self }
152 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
169#[serde(rename_all = "camelCase")]
170pub struct PositionTickInfo {
171 line: i64,
173 ticks: i64,
175}
176
177impl PositionTickInfo {
178 pub fn builder(line: i64, ticks: i64) -> PositionTickInfoBuilder {
182 PositionTickInfoBuilder {
183 line: line,
184 ticks: ticks,
185 }
186 }
187 pub fn line(&self) -> i64 { self.line }
189 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
211#[serde(rename_all = "camelCase")]
212pub struct CoverageRange {
213 #[serde(rename = "startOffset")]
215 start_offset: i32,
216 #[serde(rename = "endOffset")]
218 end_offset: i32,
219 count: u64,
221}
222
223impl CoverageRange {
224 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 pub fn start_offset(&self) -> i32 { self.start_offset }
237 pub fn end_offset(&self) -> i32 { self.end_offset }
239 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
263#[serde(rename_all = "camelCase")]
264pub struct FunctionCoverage<'a> {
265 #[serde(rename = "functionName")]
267 function_name: Cow<'a, str>,
268 ranges: Vec<CoverageRange>,
270 #[serde(rename = "isBlockCoverage")]
272 is_block_coverage: bool,
273}
274
275impl<'a> FunctionCoverage<'a> {
276 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 pub fn function_name(&self) -> &str { self.function_name.as_ref() }
289 pub fn ranges(&self) -> &[CoverageRange] { &self.ranges }
291 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
315#[serde(rename_all = "camelCase")]
316pub struct ScriptCoverage<'a> {
317 #[serde(rename = "scriptId")]
319 script_id: crate::runtime::ScriptId<'a>,
320 url: Cow<'a, str>,
322 functions: Vec<FunctionCoverage<'a>>,
324}
325
326impl<'a> ScriptCoverage<'a> {
327 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 pub fn script_id(&self) -> &crate::runtime::ScriptId<'a> { &self.script_id }
340 pub fn url(&self) -> &str { self.url.as_ref() }
342 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
387#[serde(rename_all = "camelCase")]
388pub struct GetBestEffortCoverageReturns<'a> {
389 result: Vec<ScriptCoverage<'a>>,
391}
392
393impl<'a> GetBestEffortCoverageReturns<'a> {
394 pub fn builder(result: Vec<ScriptCoverage<'a>>) -> GetBestEffortCoverageReturnsBuilder<'a> {
397 GetBestEffortCoverageReturnsBuilder {
398 result: result,
399 }
400 }
401 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
431#[serde(rename_all = "camelCase")]
432pub struct SetSamplingIntervalParams {
433 interval: i64,
435}
436
437impl SetSamplingIntervalParams {
438 pub fn builder(interval: i64) -> SetSamplingIntervalParamsBuilder {
441 SetSamplingIntervalParamsBuilder {
442 interval: interval,
443 }
444 }
445 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
484#[serde(rename_all = "camelCase")]
485pub struct StartPreciseCoverageParams {
486 #[serde(skip_serializing_if = "Option::is_none", rename = "callCount")]
488 call_count: Option<bool>,
489 #[serde(skip_serializing_if = "Option::is_none")]
491 detailed: Option<bool>,
492 #[serde(skip_serializing_if = "Option::is_none", rename = "allowTriggeredUpdates")]
494 allow_triggered_updates: Option<bool>,
495}
496
497impl StartPreciseCoverageParams {
498 pub fn builder() -> StartPreciseCoverageParamsBuilder {
500 StartPreciseCoverageParamsBuilder {
501 call_count: None,
502 detailed: None,
503 allow_triggered_updates: None,
504 }
505 }
506 pub fn call_count(&self) -> Option<bool> { self.call_count }
508 pub fn detailed(&self) -> Option<bool> { self.detailed }
510 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 pub fn call_count(mut self, call_count: bool) -> Self { self.call_count = Some(call_count); self }
524 pub fn detailed(mut self, detailed: bool) -> Self { self.detailed = Some(detailed); self }
526 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
542#[serde(rename_all = "camelCase")]
543pub struct StartPreciseCoverageReturns {
544 timestamp: f64,
546}
547
548impl StartPreciseCoverageReturns {
549 pub fn builder(timestamp: f64) -> StartPreciseCoverageReturnsBuilder {
552 StartPreciseCoverageReturnsBuilder {
553 timestamp: timestamp,
554 }
555 }
556 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 profile: Profile<'a>,
586}
587
588impl<'a> StopReturns<'a> {
589 pub fn builder(profile: Profile<'a>) -> StopReturnsBuilder<'a> {
592 StopReturnsBuilder {
593 profile: profile,
594 }
595 }
596 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#[derive(Debug, Clone, Serialize, Deserialize, Default)]
637#[serde(rename_all = "camelCase")]
638pub struct TakePreciseCoverageReturns<'a> {
639 result: Vec<ScriptCoverage<'a>>,
641 timestamp: f64,
643}
644
645impl<'a> TakePreciseCoverageReturns<'a> {
646 pub fn builder(result: Vec<ScriptCoverage<'a>>, timestamp: f64) -> TakePreciseCoverageReturnsBuilder<'a> {
650 TakePreciseCoverageReturnsBuilder {
651 result: result,
652 timestamp: timestamp,
653 }
654 }
655 pub fn result(&self) -> &[ScriptCoverage<'a>] { &self.result }
657 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}