summaryrefslogtreecommitdiff
path: root/examples/dhtd.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-26 17:29:30 -0400
committerjoe <joe@jerkface.net>2018-06-26 17:29:30 -0400
commit2b2627f11e4f7544d86c78a474872f02665ef109 (patch)
treebc516de9e87e81d86827cb616c14ae63897b2500 /examples/dhtd.hs
parent7123e72a7256a146d2d756394eab863c5d536fc9 (diff)
Thread report in test program.
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r--examples/dhtd.hs28
1 files changed, 4 insertions, 24 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index e4b10b8d..3f2a6a63 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -69,6 +69,7 @@ import Announcer
69import Announcer.Tox 69import Announcer.Tox
70import ToxManager 70import ToxManager
71import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) 71import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys)
72import DebugUtil
72import Network.UPNP as UPNP 73import Network.UPNP as UPNP
73import Network.Address hiding (NodeId, NodeInfo(..)) 74import Network.Address hiding (NodeId, NodeInfo(..))
74import Network.QueryResponse 75import Network.QueryResponse
@@ -124,17 +125,6 @@ import qualified Data.CyclicBuffer as CB
124import DPut 125import DPut
125 126
126 127
127showReport :: [(String,String)] -> String
128showReport kvs = showColumns $ map (\(x,y)->[x,y]) kvs
129
130showColumns :: [[String]] -> String
131showColumns rows = do
132 let cols = transpose rows
133 ws = map (maximum . map (succ . length)) cols
134 fs <- rows
135 _ <- take 1 fs -- Guard against empty rows so that 'last' is safe.
136 " " ++ concat (zipWith (printf "%-*s") (init ws) (init fs)) ++ last fs ++ "\n"
137
138pshow :: Show a => a -> B.ByteString 128pshow :: Show a => a -> B.ByteString
139pshow = B.pack . show 129pshow = B.pack . show
140 130
@@ -471,19 +461,9 @@ clientSession s@Session{..} sock cnum h = do
471 >>= hPutClient h 461 >>= hPutClient h
472#ifdef THREAD_DEBUG 462#ifdef THREAD_DEBUG
473 ("threads", s) -> cmd0 $ do 463 ("threads", s) -> cmd0 $ do
474 threads <- threadsInformation 464 let want_ss = ["-v"] `isInfixOf` words s
475 tm <- getCurrentTime 465 r <- threadReport want_ss
476 let (ss,ts) = partition (("search" `isPrefixOf`) . lbl . snd) 466 hPutClient h r
477 threads
478 want_ss = ["-v"] `isInfixOf` words s
479 r <- forM (if want_ss then threads else ts) $ \(tid,PerThread{..}) -> do
480 stat <- threadStatus tid
481 let showStat (ThreadBlocked reason) = show reason
482 showStat stat = show stat
483 return [show lbl,show (diffUTCTime tm startTime),showStat stat]
484 hPutClient h $ unlines [ showColumns r
485 , (if want_ss then " There are " else " and ")
486 ++ show (length ss) ++ " search threads." ]
487#endif 467#endif
488 ("mem", s) -> cmd0 $ do 468 ("mem", s) -> cmd0 $ do
489 case s of 469 case s of