Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some trace logging to the event loop #152

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
}

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 @@
/// **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 @@
/// 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 @@
.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 @@
/// 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 @@
.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 @@
/// 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 @@
.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 @@

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 @@
)?;
}
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 @@
)?;
}
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
6 changes: 6 additions & 0 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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,10 @@
ref mut callback,
..
} = *disp;
trace!(
"[calloop] Processing events for source type {}",
std::any::type_name::<S>()

Check warning on line 324 in src/sources/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/sources/mod.rs#L323-L324

Added lines #L323 - L324 were not covered by tests
);
source
.process_events(readiness, token, |event, meta| callback(event, meta, data))
.map_err(|e| crate::Error::OtherError(e.into()))
Expand Down
Loading