Skip to content

Commit

Permalink
Add some trace logging to the event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Sep 24, 2023
1 parent b0f3b35 commit 501c299
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/loop_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::future::Future;

use slab::Slab;

use log::trace;

use crate::sources::{Dispatcher, EventSource, Idle, IdleDispatcher};
use crate::sys::{Notifier, PollEvent};
use crate::{
Expand Down Expand Up @@ -148,6 +150,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
}

let key = sources.insert(dispatcher.clone_as_event_dispatcher());
trace!("[calloop] Inserting new source #{}", key);
let ret = sources.get(key).unwrap().register(
&mut poll,
&mut self
Expand Down Expand Up @@ -187,6 +190,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
/// **Note:** this cannot be done from within the source callback.
pub fn enable(&self, token: &RegistrationToken) -> crate::Result<()> {
if let Some(source) = self.inner.sources.borrow().get(token.key) {
trace!("[calloop] Registering source #{}", token.key);
source.register(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -205,6 +209,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
/// updating its registration.
pub fn update(&self, token: &RegistrationToken) -> crate::Result<()> {
if let Some(source) = self.inner.sources.borrow().get(token.key) {
trace!("[calloop] Updating registration of source #{}", token.key);
if !source.reregister(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -213,6 +218,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
.borrow_mut(),
&mut TokenFactory::new(token.key),
)? {
trace!("[calloop] Cannot do it now, storing for later.");

Check warning on line 221 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L221

Added line #L221 was not covered by tests
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Reregister);
}
Expand All @@ -225,6 +231,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
/// The source remains in the event loop, but it'll no longer generate events
pub fn disable(&self, token: &RegistrationToken) -> crate::Result<()> {
if let Some(source) = self.inner.sources.borrow().get(token.key) {
trace!("[calloop] Unregistering source #{}", token.key);
if !source.unregister(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand All @@ -233,6 +240,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
.borrow_mut(),
*token,
)? {
trace!("[calloop] Cannot do it now, storing for later.");

Check warning on line 243 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L243

Added line #L243 was not covered by tests
// we are in a callback, store for later processing
self.inner.pending_action.set(PostAction::Disable);
}
Expand All @@ -243,6 +251,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
/// Removes this source from the event loop.
pub fn remove(&self, token: RegistrationToken) {
if let Some(source) = self.inner.sources.borrow_mut().try_remove(token.key) {
trace!("[calloop] Removing source #{}", token.key);
if let Err(e) = source.unregister(
&mut self.inner.poll.borrow_mut(),
&mut self
Expand Down Expand Up @@ -411,6 +420,10 @@ impl<'l, Data> EventLoop<'l, Data> {
.cloned();

if let Some(disp) = opt_disp {
trace!(
"[calloop] Dispatching events for source #{}",

Check warning on line 424 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L424

Added line #L424 was not covered by tests
registroken_token
);
let mut ret = disp.process_events(event.readiness, event.token, data)?;

// if the returned PostAction is Continue, it may be overwritten by an user-specified pending action
Expand All @@ -425,6 +438,10 @@ impl<'l, Data> EventLoop<'l, Data> {

match ret {
PostAction::Reregister => {
trace!(
"[calloop] Postaction reregister for source #{}",

Check warning on line 442 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L442

Added line #L442 was not covered by tests
registroken_token
);
disp.reregister(
&mut self.handle.inner.poll.borrow_mut(),
&mut self
Expand All @@ -436,6 +453,10 @@ impl<'l, Data> EventLoop<'l, Data> {
)?;
}
PostAction::Disable => {
trace!(
"[calloop] Postaction unregister for source #{}",

Check warning on line 457 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L456-L457

Added lines #L456 - L457 were not covered by tests
registroken_token
);
disp.unregister(
&mut self.handle.inner.poll.borrow_mut(),
&mut self
Expand All @@ -447,6 +468,10 @@ impl<'l, Data> EventLoop<'l, Data> {
)?;
}
PostAction::Remove => {
trace!(
"[calloop] Postaction remove for source #{}",

Check warning on line 472 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L472

Added line #L472 was not covered by tests
registroken_token
);
// delete the source from the list, it'll be cleaned up with the if just below
self.handle
.inner
Expand Down
3 changes: 3 additions & 0 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
rc::Rc,
};

use log::trace;

pub use crate::loop_logic::EventIterator;
use crate::{sys::TokenFactory, Poll, Readiness, RegistrationToken, Token};

Expand Down Expand Up @@ -317,6 +319,7 @@ where
ref mut callback,
..
} = *disp;
trace!("[calloop] Processing events for source type {}", std::any::type_name::<S>());
source
.process_events(readiness, token, |event, meta| callback(event, meta, data))
.map_err(|e| crate::Error::OtherError(e.into()))
Expand Down

0 comments on commit 501c299

Please sign in to comment.