Skip to content

Commit 806bb14

Browse files
committed
locli & workbench: CDF exports & various cleanups
1 parent c817004 commit 806bb14

File tree

11 files changed

+336
-219
lines changed

11 files changed

+336
-219
lines changed

bench/locli/src/Cardano/Analysis/API.hs

+32-25
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ deriving instance (Show (f NominalDiffTime), Show (f Int)) => Show (
5959
deriving instance (FromJSON (f NominalDiffTime), FromJSON (f Int)) => FromJSON (BlockProp f)
6060
deriving instance (ToJSON (f NominalDiffTime), ToJSON (f Int)) => ToJSON (BlockProp f)
6161

62-
type BlockPropOne = BlockProp I
63-
type BlockProps = BlockProp (CDF I)
62+
type BlockPropOne = BlockProp I
63+
type MultiBlockProp = BlockProp (CDF I)
6464

6565
-- | All events related to a block.
6666
data BlockEvents
@@ -215,8 +215,8 @@ type ClusterPerf = MachPerf (CDF I)
215215

216216
-- | Bunch'a bunches'a machine performances.
217217
-- Same as above, since we collapse [CDF I] into CDF I -- just with more statistical confidence.
218-
newtype ClusterPerfs
219-
= ClusterPerfs { unClusterPerfs :: ClusterPerf }
218+
newtype MultiClusterPerf
219+
= MultiClusterPerf { unMultiClusterPerf :: ClusterPerf }
220220
deriving newtype (ToJSON, FromJSON)
221221

222222
deriving newtype instance FromJSON a => FromJSON (I a)
@@ -306,17 +306,27 @@ testSlotStats g SlotStats{..} = \case
306306
--
307307
-- * Timeline rendering instances
308308
--
309-
bpFieldsForger :: Field DSelect p a -> Bool
310-
bpFieldsForger Field{fId} = elem fId
309+
bpFieldSelectForger :: Field DSelect p a -> Bool
310+
bpFieldSelectForger Field{fId} = elem fId
311311
[ "fChecked", "fLeading", "fForged", "fAdopted", "fAnnounced", "fSendStart" ]
312312

313-
bpFieldsPeers :: Field DSelect p a -> Bool
314-
bpFieldsPeers Field{fId} = elem fId
315-
[ "noticedVal", "requestedVal", "fetchedVal", "pAdoptedVal", "pAnnouncedVal", "pSendStartVal" ]
313+
bpFieldSelectPeers :: Field DSelect p a -> Bool
314+
bpFieldSelectPeers Field{fId} = elem fId
315+
[ "pNoticed", "pRequested", "pFetched", "pAdopted", "pAnnounced", "pSendStart" ]
316316

317-
bpFieldsPropagation :: Field DSelect p a -> Bool
318-
bpFieldsPropagation Field{fHead2} = elem fHead2
319-
[ "0.50", "0.80", "0.90", "0.92", "0.94", "0.96", "0.98", "1.00" ]
317+
bpFieldSelectPropagation :: Field DSelect p a -> Bool
318+
bpFieldSelectPropagation Field{fHead2} = elem fHead2 adoptionPctsRendered
319+
320+
renderAdoptionCentile :: Centile -> Text
321+
renderAdoptionCentile = T.pack . printf "prop%0.2f" . unCentile
322+
323+
adoptionPctsRendered :: [Text]
324+
adoptionPctsRendered = adoptionPcts <&> T.drop 4 . renderAdoptionCentile
325+
326+
adoptionPcts :: [Centile]
327+
adoptionPcts =
328+
[ Centile 0.5, Centile 0.8, Centile 0.9
329+
, Centile 0.92, Centile 0.94, Centile 0.96, Centile 0.98, Centile 1.0 ]
320330

321331
instance RenderCDFs BlockProp p where
322332
rdFields =
@@ -334,27 +344,24 @@ instance RenderCDFs BlockProp p where
334344
, Field 5 0 "pAnnounced" (p!!4) "Annou" $ DDeltaT bpPeerAnnouncements
335345
, Field 5 0 "pSendStart" (p!!5) "Send" $ DDeltaT bpPeerSends
336346
] ++
337-
[ Field 5 0 (printf "prop%.02f" ps & T.pack)
347+
[ Field 5 0 (renderAdoptionCentile ct)
338348
(r!!i)
339-
(T.take 4 $ T.pack $ printf "%.04f" ps)
340-
(DDeltaT ((\(ps', d) ->
341-
if ps' == ps then d
342-
else error $ printf "Centile mismatch: [%d]: exp=%f act=%f" i ps ps')
349+
(T.take 4 $ T.pack $ printf "%.04f" centi)
350+
(DDeltaT ((\(centi', d) ->
351+
if centi' == centi then d
352+
else error $ printf "Centile mismatch: [%d]: exp=%f act=%f"
353+
i centi centi')
343354
. fromMaybe
344-
(error $ printf "No centile %d/%f in bpPropagation." i ps)
355+
(error $ printf "No centile %d/%f in bpPropagation." i centi)
345356
. flip atMay i . bpPropagation))
346-
| (i, Centile ps) <- zip [0::Int ..] (adoptionPcts <> [Centile 1.0]) ] ++
357+
| (i, ct@(Centile centi)) <- zip [0::Int ..] adoptionPcts ] ++
347358
[ Field 9 0 "sizes" "Size" "bytes" $ DInt bpSizes
348359
]
349360
where
350361
f = nChunksEachOf 6 7 "--- Forger event Δt: ---"
351362
p = nChunksEachOf 6 6 "--- Peer event Δt: ---"
352363
r = nChunksEachOf aLen 6 "Slot-rel. Δt to adoption centile:"
353-
aLen = length adoptionPcts + 1 -- +1 is for the implied 1.0 centile
354-
355-
adoptionPcts :: [Centile]
356-
adoptionPcts =
357-
[ Centile 0.5, Centile 0.8, Centile 0.9, Centile 0.92, Centile 0.94, Centile 0.96, Centile 0.98 ]
364+
aLen = length adoptionPcts
358365

359366
instance RenderTimeline BlockEvents where
360367
rtFields _ =
@@ -382,7 +389,7 @@ instance RenderTimeline BlockEvents where
382389
, Field 5 0 "pSendStartVal" (p!!5) "Send" $ IDeltaT (af' boSending . valids)
383390
, Field 5 0 "pPropag0.5" (r!!0) "0.5" $ IDeltaT (percSpec 0.5 . bePropagation)
384391
, Field 5 0 "pPropag0.96" (r!!1) "0.96" $ IDeltaT (percSpec 0.96 . bePropagation)
385-
, Field 5 0 "pPropag1.0" (r!!2) "1.0" $ IDeltaT (percSpec 1.0 . bePropagation)
392+
, Field 5 0 "pPropag1.0" (r!!2) "1.0" $ IDeltaT (snd . cdfRange . bePropagation)
386393
, Field 5 0 "errors" "all" "errs" $ IInt (length . beErrors)
387394
, Field 3 0 "missAdopt" (m!!0) "ado" $ IInt (count (bpeIsMissing Adopt) . beErrors)
388395
, Field 3 0 "missAnnou" (m!!1) "ann" $ IInt (count (bpeIsMissing Announce) . beErrors)

bench/locli/src/Cardano/Analysis/BlockProp.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{- HLINT ignore "Use head" -}
66
{- HLINT ignore "Avoid lambda" -}
77
module Cardano.Analysis.BlockProp
8-
( summariseBlockProps
8+
( summariseMultiBlockProp
99
, MachView
1010
, buildMachViews
1111
, rebuildChain
@@ -54,9 +54,9 @@ import Cardano.Unlog.Resources
5454
import Cardano.Util
5555

5656

57-
summariseBlockProps :: [Centile] -> [BlockPropOne] -> Either CDFError BlockProps
58-
summariseBlockProps _ [] = error "Asked to summarise empty list of BlockPropOne"
59-
summariseBlockProps centiles bs@(headline:_) = do
57+
summariseMultiBlockProp :: [Centile] -> [BlockPropOne] -> Either CDFError MultiBlockProp
58+
summariseMultiBlockProp _ [] = error "Asked to summarise empty list of BlockPropOne"
59+
summariseMultiBlockProp centiles bs@(headline:_) = do
6060
bpForgerChecks <- cdf2OfCDFs comb $ bs <&> bpForgerChecks
6161
bpForgerLeads <- cdf2OfCDFs comb $ bs <&> bpForgerLeads
6262
bpForgerForges <- cdf2OfCDFs comb $ bs <&> bpForgerForges

bench/locli/src/Cardano/Analysis/Ground.hs

+12
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ newtype JsonOutputFile
104104
= JsonOutputFile { unJsonOutputFile :: FilePath }
105105
deriving (Show, Eq)
106106

107+
newtype CDFOutputFile
108+
= CDFOutputFile { unCDFOutputFile :: FilePath }
109+
deriving (Show, Eq)
110+
107111
newtype TextOutputFile
108112
= TextOutputFile { unTextOutputFile :: FilePath }
109113
deriving (Show, Eq)
@@ -200,6 +204,14 @@ optJsonOutputFile optname desc =
200204
<> metavar "JSON-OUTFILE"
201205
<> help desc
202206

207+
optCDFOutputFile :: String -> String -> Parser CDFOutputFile
208+
optCDFOutputFile optname desc =
209+
fmap CDFOutputFile $
210+
Opt.option Opt.str
211+
$ long optname
212+
<> metavar "CDF-OUTFILE"
213+
<> help desc
214+
203215
optTextOutputFile :: String -> String -> Parser TextOutputFile
204216
optTextOutputFile optname desc =
205217
fmap TextOutputFile $

bench/locli/src/Cardano/Analysis/MachPerf.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import Cardano.Unlog.LogObject hiding (Text)
3131
import Cardano.Unlog.Resources
3232

3333

34-
summariseClusterPerfs :: [Centile] -> [ClusterPerf] -> Either CDFError ClusterPerfs
35-
summariseClusterPerfs _ [] = error "Asked to summarise empty list of MachPerfOne"
36-
summariseClusterPerfs centiles mps@(headline:_) = do
34+
summariseMultiClusterPerf :: [Centile] -> [ClusterPerf] -> Either CDFError MultiClusterPerf
35+
summariseMultiClusterPerf _ [] = error "Asked to summarise empty list of MachPerfOne"
36+
summariseMultiClusterPerf centiles mps@(headline:_) = do
3737
sMissCDF <- cdf2OfCDFs comb $ mps <&> sMissCDF
3838
sLeadsCDF <- cdf2OfCDFs comb $ mps <&> sLeadsCDF
3939
sUtxoCDF <- cdf2OfCDFs comb $ mps <&> sUtxoCDF
@@ -50,7 +50,7 @@ summariseClusterPerfs centiles mps@(headline:_) = do
5050
[] -> Left CDFEmptyDataset
5151
(xs :: [CDF (CDF I) Word64]) -> cdf2OfCDFs comb xs :: Either CDFError (CDF (CDF I) Word64)
5252

53-
pure . ClusterPerfs $ MachPerf
53+
pure . MultiClusterPerf $ MachPerf
5454
{ sVersion = sVersion headline
5555
, sDomainSlots = dataDomainsMergeOuter $ mps <&> sDomainSlots
5656
, ..

bench/locli/src/Cardano/Analysis/Run.hs

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Data.Aeson qualified as Aeson
1010
import Data.Aeson (FromJSON(..), Object, ToJSON(..), withObject, (.:), (.:?))
1111
import Data.ByteString.Lazy.Char8 qualified as LBS
1212
import Data.Text qualified as T
13+
import Data.Time.Clock
14+
import Data.Time.Clock.POSIX
1315

1416
import Cardano.Analysis.ChainFilter
1517
import Cardano.Analysis.Context
@@ -20,16 +22,17 @@ import Cardano.Util
2022
-- | Explain the poor human a little bit of what was going on:
2123
data Anchor
2224
= Anchor
23-
{ aRuns :: ![Text]
24-
, aFilters :: ![FilterName]
25-
, aVersion :: !Version
25+
{ aRuns :: [Text]
26+
, aFilters :: [FilterName]
27+
, aVersion :: Version
28+
, aWhen :: UTCTime
2629
}
2730

28-
runAnchor :: Run -> [FilterName] -> Anchor
31+
runAnchor :: Run -> UTCTime -> [FilterName] -> Anchor
2932
runAnchor Run{..} = tagsAnchor [tag metadata]
3033

31-
tagsAnchor :: [Text] -> [FilterName] -> Anchor
32-
tagsAnchor aRuns aFilters =
34+
tagsAnchor :: [Text] -> UTCTime -> [FilterName] -> Anchor
35+
tagsAnchor aRuns aWhen aFilters =
3336
Anchor { aVersion = getVersion, .. }
3437

3538
renderAnchor :: Anchor -> Text
@@ -40,6 +43,8 @@ renderAnchor Anchor{..} = mconcat
4043
xs -> T.intercalate ", " (unFilterName <$> xs)
4144
, ", "
4245
, renderProgramAndVersion aVersion
46+
, ", analysed at "
47+
, show (posixSecondsToUTCTime . utcTimeToPOSIXSeconds $ aWhen) -- Round to seconds.
4348
]
4449

4550
data AnalysisCmdError

0 commit comments

Comments
 (0)