Skip to content

Commit 445db4c

Browse files
committed
simulation: --log-verbosity replaces --no-log, --emit-control
`cabal run ols -- sim short-leios -h` shows details: ``` --log-verbosity NUMBER 0: no log; 1: major events; 2: debug; 3: all. (default: 1) ``` `major events` are the ones shown previously by default.
1 parent 7b6dc89 commit 445db4c

File tree

4 files changed

+54
-34
lines changed

4 files changed

+54
-34
lines changed

simulation/docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ OTHER_SCENARIOS := scenario4-higher-IB-rate scenario4-lower-stage-length scenari
4646
$(foreach s,$(OTHER_SCENARIOS),$(eval $(call main_scenario_template,$(s))))
4747

4848
#### Running simulations.
49-
SHORT_LEIOS = cabal run ols -- sim --output-seconds="$(SIM_SECONDS)" --output-file="$@" short-leios --no-log
49+
SHORT_LEIOS = cabal run ols -- sim --output-seconds="$(SIM_SECONDS)" --output-file="$@" short-leios --log-verbosity=0
5050

5151
%/sim-data.json: %/config.yaml %/topology.yaml
5252
$(SHORT_LEIOS) -l "$(word 1, $^)" -t "$(word 2, $^)" +RTS -s

simulation/src/LeiosProtocol/Short/DataSimP2P.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ accumDataTransmitted _msg TcpMsgForecast{..} = [(start, end, msgSize)]
232232

