diff options
author | joe <joe@jerkface.net> | 2017-01-23 22:32:17 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-23 22:33:08 -0500 |
commit | 058ccb22f43e9053fa37ed719d31c72dd6dac27c (patch) | |
tree | f6faea43c0b4cc9428e0b8cb8d0b836a9ec13107 /src/Network/BitTorrent | |
parent | 6a2506745dd06ad0849a1b0d440ad9751a69cf81 (diff) |
Added thread-debug flag and "threads" command.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT/Query.hs | 13 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs index 73b3d492..47d17622 100644 --- a/src/Network/BitTorrent/DHT/Query.hs +++ b/src/Network/BitTorrent/DHT/Query.hs | |||
@@ -9,6 +9,7 @@ | |||
9 | -- Normally, you don't need to import this module, use | 9 | -- Normally, you don't need to import this module, use |
10 | -- "Network.BitTorrent.DHT" instead. | 10 | -- "Network.BitTorrent.DHT" instead. |
11 | -- | 11 | -- |
12 | {-# LANGUAGE CPP #-} | ||
12 | {-# LANGUAGE FlexibleContexts #-} | 13 | {-# LANGUAGE FlexibleContexts #-} |
13 | {-# LANGUAGE ScopedTypeVariables #-} | 14 | {-# LANGUAGE ScopedTypeVariables #-} |
14 | {-# LANGUAGE TemplateHaskell #-} | 15 | {-# LANGUAGE TemplateHaskell #-} |
@@ -49,7 +50,12 @@ module Network.BitTorrent.DHT.Query | |||
49 | , (<@>) | 50 | , (<@>) |
50 | ) where | 51 | ) where |
51 | 52 | ||
53 | #ifdef THREAD_DEBUG | ||
54 | import Control.Concurrent.Lifted.Instrument hiding (yield) | ||
55 | #else | ||
56 | import GHC.Conc (labelThread) | ||
52 | import Control.Concurrent.Lifted hiding (yield) | 57 | import Control.Concurrent.Lifted hiding (yield) |
58 | #endif | ||
53 | import Control.Exception.Lifted hiding (Handler) | 59 | import Control.Exception.Lifted hiding (Handler) |
54 | import Control.Monad.Reader | 60 | import Control.Monad.Reader |
55 | import Control.Monad.Logger | 61 | import Control.Monad.Logger |
@@ -227,6 +233,7 @@ refreshNodes nid = do | |||
227 | -- routing table. | 233 | -- routing table. |
228 | insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId | 234 | insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId |
229 | insertNode info witnessed_ip0 = fork $ do | 235 | insertNode info witnessed_ip0 = fork $ do |
236 | -- myThreadId >>= liftIO . flip labelThread "DHT.insertNode" | ||
230 | var <- asks routingInfo | 237 | var <- asks routingInfo |
231 | tm <- getTimestamp | 238 | tm <- getTimestamp |
232 | let showTable = do | 239 | let showTable = do |
@@ -286,8 +293,10 @@ insertNode info witnessed_ip0 = fork $ do | |||
286 | return ps | 293 | return ps |
287 | ps <- join $ liftIO $ atomically $ atomicInsert arrival0 witnessed_ip0 | 294 | ps <- join $ liftIO $ atomically $ atomicInsert arrival0 witnessed_ip0 |
288 | showTable | 295 | showTable |
289 | _ <- fork $ forM_ ps $ \(CheckPing ns)-> do | 296 | _ <- fork $ do |
290 | forM_ ns $ \n -> do | 297 | myThreadId >>= liftIO . flip labelThread "DHT.insertNode.pingResults" |
298 | forM_ ps $ \(CheckPing ns)-> do | ||
299 | forM_ ns $ \n -> do | ||
291 | (b,mip) <- probeNode (nodeAddr n) | 300 | (b,mip) <- probeNode (nodeAddr n) |
292 | let alive = PingResult n b | 301 | let alive = PingResult n b |
293 | $(logDebugS) "insertNode" $ T.pack ("PingResult "++show (nodeId n,b)) | 302 | $(logDebugS) "insertNode" $ T.pack ("PingResult "++show (nodeId n,b)) |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index 8dc3f7ac..bad783a5 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -72,7 +72,11 @@ module Network.BitTorrent.DHT.Session | |||
72 | import Prelude hiding (ioError) | 72 | import Prelude hiding (ioError) |
73 | 73 | ||
74 | import Control.Concurrent.STM | 74 | import Control.Concurrent.STM |
75 | #ifdef THREAD_DEBUG | ||
76 | import Control.Concurrent.Async.Lifted.Instrument | ||
77 | #else | ||
75 | import Control.Concurrent.Async.Lifted | 78 | import Control.Concurrent.Async.Lifted |
79 | #endif | ||
76 | import Control.Exception.Lifted hiding (Handler) | 80 | import Control.Exception.Lifted hiding (Handler) |
77 | import Control.Monad.Base | 81 | import Control.Monad.Base |
78 | import Control.Monad.Logger | 82 | import Control.Monad.Logger |