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/// Gets supported tracing categories.
97
98#[derive(Debug, Clone, Serialize, Deserialize, Default)]
99#[serde(rename_all = "camelCase")]
100pub struct GetCategoriesReturns {
101    /// A list of supported tracing categories.
102
103    pub categories: Vec<String>,
104}
105
106/// Return a descriptor for all available tracing categories.
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct GetTrackEventDescriptorReturns {
111    /// Base64-encoded serialized perfetto.protos.TrackEventDescriptor protobuf message. (Encoded as a base64 string when passed over JSON)
112
113    pub descriptor: String,
114}
115
116/// Record a clock sync marker in the trace.
117
118#[derive(Debug, Clone, Serialize, Deserialize, Default)]
119#[serde(rename_all = "camelCase")]
120pub struct RecordClockSyncMarkerParams {
121    /// The ID of this clock sync marker
122
123    pub syncId: String,
124}
125
126/// Request a global memory dump.
127
128#[derive(Debug, Clone, Serialize, Deserialize, Default)]
129#[serde(rename_all = "camelCase")]
130pub struct RequestMemoryDumpParams {
131    /// Enables more deterministic results by forcing garbage collection
132
133    #[serde(skip_serializing_if = "Option::is_none")]
134    pub deterministic: Option<bool>,
135    /// Specifies level of details in memory dump. Defaults to "detailed".
136
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub levelOfDetail: Option<MemoryDumpLevelOfDetail>,
139}
140
141/// Request a global memory dump.
142
143#[derive(Debug, Clone, Serialize, Deserialize, Default)]
144#[serde(rename_all = "camelCase")]
145pub struct RequestMemoryDumpReturns {
146    /// GUID of the resulting global memory dump.
147
148    pub dumpGuid: String,
149    /// True iff the global memory dump succeeded.
150
151    pub success: bool,
152}
153
154/// Start trace events collection.
155
156#[derive(Debug, Clone, Serialize, Deserialize, Default)]
157#[serde(rename_all = "camelCase")]
158pub struct StartParams {
159    /// Category/tag filter
160
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub categories: Option<String>,
163    /// Tracing options
164
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub options: Option<String>,
167    /// If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
168
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub bufferUsageReportingInterval: Option<f64>,
171    /// Whether to report trace events as series of dataCollected events or to save trace to a
172    /// stream (defaults to 'ReportEvents').
173
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub transferMode: Option<String>,
176    /// Trace data format to use. This only applies when using 'ReturnAsStream'
177    /// transfer mode (defaults to 'json').
178
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub streamFormat: Option<StreamFormat>,
181    /// Compression format to use. This only applies when using 'ReturnAsStream'
182    /// transfer mode (defaults to 'none')
183
184    #[serde(skip_serializing_if = "Option::is_none")]
185    pub streamCompression: Option<StreamCompression>,
186
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub traceConfig: Option<TraceConfig>,
189    /// Base64-encoded serialized perfetto.protos.TraceConfig protobuf message
190    /// When specified, the parameters 'categories', 'options', 'traceConfig'
191    /// are ignored. (Encoded as a base64 string when passed over JSON)
192
193    #[serde(skip_serializing_if = "Option::is_none")]
194    pub perfettoConfig: Option<String>,
195    /// Backend type (defaults to 'auto')
196
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub tracingBackend: Option<TracingBackend>,
199}