-
Notifications
You must be signed in to change notification settings - Fork 755
Expand file tree
/
Copy pathScript.hs
More file actions
64 lines (57 loc) · 2.38 KB
/
Copy pathScript.hs
File metadata and controls
64 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RecordWildCards #-}
module Cardano.Benchmarking.Script
( Script
, runScript
, parseScriptFileAeson
)
where
import Cardano.Benchmarking.LogTypes
import Cardano.Benchmarking.Script.Action
import Cardano.Benchmarking.Script.Aeson (parseScriptFileAeson)
import Cardano.Benchmarking.Script.Core (setProtocolParameters)
import qualified Cardano.Benchmarking.Script.Env as Env (ActionM, Env (..), Error,
getEnvThreads, runActionMEnv, traceError)
import Cardano.Benchmarking.Script.Types
import Prelude
import Control.Concurrent (threadDelay)
import Control.Concurrent.STM.TVar as STM (readTVar)
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.STM as STM (atomically)
import System.Mem (performGC)
type Script = [Action]
-- | Run a benchmarking script. The second component of the result carries
-- the 'AsyncBenchmarkControl' of the submission threads when the script
-- started any: submit modes other than 'Benchmark' (e.g. 'LocalSocket',
-- 'Ogmios') never create one, in which case it is 'Nothing'.
runScript :: Env.Env -> Script -> EnvConsts -> IO (Either Env.Error (), Maybe AsyncBenchmarkControl)
runScript env script constants@EnvConsts { .. } = do
result <- go
performGC
threadDelay $ 150 * 1_000
return result
where
go :: IO (Either Env.Error (), Maybe AsyncBenchmarkControl)
go = Env.runActionMEnv env execScript constants >>= \case
(Right abcMaybe, env', ()) -> do
cleanup env' shutDownLogging
pure (Right (), abcMaybe)
(Left err, env', ()) -> do
cleanup env' (Env.traceError (show err) >> shutDownLogging)
abcMaybe <- STM.atomically $ STM.readTVar envThreads
pure (Left err, abcMaybe)
where
cleanup :: Env.Env -> Env.ActionM () -> IO ()
cleanup env' acts = void $ Env.runActionMEnv env' acts constants
execScript :: Env.ActionM (Maybe AsyncBenchmarkControl)
execScript = do
setProtocolParameters QueryLocalNode
forM_ script action
Env.getEnvThreads
shutDownLogging :: Env.ActionM ()
shutDownLogging = do
Env.traceError "QRT Last Message. LoggingLayer shutting down ..."
liftIO $ threadDelay $ 350 * 1_000