Skip to main content

browser_protocol/tracing/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Configuration for memory dump. Used only when "memory-infra" category is enabled.
5
6pub type MemoryDumpConfig = serde_json::Map<String, JsonValue>;
7
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct TraceConfig {
12    /// Controls how the trace buffer stores data. The default is 'recordUntilFull'.
13
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub recordMode: Option<String>,
16    /// Size of the trace buffer in kilobytes. If not specified or zero is passed, a default value
17    /// of 200 MB would be used.
18
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub traceBufferSizeInKb: Option<f64>,
21    /// Turns on JavaScript stack sampling.
22
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub enableSampling: Option<bool>,
25    /// Turns on system tracing.
26
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub enableSystrace: Option<bool>,
29    /// Turns on argument filter.
30
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub enableArgumentFilter: Option<bool>,
33    /// Included category filters.
34
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub includedCategories: Option<Vec<String>>,
37    /// Excluded category filters.
38
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub excludedCategories: Option<Vec<String>>,
41    /// Configuration to synthesize the delays in tracing.
42
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub syntheticDelays: Option<Vec<String>>,
45    /// Configuration for memory dump triggers. Used only when "memory-infra" category is enabled.
46
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub memoryDumpConfig: Option<MemoryDumpConfig>,
49}
50
51/// Data format of a trace. Can be either the legacy JSON format or the
52/// protocol buffer format. Note that the JSON format will be deprecated soon.
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
55pub enum StreamFormat {
56    #[default]
57    Json,
58    Proto,
59}
60
61/// Compression type to use for traces returned via streams.
62
63#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
64pub enum StreamCompression {
65    #[default]
66    None,
67    Gzip,
68}
69
70/// Details exposed when memory request explicitly declared.
71/// Keep consistent with memory_dump_request_args.h and
72/// memory_instrumentation.mojom
73
74#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
75pub enum MemoryDumpLevelOfDetail {
76    #[default]
77    Background,
78    Light,
79    Detailed,
80}
81
82/// Backend type to use for tracing. 'chrome' uses the Chrome-integrated
83/// tracing service and is supported on all platforms. 'system' is only
84/// supported on Chrome OS and uses the Perfetto system tracing service.
85/// 'auto' chooses 'system' when the perfettoConfig provided to Tracing.start
86/// specifies at least one non-Chrome data source; otherwise uses 'chrome'.
87
88#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
89pub enum TracingBackend {
90    #[default]
91    Auto,
92    Chrome,
93    System,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize, Default)]
97pub struct EndParams {}
98
99impl EndParams { pub const METHOD: &'static str = "Tracing.end"; }
100
101impl crate::CdpCommand for EndParams {
102    const METHOD: &'static str = "Tracing.end";
103    type Response = crate::EmptyReturns;
104}
105
106/// Gets supported tracing categories.
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct GetCategoriesReturns {
111    /// A list of supported tracing categories.
112
113    pub categories: Vec<String>,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize, Default)]
117pub struct GetCategoriesParams {}
118
119impl GetCategoriesParams { pub const METHOD: &'static str = "Tracing.getCategories"; }
120
121impl crate::CdpCommand for GetCategoriesParams {
122    const METHOD: &'static str = "Tracing.getCategories";
123    type Response = GetCategoriesReturns;
124}
125
126/// Return a descriptor for all available tracing categories.
127
128#[derive(Debug, Clone, Serialize, Deserialize, Default)]
129#[serde(rename_all = "camelCase")]
130pub struct GetTrackEventDescriptorReturns {
131    /// Base64-encoded serialized perfetto.protos.TrackEventDescriptor protobuf message. (Encoded as a base64 string when passed over JSON)
132
133    pub descriptor: String,
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize, Default)]
137pub struct GetTrackEventDescriptorParams {}
138
139impl GetTrackEventDescriptorParams { pub const METHOD: &'static str = "Tracing.getTrackEventDescriptor"; }
140
141impl crate::CdpCommand for GetTrackEventDescriptorParams {
142    const METHOD: &'static str = "Tracing.getTrackEventDescriptor";
143    type Response = GetTrackEventDescriptorReturns;
144}
145
146/// Record a clock sync marker in the trace.
147
148#[derive(Debug, Clone, Serialize, Deserialize, Default)]
149#[serde(rename_all = "camelCase")]
150pub struct RecordClockSyncMarkerParams {
151    /// The ID of this clock sync marker
152
153    pub syncId: String,
154}
155
156impl RecordClockSyncMarkerParams { pub const METHOD: &'static str = "Tracing.recordClockSyncMarker"; }
157
158impl crate::CdpCommand for RecordClockSyncMarkerParams {
159    const METHOD: &'static str = "Tracing.recordClockSyncMarker";
160    type Response = crate::EmptyReturns;
161}
162
163/// Request a global memory dump.
164
165#[derive(Debug, Clone, Serialize, Deserialize, Default)]
166#[serde(rename_all = "camelCase")]
167pub struct RequestMemoryDumpParams {
168    /// Enables more deterministic results by forcing garbage collection
169
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub deterministic: Option<bool>,
172    /// Specifies level of details in memory dump. Defaults to "detailed".
173
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub levelOfDetail: Option<MemoryDumpLevelOfDetail>,
176}
177
178/// Request a global memory dump.
179
180#[derive(Debug, Clone, Serialize, Deserialize, Default)]
181#[serde(rename_all = "camelCase")]
182pub struct RequestMemoryDumpReturns {
183    /// GUID of the resulting global memory dump.
184
185    pub dumpGuid: String,
186    /// True iff the global memory dump succeeded.
187
188    pub success: bool,
189}
190
191impl RequestMemoryDumpParams { pub const METHOD: &'static str = "Tracing.requestMemoryDump"; }
192
193impl crate::CdpCommand for RequestMemoryDumpParams {
194    const METHOD: &'static str = "Tracing.requestMemoryDump";
195    type Response = RequestMemoryDumpReturns;
196}
197
198/// Start trace events collection.
199
200#[derive(Debug, Clone, Serialize, Deserialize, Default)]
201#[serde(rename_all = "camelCase")]
202pub struct StartParams {
203    /// Category/tag filter
204
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub categories: Option<String>,
207    /// Tracing options
208
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub options: Option<String>,
211    /// If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
212
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub bufferUsageReportingInterval: Option<f64>,
215    /// Whether to report trace events as series of dataCollected events or to save trace to a
216    /// stream (defaults to 'ReportEvents').
217
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub transferMode: Option<String>,
220    /// Trace data format to use. This only applies when using 'ReturnAsStream'
221    /// transfer mode (defaults to 'json').
222
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub streamFormat: Option<StreamFormat>,
225    /// Compression format to use. This only applies when using 'ReturnAsStream'
226    /// transfer mode (defaults to 'none')
227
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub streamCompression: Option<StreamCompression>,
230
231    #[serde(skip_serializing_if = "Option::is_none")]
232    pub traceConfig: Option<TraceConfig>,
233    /// Base64-encoded serialized perfetto.protos.TraceConfig protobuf message
234    /// When specified, the parameters 'categories', 'options', 'traceConfig'
235    /// are ignored. (Encoded as a base64 string when passed over JSON)
236
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub perfettoConfig: Option<String>,
239    /// Backend type (defaults to 'auto')
240
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub tracingBackend: Option<TracingBackend>,
243}
244
245impl StartParams { pub const METHOD: &'static str = "Tracing.start"; }
246
247impl crate::CdpCommand for StartParams {
248    const METHOD: &'static str = "Tracing.start";
249    type Response = crate::EmptyReturns;
250}