screencasting: Use spans to reduce logging boilerplate

This commit is contained in:
Ivan Molodetskikh
2026-01-12 18:16:05 +03:00
parent 3672e79369
commit df4614e62c
2 changed files with 30 additions and 44 deletions
+3 -8
View File
@@ -391,8 +391,7 @@ impl State {
signal_ctx,
} => {
let _span = tracy_client::span!("StartCast");
debug!(session_id, stream_id, "StartCast");
let _span = debug_span!("StartCast", session_id, stream_id).entered();
let (target, size, refresh, alpha) = match target {
StreamTargetId::Output { name } => {
@@ -410,10 +409,7 @@ impl State {
StreamTargetId::Window { id }
if id == self.niri.casting.dynamic_cast_id_for_portal.get() =>
{
debug!(
session_id,
stream_id, "delaying dynamic cast until target is set"
);
debug!("delaying dynamic cast until target is set");
self.niri.casting.pending_dynamic_casts.push(PendingCast {
session_id,
stream_id,
@@ -700,8 +696,7 @@ impl Niri {
fn stop_cast(&mut self, session_id: usize) {
let _span = tracy_client::span!("Niri::stop_cast");
debug!(session_id, "StopCast");
let _span = debug_span!("stop_cast", session_id).entered();
self.casting
.pending_dynamic_casts
+27 -36
View File
@@ -328,7 +328,8 @@ impl PipeWire {
let inner = inner.clone();
let stop_cast = stop_cast.clone();
move |stream, (), old, new| {
debug!(stream_id, "pw stream: state changed: {old:?} -> {new:?}");
let _span = debug_span!("state_changed", stream_id).entered();
debug!("{old:?} -> {new:?}");
let mut inner = inner.borrow_mut();
match new {
@@ -336,7 +337,7 @@ impl PipeWire {
if inner.node_id.is_none() {
let id = stream.node_id();
inner.node_id = Some(id);
debug!(stream_id, "pw stream: sending signal with {id}");
debug!("sending signal with {id}");
let _span = tracy_client::span!("sending PipeWireStreamAdded");
async_io::block_on(async {
@@ -347,10 +348,7 @@ impl PipeWire {
.await;
if let Err(err) = res {
warn!(
stream_id,
"error sending PipeWireStreamAdded: {err:?}"
);
warn!("error sending PipeWireStreamAdded: {err:?}");
stop_cast();
}
});
@@ -380,7 +378,7 @@ impl PipeWire {
let formats = formats.clone();
move |stream, (), id, pod| {
let id = ParamType::from_raw(id);
trace!(stream_id, ?id, "pw stream: param_changed");
trace!(stream_id, ?id, "param_changed");
let mut inner = inner.borrow_mut();
let inner = &mut *inner;
@@ -388,12 +386,14 @@ impl PipeWire {
return;
}
let _span = debug_span!("param_changed", stream_id).entered();
let Some(pod) = pod else { return };
let (m_type, m_subtype) = match parse_format(pod) {
Ok(x) => x,
Err(err) => {
warn!(stream_id, "pw stream: error parsing format: {err:?}");
warn!("error parsing format: {err:?}");
return;
}
};
@@ -404,19 +404,19 @@ impl PipeWire {
let mut format = VideoInfoRaw::new();
format.parse(pod).unwrap();
debug!(stream_id, "pw stream: got format = {format:?}");
debug!("got format = {format:?}");
let format_size = Size::from((format.size().width, format.size().height));
let state = &mut inner.state;
if format_size != state.expected_format_size() {
if !matches!(&*state, CastState::ResizePending { .. }) {
warn!(stream_id, "pw stream: wrong size, but we're not resizing");
warn!("wrong size, but we're not resizing");
stop_cast();
return;
}
debug!(stream_id, "pw stream: wrong size, waiting");
debug!("wrong size, waiting");
return;
}
@@ -437,25 +437,25 @@ impl PipeWire {
let Some(prop_modifier) =
object.find_prop(spa::utils::Id(FormatProperties::VideoModifier.0))
else {
warn!(stream_id, "pw stream: modifier prop missing");
warn!("modifier prop missing");
stop_cast();
return;
};
if prop_modifier.flags().contains(PodPropFlags::DONT_FIXATE) {
debug!(stream_id, "pw stream: fixating the modifier");
debug!("fixating the modifier");
let pod_modifier = prop_modifier.value();
let Ok((_, modifiers)) = PodDeserializer::deserialize_from::<Choice<i64>>(
pod_modifier.as_bytes(),
) else {
warn!(stream_id, "pw stream: wrong modifier property type");
warn!("wrong modifier property type");
stop_cast();
return;
};
let ChoiceEnum::Enum { alternatives, .. } = modifiers.1 else {
warn!(stream_id, "pw stream: wrong modifier choice type");
warn!("wrong modifier choice type");
stop_cast();
return;
};
@@ -468,18 +468,14 @@ impl PipeWire {
) {
Ok(x) => x,
Err(err) => {
warn!(
stream_id,
"pw stream: couldn't find preferred modifier: {err:?}"
);
warn!("couldn't find preferred modifier: {err:?}");
stop_cast();
return;
}
};
debug!(
stream_id,
"pw stream: allocation successful \
"allocation successful \
(modifier={modifier:?}, plane_count={plane_count}), \
moving to confirmation pending"
);
@@ -516,7 +512,7 @@ impl PipeWire {
let mut params = [pod1, make_pod(&mut b2, o2)];
if let Err(err) = stream.update_params(&mut params) {
warn!(stream_id, "error updating stream params: {err:?}");
warn!("error updating stream params: {err:?}");
stop_cast();
}
@@ -557,7 +553,7 @@ impl PipeWire {
(None, None)
};
debug!(stream_id, "pw stream: moving to ready state");
debug!("moving to ready state");
*state = CastState::Ready {
size,
@@ -582,15 +578,14 @@ impl PipeWire {
) {
Ok(x) => x,
Err(err) => {
warn!(stream_id, "pw stream: test allocation failed: {err:?}");
warn!("test allocation failed: {err:?}");
stop_cast();
return;
}
};
debug!(
stream_id,
"pw stream: allocation successful \
"allocation successful \
(modifier={modifier:?}, plane_count={plane_count}), \
moving to ready"
);
@@ -674,7 +669,7 @@ impl PipeWire {
}
if let Err(err) = stream.update_params(&mut params) {
warn!(stream_id, "error updating stream params: {err:?}");
warn!("error updating stream params: {err:?}");
stop_cast();
}
}
@@ -683,6 +678,7 @@ impl PipeWire {
let inner = inner.clone();
let stop_cast = stop_cast.clone();
move |stream, (), buffer| {
let _span = debug_span!("add_buffer", stream_id).entered();
let mut inner = inner.borrow_mut();
let (size, alpha, modifier) = if let CastState::Ready {
@@ -694,15 +690,11 @@ impl PipeWire {
{
(*size, *alpha, *modifier)
} else {
trace!(stream_id, "pw stream: add buffer, but not ready yet");
trace!("add_buffer, but not ready yet");
return;
};
trace!(
stream_id,
"pw stream: add_buffer, size={size:?}, alpha={alpha}, \
modifier={modifier:?}"
);
trace!("size={size:?}, alpha={alpha}, modifier={modifier:?}");
unsafe {
let spa_buffer = (*buffer).buffer;
@@ -716,7 +708,7 @@ impl PipeWire {
let dmabuf = match allocate_dmabuf(&gbm, size, fourcc, modifier) {
Ok(dmabuf) => dmabuf,
Err(err) => {
warn!(stream_id, "error allocating dmabuf: {err:?}");
warn!("error allocating dmabuf: {err:?}");
stop_cast();
return;
}
@@ -747,7 +739,6 @@ impl PipeWire {
(*chunk).offset = offset;
trace!(
stream_id,
"pw buffer plane: fd={}, stride={stride}, offset={offset}",
(*spa_data).fd
);
@@ -767,7 +758,7 @@ impl PipeWire {
.remove_buffer({
let inner = inner.clone();
move |_stream, (), buffer| {
trace!(stream_id, "pw stream: remove_buffer");
trace!(stream_id, "remove_buffer");
let mut inner = inner.borrow_mut();
inner