Skip to content

Commit

Permalink
Keep wallet Notice logs in restore bench
Browse files Browse the repository at this point in the history
To be able to see and debug things that go wrong, let's ensure the
wallet logs to stdout at Notice level.
  • Loading branch information
Anviking committed Jan 27, 2021
1 parent df25b2c commit f3fdcee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/core-integration/src/Cardano/Wallet/BenchShared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module Cardano.Wallet.BenchShared
-- * Main function
, execBenchWithNode

, initBenchmarkLogging

-- * Benchmark runner
, runBenchmarks
, bench
Expand Down Expand Up @@ -123,7 +125,7 @@ execBenchWithNode networkConfig action = do
hSetBuffering stdout NoBuffering
hSetBuffering stderr NoBuffering

(_logCfg, tr') <- initBenchmarkLogging Info
(_logCfg, tr') <- initBenchmarkLogging "bench-restore" Info
let tr = if argQuiet args then nullTracer else tr'
installSignalHandlers (return ())

Expand Down Expand Up @@ -269,10 +271,10 @@ bench benchName action = do
let t = Time $ finish - start
(res, t) <$ sayErr (pretty $ nameF (build benchName) (build t))

initBenchmarkLogging :: Severity -> IO (CM.Configuration, Trace IO Text)
initBenchmarkLogging minSeverity = do
initBenchmarkLogging :: Text -> Severity -> IO (CM.Configuration, Trace IO Text)
initBenchmarkLogging name minSeverity = do
c <- defaultConfigStdout
CM.setMinSeverity c minSeverity
CM.setSetupBackends c [CM.KatipBK, CM.AggregationBK]
(tr, _sb) <- setupTrace_ c "bench-restore"
(tr, _sb) <- setupTrace_ c name
pure (c, tr)
22 changes: 15 additions & 7 deletions lib/shelley/bench/Restore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import Cardano.Wallet.BenchShared
, argsNetworkDir
, bench
, execBenchWithNode
, initBenchmarkLogging
, runBenchmarks
)
import Cardano.Wallet.DB
Expand Down Expand Up @@ -234,6 +235,8 @@ cardanoRestoreBench tr c socketFile = do
(SomeNetworkDiscriminant networkProxy, np, vData, _b)
<- unsafeRunExceptT $ parseGenesisData c

(_, walletTr) <- initBenchmarkLogging "wallet" Notice

let network = networkDescription networkProxy
sayErr $ "Network: " <> network

Expand All @@ -244,6 +247,7 @@ cardanoRestoreBench tr c socketFile = do
bench_restoration @_ @ShelleyKey
networkProxy
(trMessageText tr)
walletTr
socketFile
np
vData
Expand All @@ -260,6 +264,7 @@ cardanoRestoreBench tr c socketFile = do
bench_restoration
networkProxy
(trMessageText tr)
walletTr
socketFile
np
vData
Expand All @@ -275,6 +280,7 @@ cardanoRestoreBench tr c socketFile = do
bench_restoration
networkProxy
(trMessageText tr)
walletTr
socketFile
np
vData
Expand Down Expand Up @@ -567,6 +573,7 @@ bench_restoration
)
=> Proxy n
-> Tracer IO (BenchmarkLog n)
-> Trace IO Text -- ^ For wallet tracing
-> CardanoNodeConn -- ^ Socket path
-> NetworkParameters
-> NodeVersionData
Expand All @@ -576,20 +583,20 @@ bench_restoration
-> Percentage -- ^ Target sync progress
-> (Proxy n -> WalletLayer s k -> WalletId -> WalletName -> Text -> Time -> IO results)
-> IO SomeBenchmarkResults
bench_restoration proxy tr socket np vData benchname wallets traceToDisk targetSync benchmarks = do
bench_restoration proxy tr wlTr socket np vData benchname wallets traceToDisk targetSync benchmarks = do
putStrLn $ "*** " ++ T.unpack benchname
let networkId = networkIdVal proxy
let tl = newTransactionLayer @k networkId
withNetworkLayer nullTracer np socket vData $ \nw' -> do
withNetworkLayer (trMessageText wlTr) np socket vData $ \nw' -> do
let gp = genesisParameters np
let convert = fromCardanoBlock gp
let nw = convert <$> nw'
let ti = neverFails "bench db shouldn't forecast into future"
$ timeInterpreter nw
withBenchDBLayer @s @k ti $ \db -> do
withWalletLayerTracer $ \wlTr -> do
withBenchDBLayer @s @k ti wlTr $ \db -> do
withWalletLayerTracer $ \progressTrace -> do
let w = WalletLayer
wlTr
((trMessageText wlTr) <> progressTrace)
(emptyGenesis gp, np, mkSyncTolerance 3600)
nw
tl
Expand Down Expand Up @@ -669,11 +676,12 @@ withBenchDBLayer
, WalletKey k
)
=> TimeInterpreter IO
-> Trace IO Text
-> (DBLayer IO s k -> IO a)
-> IO a
withBenchDBLayer ti action =
withBenchDBLayer ti tr action =
withSystemTempFile "bench.db" $ \dbFile _ -> do
let before = newDBLayer nullTracer migrationDefaultValues (Just dbFile) ti
let before = newDBLayer (trMessageText tr) migrationDefaultValues (Just dbFile) ti
let after = destroyDBLayer . fst
bracket before after $ \(_ctx, db) -> action db
where
Expand Down

0 comments on commit f3fdcee

Please sign in to comment.