Skip to content

Commit

Permalink
diffusion: dump connection manager state on SIGUSR1
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Oct 20, 2021
1 parent 1754eb6 commit df4704e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ouroboros-network/ouroboros-network.cabal
Expand Up @@ -191,6 +191,8 @@ library
typed-protocols >=0.1 && < 1.0,
typed-protocols-cborg
>=0.1 && < 1.0
if !os(windows)
build-depends: unix

ghc-options: -Wall
-Wno-unticked-promoted-constructors
Expand Down
37 changes: 35 additions & 2 deletions ouroboros-network/src/Ouroboros/Network/Diffusion.hs
Expand Up @@ -9,6 +9,10 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

#if !defined(mingw32_HOST_OS)
#define POSIX
#endif

module Ouroboros.Network.Diffusion
( DiffusionTracers (..)
, DiffusionArguments (..)
Expand Down Expand Up @@ -54,6 +58,9 @@ import Data.Void (Void)
import Data.ByteString.Lazy (ByteString)
import Data.Kind (Type)
import System.Random (newStdGen, split)
#ifdef POSIX
import qualified System.Posix.Signals as Signals
#endif

import Network.Mux ( MiniProtocolBundle (..)
, MiniProtocolInfo (..)
Expand All @@ -80,6 +87,9 @@ import Ouroboros.Network.Protocol.Handshake.Version
import Ouroboros.Network.Protocol.Handshake.Codec

import Ouroboros.Network.ConnectionManager.Types
#ifdef POSIX
import qualified Ouroboros.Network.ConnectionManager.Types as ConnectionManager
#endif
import Ouroboros.Network.ConnectionManager.Core
import Ouroboros.Network.ConnectionHandler
import Ouroboros.Network.RethrowPolicy
Expand Down Expand Up @@ -809,7 +819,19 @@ runDataDiffusion tracers
connectionHandler
classifyHandleError
NotInResponderMode
$ \(connectionManager :: NodeToNodeConnectionManager InitiatorMode Void) ->
$ \(connectionManager :: NodeToNodeConnectionManager InitiatorMode Void) -> do
#ifdef POSIX
_ <- Signals.installHandler
Signals.sigUSR1
(Signals.Catch
(do state <- ConnectionManager.readState connectionManager
traceWith dtConnectionManagerTracer
(TrState state)
)
)
Nothing
#endif

--
-- peer state actions
--
Expand Down Expand Up @@ -917,7 +939,18 @@ runDataDiffusion tracers
connectionHandler
classifyHandleError
(InResponderMode controlChannel)
$ \(connectionManager :: NodeToNodeConnectionManager InitiatorResponderMode ()) ->
$ \(connectionManager :: NodeToNodeConnectionManager InitiatorResponderMode ()) -> do
#ifdef POSIX
_ <- Signals.installHandler
Signals.sigUSR1
(Signals.Catch
(do state <- ConnectionManager.readState connectionManager
traceWith dtConnectionManagerTracer
(TrState state)
)
)
Nothing
#endif
--
-- peer state actions
--
Expand Down

0 comments on commit df4704e

Please sign in to comment.