From 52206d542132f9d3aa02ca23d8e45998b26c531a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Dec 2018 12:12:06 +0300 Subject: [PATCH] show SharedState in Debug for Runtime This should be useful to debug deadlocks due to bad forking. --- src/runtime.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/runtime.rs b/src/runtime.rs index 22ce4699..f1b41f36 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -56,7 +56,8 @@ where fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fmt.debug_struct("Runtime") .field("id", &self.id()) - .field("revision", &self.current_revision()) + .field("forked", &self.revision_guard.is_some()) + .field("shared_state", &self.shared_state) .finish() } } @@ -398,6 +399,26 @@ impl Default for SharedState { } } +impl std::fmt::Debug for SharedState +where + DB: Database, +{ + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let query_lock = if self.query_lock.try_write().is_some() { + "" + } else if self.query_lock.try_read().is_some() { + "" + } else { + "" + }; + fmt.debug_struct("SharedState") + .field("query_lock", &query_lock) + .field("revision", &self.revision) + .field("pending_revision_increments", &self.pending_revision_increments) + .finish() + } +} + /// State that will be specific to a single execution threads (when we /// support multiple threads) struct LocalState {