mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-21 16:11:37 +01:00
feat(windows): heartbeat thread and an accept log line, evidence for a daemon-wide stall
The stall analysis could not tell a frozen daemon (or guest) from a lock hold: in both, the threads are silent. A heartbeat thread (komorebi/src/heartbeat.rs) sleeps 100 ms in a loop and logs a warning, "heartbeat was N ms late: the daemon was not scheduled for that long", when a beat comes 500 ms or more after it should; started next to the command listener. If it is late exactly when the other threads are silent, the process was not scheduled; if it keeps beating while they are silent, something holds a lock (see the lock holder warnings). The Windows connection policy's on_accept also logs, at debug, "accepted a command connection (N ms since the previous one)", so a request that waited in the backlog during a stall shows up at its late accept. Both cost next to nothing (a 100 ms timer and one debug line per connection). komorebi-transport is unchanged: KDE and macOS do not see either. Diagnostics only, no behaviour change. Verified: tools/fast-check Windows clippy -D warnings PASS; e2e: none needed.
This commit is contained in:
1 parent
d0ee249ba2
commit
b7b3c1c8f4
4 files changed
+57
No files matched your search
@@ -333,6 +333,7 @@ pub fn run() -> eyre::Result<()> {
|
||||
focus_manager::listen_for_notifications(wm.clone());
|
||||
theme_manager::listen_for_notifications();
|
||||
|
||||
crate::heartbeat::start();
|
||||
listen_for_commands(wm.clone());
|
||||
|
||||
if let Some(port) = opts.tcp_port {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//! Evidence of a stall of the whole daemon.
|
||||
//!
|
||||
//! A thread that sleeps 100 ms in a loop and says so when it wakes up much later than that. If
|
||||
//! it is late in the same moments in which every other thread of the daemon is silent, the
|
||||
//! process (or the guest it runs in) was not scheduled; if only some threads are silent, one of
|
||||
//! them holds something (see [`crate::lock_holder`]).
|
||||
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
/// How long the heartbeat thread sleeps between two beats
|
||||
const BEAT: Duration = Duration::from_millis(100);
|
||||
|
||||
/// A beat later than this after the one before is logged
|
||||
const LATE: Duration = Duration::from_millis(500);
|
||||
|
||||
/// Starts the heartbeat thread
|
||||
pub fn start() {
|
||||
let _ = std::thread::Builder::new()
|
||||
.name("heartbeat".to_string())
|
||||
.spawn(|| {
|
||||
let mut last = Instant::now();
|
||||
|
||||
loop {
|
||||
std::thread::sleep(BEAT);
|
||||
|
||||
let now = Instant::now();
|
||||
let late = now.duration_since(last).saturating_sub(BEAT);
|
||||
last = now;
|
||||
|
||||
if late >= LATE {
|
||||
tracing::warn!(
|
||||
"heartbeat was {} ms late: the daemon was not scheduled for that long",
|
||||
late.as_millis()
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -15,6 +15,7 @@ pub mod focus_manager;
|
||||
pub mod live_resize;
|
||||
pub use komorebi_collections::Lockable;
|
||||
pub use komorebi_collections::lockable_sequence;
|
||||
pub mod heartbeat;
|
||||
pub mod lock_holder;
|
||||
pub mod monitor;
|
||||
pub mod monitor_reconciliator;
|
||||
|
||||
@@ -114,6 +114,22 @@ struct WindowsConnectionPolicy;
|
||||
|
||||
impl ConnectionPolicy<UnixStream> for WindowsConnectionPolicy {
|
||||
fn on_accept(&self, stream: &UnixStream) {
|
||||
// when connections come in: a request that waits in the backlog while the process is
|
||||
// stalled is seen here late, next to the heartbeat
|
||||
{
|
||||
static LAST_ACCEPT: parking_lot::Mutex<Option<std::time::Instant>> =
|
||||
parking_lot::Mutex::new(None);
|
||||
let now = std::time::Instant::now();
|
||||
let since = LAST_ACCEPT
|
||||
.lock()
|
||||
.replace(now)
|
||||
.map(|last| now.duration_since(last));
|
||||
tracing::debug!(
|
||||
"accepted a command connection ({} ms since the previous one)",
|
||||
since.map_or(-1, |d| d.as_millis() as i64)
|
||||
);
|
||||
}
|
||||
|
||||
match stream.set_read_timeout(Some(Duration::from_secs(1))) {
|
||||
Ok(()) => {}
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
|
||||
Reference in new issue
Block a user