diff options
author | joe <joe@jerkface.net> | 2018-06-26 17:29:30 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-26 17:29:30 -0400 |
commit | 2b2627f11e4f7544d86c78a474872f02665ef109 (patch) | |
tree | bc516de9e87e81d86827cb616c14ae63897b2500 /examples/dhtd.hs | |
parent | 7123e72a7256a146d2d756394eab863c5d536fc9 (diff) |
Thread report in test program.
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 28 |
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 | |||
69 | import Announcer.Tox | 69 | import Announcer.Tox |
70 | import ToxManager | 70 | import ToxManager |
71 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) | 71 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) |
72 | import DebugUtil | ||
72 | import Network.UPNP as UPNP | 73 | import Network.UPNP as UPNP |
73 | import Network.Address hiding (NodeId, NodeInfo(..)) | 74 | import Network.Address hiding (NodeId, NodeInfo(..)) |
74 | import Network.QueryResponse | 75 | import Network.QueryResponse |
@@ -124,17 +125,6 @@ import qualified Data.CyclicBuffer as CB | |||
124 | import DPut | 125 | import DPut |
125 | 126 | ||
126 | 127 | ||
127 | showReport :: [(String,String)] -> String | ||
128 | showReport kvs = showColumns $ map (\(x,y)->[x,y]) kvs | ||
129 | |||
130 | showColumns :: [[String]] -> String | ||
131 | showColumns 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 | |||
138 | pshow :: Show a => a -> B.ByteString | 128 | pshow :: Show a => a -> B.ByteString |
139 | pshow = B.pack . show | 129 | pshow = 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 |