Skip to main content

servo_constellation/
tracing.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5/// Log an event from embedder at trace level.
6/// - To disable tracing: RUST_LOG='constellation<embedder@=off'
7/// - To enable tracing: RUST_LOG='constellation<embedder@'
8/// - Recommended filters when tracing is enabled:
9///   - constellation<embedder@ForwardEvent(MouseMoveEvent)=off
10///   - constellation<embedder@LogEntry=off
11///   - constellation<embedder@ReadyToPresent=off
12macro_rules! trace_msg_from_embedder {
13    // This macro only exists to put the docs in the same file as the target prefix,
14    // so the macro definition is always the same.
15    ($event:expr, $($rest:tt)+) => {
16        ::log::trace!(target: $crate::tracing::LogTarget::log_target(&$event), $($rest)+)
17    };
18}
19
20/// Log an event from script at trace level.
21/// - To disable tracing: RUST_LOG='constellation<script@=off'
22/// - To enable tracing: RUST_LOG='constellation<script@'
23/// - Recommended filters when tracing is enabled:
24///   - constellation<script@LogEntry=off
25macro_rules! trace_script_msg {
26    // This macro only exists to put the docs in the same file as the target prefix,
27    // so the macro definition is always the same.
28    ($event:expr, $($rest:tt)+) => {
29        ::log::trace!(target: $crate::tracing::LogTarget::log_target(&$event), $($rest)+)
30    };
31}
32
33/// Get the log target for an event, as a static string.
34pub(crate) trait LogTarget {
35    fn log_target(&self) -> &'static str;
36}
37
38mod from_embedder {
39    use embedder_traits::{InputEvent, InputEventAndId};
40
41    use super::LogTarget;
42
43    macro_rules! target {
44        ($($name:literal)+) => {
45            concat!("constellation<embedder@", $($name),+)
46        };
47    }
48
49    impl LogTarget for servo_constellation_traits::EmbedderToConstellationMessage {
50        fn log_target(&self) -> &'static str {
51            match self {
52                Self::Exit => target!("Exit"),
53                Self::AllowNavigationResponse(..) => target!("AllowNavigationResponse"),
54                Self::LoadUrl(..) => target!("LoadUrl"),
55                Self::TraverseHistory(..) => target!("TraverseHistory"),
56                Self::ChangeViewportDetails(..) => target!("ChangeViewportDetails"),
57                Self::ThemeChange(..) => target!("ThemeChange"),
58                Self::TickAnimation(..) => target!("TickAnimation"),
59                Self::WebDriverCommand(..) => target!("WebDriverCommand"),
60                Self::Reload(..) => target!("Reload"),
61                Self::LogEntry(..) => target!("LogEntry"),
62                Self::NewWebView(..) => target!("NewWebView"),
63                Self::CloseWebView(..) => target!("CloseWebView"),
64                Self::FocusWebView(..) => target!("FocusWebView"),
65                Self::BlurWebView => target!("BlurWebView"),
66                Self::ForwardInputEvent(_webview_id, event, ..) => event.log_target(),
67                Self::RefreshCursor(..) => target!("RefreshCursor"),
68                Self::ExitFullScreen(_) => target!("ExitFullScreen"),
69                Self::MediaSessionAction(_) => target!("MediaSessionAction"),
70                Self::SetWebViewThrottled(_, _) => target!("SetWebViewThrottled"),
71                Self::SetScrollStates(..) => target!("SetScrollStates"),
72                Self::PaintMetric(..) => target!("PaintMetric"),
73                Self::EvaluateJavaScript(..) => target!("EvaluateJavaScript"),
74                Self::CreateMemoryReport(..) => target!("CreateMemoryReport"),
75                Self::SendImageKeysForPipeline(..) => target!("SendImageKeysForPipeline"),
76                Self::PreferencesUpdated(..) => target!("PreferencesUpdated"),
77                Self::NoLongerWaitingOnAsynchronousImageUpdates(..) => {
78                    target!("NoLongerWaitingOnCanvas")
79                },
80                Self::RequestScreenshotReadiness(..) => target!("RequestScreenshotReadiness"),
81                Self::EmbedderControlResponse(..) => target!("EmbedderControlResponse"),
82                Self::UserContentManagerAction(..) => target!("UserContentManagerAction"),
83                Self::UpdatePinchZoomInfos(..) => target!("UpdatePinchZoomInfos"),
84                Self::SetAccessibilityActive(..) => target!("SetAccessibilityActive"),
85            }
86        }
87    }
88
89    impl LogTarget for InputEventAndId {
90        fn log_target(&self) -> &'static str {
91            macro_rules! target_variant {
92                ($name:literal) => {
93                    target!("ForwardInputEvent(" $name ")")
94                };
95            }
96            match self.event {
97                InputEvent::EditingAction(..) => target_variant!("EditingAction"),
98                #[cfg(feature = "gamepad")]
99                InputEvent::Gamepad(..) => target_variant!("Gamepad"),
100                InputEvent::Ime(..) => target_variant!("Ime"),
101                InputEvent::Keyboard(..) => target_variant!("Keyboard"),
102                InputEvent::MouseButton(..) => target_variant!("MouseButton"),
103                InputEvent::MouseMove(..) => target_variant!("MouseMove"),
104                InputEvent::MouseLeftViewport(..) => target_variant!("MouseLeftViewport"),
105                InputEvent::Touch(..) => target_variant!("Touch"),
106                InputEvent::Wheel(..) => target_variant!("Wheel"),
107            }
108        }
109    }
110}
111
112mod from_script {
113    use super::LogTarget;
114
115    macro_rules! target {
116        ($($name:literal)+) => {
117            concat!("constellation<script@", $($name),+)
118        };
119    }
120
121    impl LogTarget for servo_constellation_traits::ScriptToConstellationMessage {
122        fn log_target(&self) -> &'static str {
123            match self {
124                Self::ServiceWorkerAlgorithm(..) => target!("ServiceWorkerAlgorithm"),
125                Self::CompleteMessagePortTransfer(..) => target!("CompleteMessagePortTransfer"),
126                Self::MessagePortTransferResult(..) => target!("MessagePortTransferResult"),
127                Self::NewMessagePort(..) => target!("NewMessagePort"),
128                Self::NewMessagePortRouter(..) => target!("NewMessagePortRouter"),
129                Self::RemoveMessagePortRouter(..) => target!("RemoveMessagePortRouter"),
130                Self::RerouteMessagePort(..) => target!("RerouteMessagePort"),
131                Self::MessagePortShipped(..) => target!("MessagePortShipped"),
132                Self::EntanglePorts(..) => target!("EntanglePorts"),
133                Self::DisentanglePorts(..) => target!("DisentanglePorts"),
134                Self::NewBroadcastChannelRouter(..) => target!("NewBroadcastChannelRouter"),
135                Self::RemoveBroadcastChannelRouter(..) => target!("RemoveBroadcastChannelRouter"),
136                Self::NewBroadcastChannelNameInRouter(..) => {
137                    target!("NewBroadcastChannelNameInRouter")
138                },
139                Self::RemoveBroadcastChannelNameInRouter(..) => {
140                    target!("RemoveBroadcastChannelNameInRouter")
141                },
142                Self::ScheduleBroadcast(..) => target!("ScheduleBroadcast"),
143                Self::RegisterInterest(..) => target!("RegisterInterest"),
144                Self::UnregisterInterest(..) => target!("UnregisterInterest"),
145                Self::BroadcastStorageEvent(..) => target!("BroadcastStorageEvent"),
146                Self::ChangeRunningAnimationsState(..) => target!("ChangeRunningAnimationsState"),
147                Self::RegisterWorkerAnimationFrameProvider(..) => {
148                    target!("RegisterWorkerAnimationFrameProvider")
149                },
150                Self::UnregisterWorkerAnimationFrameProvider(..) => {
151                    target!("UnregisterWorkerAnimationFrameProvider")
152                },
153                Self::ChangeWorkerAnimationFrameProviderState(..) => {
154                    target!("ChangeWorkerAnimationFrameProviderState")
155                },
156                Self::CreateCanvasPaintThread(..) => target!("CreateCanvasPaintThread"),
157                Self::FocusAncestorBrowsingContextsForFocusingSteps(..) => {
158                    target!("FocusAncestorBrowsingContextsForFocusingSteps")
159                },
160                Self::FocusRemoteBrowsingContext(..) => target!("FocusRemoteBrowsingContext"),
161                Self::GetTopForBrowsingContext(..) => target!("GetTopForBrowsingContext"),
162                Self::GetBrowsingContextInfo(..) => target!("GetBrowsingContextInfo"),
163                Self::GetDocumentOrigin(..) => target!("GetDocumentOrigin"),
164                Self::GetChildBrowsingContextId(..) => target!("GetChildBrowsingContextId"),
165                Self::LoadComplete => target!("LoadComplete"),
166                Self::LoadUrl(..) => target!("LoadUrl"),
167                Self::AbortLoadUrl => target!("AbortLoadUrl"),
168                Self::PostMessage { .. } => target!("PostMessage"),
169                Self::NavigatedToFragment(..) => target!("NavigatedToFragment"),
170                Self::TraverseHistory(..) => target!("TraverseHistory"),
171                Self::PushHistoryState(..) => target!("PushHistoryState"),
172                Self::ReplaceHistoryState(..) => target!("ReplaceHistoryState"),
173                Self::JointSessionHistoryLength(..) => target!("JointSessionHistoryLength"),
174                Self::RemoveIFrame(..) => target!("RemoveIFrame"),
175                Self::SetThrottledComplete(..) => target!("SetThrottledComplete"),
176                Self::ScriptLoadedURLInIFrame(..) => target!("ScriptLoadedURLInIFrame"),
177                Self::ScriptNewIFrame(..) => target!("ScriptNewIFrame"),
178                Self::CreateAuxiliaryWebView(..) => target!("ScriptNewAuxiliary"),
179                Self::ActivateDocument => target!("ActivateDocument"),
180                Self::SetDocumentState(..) => target!("SetDocumentState"),
181                Self::SetFinalUrl(..) => target!("SetFinalUrl"),
182                Self::LogEntry(..) => target!("LogEntry"),
183                Self::DiscardDocument => target!("DiscardDocument"),
184                Self::DiscardTopLevelBrowsingContext => target!("DiscardTopLevelBrowsingContext"),
185                Self::PipelineExited => target!("PipelineExited"),
186                Self::ForwardDOMMessage(..) => target!("ForwardDOMMessage"),
187                Self::MediaSessionEvent(..) => target!("MediaSessionEvent"),
188                #[cfg(feature = "webgpu")]
189                Self::RequestAdapter(..) => target!("RequestAdapter"),
190                #[cfg(feature = "webgpu")]
191                Self::GetWebGPUChan(..) => target!("GetWebGPUChan"),
192                Self::TitleChanged(..) => target!("TitleChanged"),
193                Self::IFrameSizes(..) => target!("IFrameSizes"),
194                Self::ReportMemory(..) => target!("ReportMemory"),
195                Self::FinishJavaScriptEvaluation(..) => target!("FinishJavaScriptEvaluation"),
196                Self::ForwardKeyboardScroll(..) => target!("ForwardKeyboardScroll"),
197                Self::RespondToScreenshotReadinessRequest(..) => {
198                    target!("RespondToScreenshotReadinessRequest")
199                },
200                Self::TriggerGarbageCollection => target!("TriggerGarbageCollection"),
201                Self::AcquireWakeLock(..) => target!("AcquireWakeLock"),
202                Self::ReleaseWakeLock(..) => target!("ReleaseWakeLock"),
203            }
204        }
205    }
206}