Skip to content

Commit dfec557

Browse files
committed
tx-generator: trace expected amount of transactions
1 parent 04bb8fb commit dfec557

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎bench/tx-generator/src/Cardano/Benchmarking/Script.hs‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE BlockArguments #-}
22
{-# LANGUAGE LambdaCase #-}
3+
{-# LANGUAGE MultiWayIf #-}
34
{-# LANGUAGE NumericUnderscores #-}
45
{-# LANGUAGE RecordWildCards #-}
56

@@ -15,7 +16,7 @@ import Cardano.Benchmarking.Script.Action
1516
import Cardano.Benchmarking.Script.Aeson (parseScriptFileAeson)
1617
import Cardano.Benchmarking.Script.Core (setProtocolParameters)
1718
import qualified Cardano.Benchmarking.Script.Env as Env (ActionM, Env (..), Error,
18-
getEnvThreads, runActionMEnv, traceError)
19+
getEnvThreads, runActionMEnv, traceDebug, traceError)
1920
import Cardano.Benchmarking.Script.Types
2021

2122
import Prelude
@@ -35,6 +36,17 @@ type Script = [Action]
3536
-- 'Ogmios') never create one, in which case it is 'Nothing'.
3637
runScript :: Env.Env -> Script -> EnvConsts -> IO (Either Env.Error (), Maybe AsyncBenchmarkControl)
3738
runScript env script constants@EnvConsts { .. } = do
39+
-- Plain 'putStrLn', not a trace: this runs before the script's own
40+
-- 'StartProtocol' action (if it even has one), so BenchTracers are
41+
-- not yet constructed.
42+
putStrLn $ "This workload script will generate " ++
43+
( let count = countScriptTxns script in
44+
if
45+
| count == 0 -> "no transactions"
46+
| count == maxBound -> "an infinite stream of transactions"
47+
| count == (-1) -> "an unknown number of transactions (stream is non-deterministic)"
48+
| otherwise -> "a finite stream yielding " ++ show count ++ " transactions"
49+
)
3850
result <- go
3951
performGC
4052
threadDelay $ 150 * 1_000
@@ -60,5 +72,31 @@ runScript env script constants@EnvConsts { .. } = do
6072

6173
shutDownLogging :: Env.ActionM ()
6274
shutDownLogging = do
63-
Env.traceError "QRT Last Message. LoggingLayer shutting down ..."
75+
Env.traceDebug "QRT Last Message. LoggingLayer shutting down ..."
6476
liftIO $ threadDelay $ 350 * 1_000
77+
78+
-- Results:
79+
-- (-1): somwhere in [0..Infinity] due to use of non-deterministic generator combinator
80+
-- maxBound: infinite txn stream
81+
-- n: finite stream of n txns
82+
countScriptTxns :: Script -> Int
83+
countScriptTxns = sum . map actionTxCount
84+
where
85+
actionTxCount = \case
86+
Submit _ _ _ gen -> genTxCount gen
87+
_ -> 0
88+
genTxCount = \case
89+
SecureGenesis{} -> 1
90+
Split{} -> 1
91+
SplitN{} -> 1
92+
NtoM{} -> 1
93+
Cycle g -> if genTxCount g < 0 then (-1) else maxBound
94+
Take i g -> min i (genTxCount g)
95+
Sequence gs -> guardedSum $ map genTxCount gs
96+
RoundRobin gs -> guardedSum $ map genTxCount gs
97+
OneOf{} -> (-1) -- is non-deterministic
98+
where
99+
guardedSum is
100+
| any (< 0) is = -1
101+
| maxBound `elem` is = maxBound
102+
| otherwise = sum is

‎bench/tx-generator/src/Cardano/Benchmarking/Script/Env.hs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,12 @@ getBenchTracers = do
254254
case mTracer of
255255
Just tracer -> pure tracer
256256
Nothing -> do
257-
-- If this occurs, it may be worthwhile to output it in more ways
258-
-- because the tracer isn't actually initialized.
257+
-- Deliberately not `traceError`: that goes through
258+
-- `traceBenchTxSubmit`, which calls back into `getBenchTracers`,
259+
-- and again into this branch, causing infinite recursion.
259260
let errMsg = "Env.getBenchTracers: attempted to set tracer before\
260261
\ STM.TVar init"
261-
traceError errMsg
262-
liftIO $ do
263-
putStrLn errMsg
264-
IO.hPutStrLn IO.stderr errMsg
262+
liftIO $ IO.hPutStrLn IO.stderr errMsg
265263
pure $ error errMsg
266264

267265
-- | Read accessor for `envGenesis`.

0 commit comments

Comments
 (0)