233233
data SimOutputConfig = SimOutputConfig
234234
{ logFile :: Maybe FilePath
235-
, emitControl :: Bool
235+
, logVerbosity :: Int
236236
, dataFile :: Maybe FilePath
237237
, analize :: Bool
238238
, stop :: Time
@@ -337,7 +337,7 @@ exampleSim seed cfg p2pNetwork@P2PNetwork{..} SimOutputConfig{..} = do
337337
runSampleModel' logFile logEvent model stop $
338338
exampleTrace2 seed cfg p2pNetwork
339339
logEvent = case sharedFormat of
340-
False -> logLeiosTraceEvent p2pNodeNames emitControl
340+
False -> logLeiosTraceEvent p2pNodeNames logVerbosity
341341
True -> (fmap toEncoding .) . sharedTraceEvent p2pNodeNames
342342
renderState fp st = do
343343
let diffusionData = maybeAnalizeRawData analize (rawDataFromState cfg p2pNetwork st stop)

simulation/src/LeiosProtocol/Short/Sim.hs

+37-24
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ data LeiosEvent
7070
LeiosEventTcp (LabelLink (TcpEvent LeiosMessage))
7171
deriving (Show)
7272

73-
logLeiosTraceEvent :: Map NodeId T.Text -> Bool -> DiffTime -> LeiosEvent -> Maybe Encoding
74-
logLeiosTraceEvent m emitControl t e = do
75-
x <- logLeiosEvent m emitControl e
73+
logLeiosTraceEvent :: Map NodeId T.Text -> Int -> DiffTime -> LeiosEvent -> Maybe Encoding
74+
logLeiosTraceEvent m loudness t e = do
75+
x <- logLeiosEvent m loudness e
7676
pure $ (pairs $ "time_s" .= t <> pair "event" x)
7777

78-
logLeiosEvent :: Map NodeId T.Text -> Bool -> LeiosEvent -> Maybe Encoding
79-
logLeiosEvent nodeNames emitControl e = case e of
78+
logLeiosEvent :: Map NodeId T.Text -> Int -> LeiosEvent -> Maybe Encoding
79+
logLeiosEvent nodeNames loudness e = case e of
8080
LeiosEventSetup{} -> Nothing
8181
LeiosEventNode (LabelNode nid x) -> do
8282
pairs <$> logNode nid x
@@ -87,14 +87,19 @@ logLeiosEvent nodeNames emitControl e = case e of
8787
"tag" .= asString "Sent"
8888
<> "sender" .= from
8989
<> "receipient" .= to
90-
<> "fragments" .= length fcs
91-
<> "forecast" .= forecast
92-
-- <> "forecasts" .= fcs
90+
<> mconcat
91+
[ "fragments" .= length fcs
92+
<> "forecast" .= forecast
93+
| emitDebug
94+
]
95+
<> mconcat ["forecasts" .= fcs | emitControl]
9396
<> "msg_size_bytes" .= fromBytes (messageSizeBytes msg)
9497
<> "time_to_received_s" .= (coerce forecast.msgRecvTrailingEdge - coerce forecast.msgSendLeadingEdge :: DiffTime)
9598
<> "sending_s" .= (coerce forecast.msgSendTrailingEdge - coerce forecast.msgSendLeadingEdge :: DiffTime)
9699
<> ps
97100
where
101+
emitControl = loudness >= 3
102+
emitDebug = loudness >= 2
98103
node nid = "node" .= nid <> "node_name" .= nodeNames Map.! nid
99104
ibKind = "kind" .= asString "IB"
100105
ebKind = "kind" .= asString "EB"
@@ -177,26 +182,34 @@ logLeiosEvent nodeNames emitControl e = case e of
177182
logMsg (PraosMsg (PraosMessage (Right (ProtocolMessage (SomeMessage (MsgBlock hash _body)))))) =
178183
Just $ rbKind <> "id" .= show (coerce @_ @Int hash)
179184
logMsg (PraosMsg msg)
180-
| emitControl = Just $ mconcat ["id" .= asString "control", "label" .= praosMessageLabel msg]
185+
| emitControl = Just $ mconcat [rbKind <> "id" .= asString "control", "msg_label" .= praosMessageLabel msg]
181186
| otherwise = Nothing
182187
logRelay :: (HasField "node" id NodeId, HasField "num" id Int) => (h -> id) -> RelayMessage id h b -> Maybe Series
183-
logRelay _getId (ProtocolMessage (SomeMessage (MsgRespondBodies xs))) =
184-
Just $ "ids" .= map (mkStringId . fst) xs <> "msg_label" .= asString "respond-bodies"
185-
logRelay _getId (ProtocolMessage (SomeMessage (MsgRequestBodies xs))) =
188+
logRelay _getId (ProtocolMessage (SomeMessage msg@(MsgRespondBodies xs))) =
186189
Just $
187-
"ids" .= map mkStringId xs
188-
<> "msg_label" .= asString "request-bodies"
189-
logRelay getId (ProtocolMessage (SomeMessage (MsgRespondHeaders xs))) =
190-
Just $
191-
"ids" .= map (mkStringId . getId) (toList xs)
192-
<> "msg_label" .= asString "respond-headers"
193-
logRelay _getId (ProtocolMessage (SomeMessage (MsgRequestHeaders _ ws we))) =
194-
Just $
195-
"shrink" .= ws.value
196-
<> "expand" .= we.value
197-
<> "msg_label" .= asString "request-headers"
190+
"ids" .= map (mkStringId . fst) xs
191+
<> "msg_label" .= relayMessageLabel msg
192+
logRelay _getId (ProtocolMessage (SomeMessage msg@(MsgRequestBodies xs)))
193+
| emitDebug =
194+
Just $
195+
"ids" .= map mkStringId xs
196+
<> "msg_label" .= relayMessageLabel msg
197+
logRelay getId (ProtocolMessage (SomeMessage msg@(MsgRespondHeaders xs)))
198+
| emitDebug =
199+
Just $
200+
"ids" .= map (mkStringId . getId) (toList xs)
201+
<> "msg_label" .= relayMessageLabel msg
202+
logRelay _getId (ProtocolMessage (SomeMessage msg@(MsgRequestHeaders _ ws we)))
203+
| emitDebug =
204+
Just $
205+
"shrink" .= ws.value
206+
<> "expand" .= we.value
207+
<> "msg_label" .= relayMessageLabel msg
198208
logRelay _ (ProtocolMessage (SomeMessage msg))
199-
| emitControl = Just $ "id" .= asString "control" <> "label" .= relayMessageLabel msg
209+
| emitControl =
210+
Just $
211+
"id" .= asString "control"
212+
<> "msg_label" .= relayMessageLabel msg
200213
| otherwise = Nothing
201214
asString x = x :: String
202215

simulation/src/Main.hs

+14-7
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ runSimOptions SimOptions{..} = case simCommand of
374374
p2pNetwork <- execTopologyOptions rng1 topologyOptions
375375
let outputCfg =
376376
DataShortLeiosP2P.SimOutputConfig
377-
{ logFile = listToMaybe [dropExtension simOutputFile <.> "log" | not skipLog]
378-
, emitControl
377+
{ logFile = listToMaybe [dropExtension simOutputFile <.> "log" | logVerbosity > 0 || sharedFormat]
378+
, logVerbosity
379379
, dataFile = guard (takeExtension simOutputFile == ".json") >> pure simOutputFile
380380
, analize
381381
, stop = simOutputSeconds
@@ -413,8 +413,7 @@ data SimCommand
413413
{ seed :: Int
414414
, configOptions :: ConfigOptions
415415
, topologyOptions :: TopologyOptions
416-
, emitControl :: Bool
417-
, skipLog :: Bool
416+
, logVerbosity :: Int
418417
, analize :: Bool
419418
, sharedFormat :: Bool
420419
}
@@ -442,10 +441,18 @@ parserShortLeios =
442441
<$> parserSeed
443442
<*> parserConfigOptions
444443
<*> parserTopologyOptions
445-
<*> switch (long "log-control" <> help "Include control messages in log.")
446-
<*> switch (long "no-log" <> help "Do not output event log.")
444+
<*> logVerbosity
447445
<*> switch (long "analize" <> help "Calculate metrics and statistics.")
448-
<*> switch (long "shared-log-format" <> help "Use log format documented in trace.haskell.d.ts")
446+
<*> switch (long "shared-log-format" <> help "Use log format documented in trace.haskell.d.ts. Ignores --log-verbosity.")
447+
where
448+
logVerbosity =
449+
option
450+
auto
451+
( long "log-verbosity"
452+
<> metavar "NUMBER"
453+
<> help "0: no log; 1: major events; 2: debug; 3: all."
454+
<> shownDefValue 1
455+
)
449456

450457
data ConfigOptions
451458
= LeiosConfigFile FilePath

0 commit comments

Comments
 (0)