js_protocol/profiler/mod.rs
1use serde::{Serialize, Deserialize};
2
3/// Profile node. Holds callsite information, execution statistics and child nodes.
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6#[serde(rename_all = "camelCase")]
7pub struct ProfileNode {
8 /// Unique id of the node.
9
10 pub id: u64,
11 /// Function location.
12
13 pub callFrame: crate::runtime::CallFrame,
14 /// Number of samples where this node was on top of the call stack.
15
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub hitCount: Option<u64>,
18 /// Child node ids.
19
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub children: Option<Vec<i64>>,
22 /// The reason of being not optimized. The function may be deoptimized or marked as don't
23 /// optimize.
24
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub deoptReason: Option<String>,
27 /// An array of source position ticks.
28
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub positionTicks: Option<Vec<PositionTickInfo>>,
31}
32
33/// Profile.
34
35#[derive(Debug, Clone, Serialize, Deserialize, Default)]
36#[serde(rename_all = "camelCase")]
37pub struct Profile {
38 /// The list of profile nodes. First item is the root node.
39
40 pub nodes: Vec<ProfileNode>,
41 /// Profiling start timestamp in microseconds.
42
43 pub startTime: f64,
44 /// Profiling end timestamp in microseconds.
45
46 pub endTime: f64,
47 /// Ids of samples top nodes.
48
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub samples: Option<Vec<i64>>,
51 /// Time intervals between adjacent samples in microseconds. The first delta is relative to the
52 /// profile startTime.
53
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub timeDeltas: Option<Vec<i64>>,
56}
57
58/// Specifies a number of samples attributed to a certain source position.
59
60#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61#[serde(rename_all = "camelCase")]
62pub struct PositionTickInfo {
63 /// Source line number (1-based).
64
65 pub line: i32,
66 /// Number of samples attributed to the source line.
67
68 pub ticks: i64,
69}
70
71/// Coverage data for a source range.
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74#[serde(rename_all = "camelCase")]
75pub struct CoverageRange {
76 /// JavaScript script source offset for the range start.
77
78 pub startOffset: i32,
79 /// JavaScript script source offset for the range end.
80
81 pub endOffset: i32,
82 /// Collected execution count of the source range.
83
84 pub count: u64,
85}
86
87/// Coverage data for a JavaScript function.
88
89#[derive(Debug, Clone, Serialize, Deserialize, Default)]
90#[serde(rename_all = "camelCase")]
91pub struct FunctionCoverage {
92 /// JavaScript function name.
93
94 pub functionName: String,
95 /// Source ranges inside the function with coverage data.
96
97 pub ranges: Vec<CoverageRange>,
98 /// Whether coverage data for this function has block granularity.
99
100 pub isBlockCoverage: bool,
101}
102
103/// Coverage data for a JavaScript script.
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default)]
106#[serde(rename_all = "camelCase")]
107pub struct ScriptCoverage {
108 /// JavaScript script id.
109
110 pub scriptId: crate::runtime::ScriptId,
111 /// JavaScript script name or url.
112
113 pub url: String,
114 /// Functions contained in the script that has coverage data.
115
116 pub functions: Vec<FunctionCoverage>,
117}
118
119/// Collect coverage data for the current isolate. The coverage data may be incomplete due to
120/// garbage collection.
121
122#[derive(Debug, Clone, Serialize, Deserialize, Default)]
123#[serde(rename_all = "camelCase")]
124pub struct GetBestEffortCoverageReturns {
125 /// Coverage data for the current isolate.
126
127 pub result: Vec<ScriptCoverage>,
128}
129
130/// Changes CPU profiler sampling interval. Must be called before CPU profiles recording started.
131
132#[derive(Debug, Clone, Serialize, Deserialize, Default)]
133#[serde(rename_all = "camelCase")]
134pub struct SetSamplingIntervalParams {
135 /// New sampling interval in microseconds.
136
137 pub interval: i64,
138}
139
140/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
141/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
142/// counters.
143
144#[derive(Debug, Clone, Serialize, Deserialize, Default)]
145#[serde(rename_all = "camelCase")]
146pub struct StartPreciseCoverageParams {
147 /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
148
149 #[serde(skip_serializing_if = "Option::is_none")]
150 pub callCount: Option<bool>,
151 /// Collect block-based coverage.
152
153 #[serde(skip_serializing_if = "Option::is_none")]
154 pub detailed: Option<bool>,
155 /// Allow the backend to send updates on its own initiative
156
157 #[serde(skip_serializing_if = "Option::is_none")]
158 pub allowTriggeredUpdates: Option<bool>,
159}
160
161/// Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
162/// coverage may be incomplete. Enabling prevents running optimized code and resets execution
163/// counters.
164
165#[derive(Debug, Clone, Serialize, Deserialize, Default)]
166#[serde(rename_all = "camelCase")]
167pub struct StartPreciseCoverageReturns {
168 /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
169
170 pub timestamp: f64,
171}
172
173
174#[derive(Debug, Clone, Serialize, Deserialize, Default)]
175#[serde(rename_all = "camelCase")]
176pub struct StopReturns {
177 /// Recorded profile.
178
179 pub profile: Profile,
180}
181
182/// Collect coverage data for the current isolate, and resets execution counters. Precise code
183/// coverage needs to have started.
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186#[serde(rename_all = "camelCase")]
187pub struct TakePreciseCoverageReturns {
188 /// Coverage data for the current isolate.
189
190 pub result: Vec<ScriptCoverage>,
191 /// Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
192
193 pub timestamp: f64,
194}