Skip to content

Commit 202b6d2

Browse files
committed
simulation: accumulate cpu events per node in Leios sim model
1 parent 03c9d55 commit 202b6d2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

simulation/ouroboros-leios-sim.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ library
120120
, graphviz
121121
, gtk3
122122
, hashable
123+
, IntervalMap
123124
, io-classes
124125
, io-sim
125126
, kdt

simulation/src/LeiosProtocol/Short/VizSim.hs

+18-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Data.Coerce (coerce)
1515
import Data.Hashable (hash)
1616
import Data.IntMap (IntMap)
1717
import qualified Data.IntMap.Strict as IMap
18+
import Data.IntervalMap.Strict (Interval (..), IntervalMap)
19+
import qualified Data.IntervalMap.Strict as ILMap
1820
import Data.Map.Strict (Map)
1921
import qualified Data.Map.Strict as Map
2022
import Data.Maybe (fromMaybe)
@@ -126,6 +128,7 @@ data LeiosSimVizState
126128
, ebMsgs :: !(LeiosSimVizMsgsState EndorseBlockId EndorseBlock)
127129
, voteMsgs :: !(LeiosSimVizMsgsState VoteId VoteMsg)
128130
, ibsInRBs :: !IBsInRBsState
131+
, nodeCpuUsage :: !(Map NodeId (IntervalMap DiffTime Int))
129132
}
130133

131134
data LeiosSimVizMsgsState id msg = LeiosSimVizMsgsState
@@ -174,6 +177,13 @@ data LinkPoints
174177
{-# UNPACK #-} !Point
175178
deriving (Show)
176179

180+
accumNodeCpuUsage :: Time -> LeiosEvent -> Map NodeId (IntervalMap DiffTime Int) -> Map NodeId (IntervalMap DiffTime Int)
181+
accumNodeCpuUsage (Time now) (LeiosEventNode (LabelNode nid (PraosNodeEvent (PraosNodeEventCPU task)))) =
182+
Map.insertWith ILMap.union nid (ILMap.singleton (ClosedInterval now (now + cpuTaskDuration task)) 1)
183+
accumNodeCpuUsage (Time now) (LeiosEventNode (LabelNode nid (LeiosNodeEventCPU task))) =
184+
Map.insertWith ILMap.union nid (ILMap.singleton (ClosedInterval now (now + cpuTaskDuration task)) 1)
185+
accumNodeCpuUsage _ _ = id
186+
177187
type ChainsMap = IntMap (Chain (Block RankingBlockBody))
178188

179189
accumChains :: Time -> LeiosEvent -> ChainsMap -> ChainsMap
@@ -250,6 +260,7 @@ leiosSimVizModel =
250260
, ebMsgs = initMsgs
251261
, voteMsgs = initMsgs
252262
, ibsInRBs = IBsInRBsState Map.empty Map.empty
263+
, nodeCpuUsage = Map.empty
253264
}
254265

255266
accumEventVizState ::
@@ -367,13 +378,14 @@ leiosSimVizModel =
367378
[(msg, msgforecast, msgforecasts)]
368379
(vizMsgsInTransit vs)
369380
}
370-
accumEventVizState _now (LeiosEventNode (LabelNode _nodeId (LeiosNodeEventCPU _task))) vs = vs
381+
accumEventVizState now e@(LeiosEventNode (LabelNode _nodeId (LeiosNodeEventCPU _task))) vs =
382+
vs{nodeCpuUsage = accumNodeCpuUsage now e (nodeCpuUsage vs)}
371383
accumEventVizState
372-
_now
373-
( LeiosEventNode
374-
(LabelNode _nodeId (PraosNodeEvent (PraosNodeEventCPU _task)))
375-
)
376-
vs = vs
384+
now
385+
e@( LeiosEventNode
386+
(LabelNode _nodeId (PraosNodeEvent (PraosNodeEventCPU _task)))
387+
)
388+
vs = vs{nodeCpuUsage = accumNodeCpuUsage now e (nodeCpuUsage vs)}
377389

378390
pruneVisState ::
379391
Time ->

0 commit comments

Comments
 (0)