Skip to content

Commit

Permalink
locli: add stddev to Distribution, and by consequent necessity s/Floa…
Browse files Browse the repository at this point in the history
…t/Double everywhere
  • Loading branch information
deepfire committed May 24, 2022
1 parent 70ba968 commit e12b786
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 70 deletions.
66 changes: 33 additions & 33 deletions bench/locli/src/Cardano/Analysis/API.hs
Expand Up @@ -38,20 +38,20 @@ data BlockPropagation
{ bpVersion :: !Version
, bpDomainSlots :: !(DataDomain SlotNo)
, bpDomainBlocks :: !(DataDomain BlockNo)
, bpForgerChecks :: !(Distribution Float NominalDiffTime)
, bpForgerLeads :: !(Distribution Float NominalDiffTime)
, bpForgerForges :: !(Distribution Float NominalDiffTime)
, bpForgerAdoptions :: !(Distribution Float NominalDiffTime)
, bpForgerAnnouncements :: !(Distribution Float NominalDiffTime)
, bpForgerSends :: !(Distribution Float NominalDiffTime)
, bpPeerNotices :: !(Distribution Float NominalDiffTime)
, bpPeerRequests :: !(Distribution Float NominalDiffTime)
, bpPeerFetches :: !(Distribution Float NominalDiffTime)
, bpPeerAdoptions :: !(Distribution Float NominalDiffTime)
, bpPeerAnnouncements :: !(Distribution Float NominalDiffTime)
, bpPeerSends :: !(Distribution Float NominalDiffTime)
, bpPropagation :: ![(Float, Distribution Float NominalDiffTime)]
, bpSizes :: !(Distribution Float Int)
, bpForgerChecks :: !(Distribution Double NominalDiffTime)
, bpForgerLeads :: !(Distribution Double NominalDiffTime)
, bpForgerForges :: !(Distribution Double NominalDiffTime)
, bpForgerAdoptions :: !(Distribution Double NominalDiffTime)
, bpForgerAnnouncements :: !(Distribution Double NominalDiffTime)
, bpForgerSends :: !(Distribution Double NominalDiffTime)
, bpPeerNotices :: !(Distribution Double NominalDiffTime)
, bpPeerRequests :: !(Distribution Double NominalDiffTime)
, bpPeerFetches :: !(Distribution Double NominalDiffTime)
, bpPeerAdoptions :: !(Distribution Double NominalDiffTime)
, bpPeerAnnouncements :: !(Distribution Double NominalDiffTime)
, bpPeerSends :: !(Distribution Double NominalDiffTime)
, bpPropagation :: ![(Double, Distribution Double NominalDiffTime)]
, bpSizes :: !(Distribution Double Int)
}
deriving (Generic, FromJSON, ToJSON, Show)

Expand All @@ -66,7 +66,7 @@ data BlockEvents
, beEpochSafeInt :: !EpochSafeInt
, beForge :: !BlockForge
, beObservations :: [BlockObservation]
, bePropagation :: !(Distribution Float NominalDiffTime)
, bePropagation :: !(Distribution Double NominalDiffTime)
-- ^ CDF of slot-start-to-adoptions on cluster
, beOtherBlocks :: [Hash]
, beErrors :: [BPError]
Expand Down Expand Up @@ -163,18 +163,18 @@ data MachTimeline' f
{ sVersion :: !Version
, sDomain :: !(f (DataDomain SlotNo))
-- distributions
, sMissDistrib :: !(f (Distribution Float Float))
, sLeadsDistrib :: !(f (Distribution Float Word64))
, sUtxoDistrib :: !(f (Distribution Float Word64))
, sDensityDistrib :: !(f (Distribution Float Float))
, sSpanCheckDistrib :: !(f (Distribution Float NominalDiffTime))
, sSpanLeadDistrib :: !(f (Distribution Float NominalDiffTime))
, sSpanForgeDistrib :: !(f (Distribution Float NominalDiffTime))
, sBlocklessDistrib :: !(f (Distribution Float Word64))
, sSpanLensCPU85Distrib :: !(f (Distribution Float Int))
, sSpanLensCPU85EBndDistrib :: !(f (Distribution Float Int))
, sSpanLensCPU85RwdDistrib :: !(f (Distribution Float Int))
, sResourceDistribs :: !(f (Resources (Distribution Float Word64)))
, sMissDistrib :: !(f (Distribution Double Double))
, sLeadsDistrib :: !(f (Distribution Double Word64))
, sUtxoDistrib :: !(f (Distribution Double Word64))
, sDensityDistrib :: !(f (Distribution Double Double))
, sSpanCheckDistrib :: !(f (Distribution Double NominalDiffTime))
, sSpanLeadDistrib :: !(f (Distribution Double NominalDiffTime))
, sSpanForgeDistrib :: !(f (Distribution Double NominalDiffTime))
, sBlocklessDistrib :: !(f (Distribution Double Word64))
, sSpanLensCPU85Distrib :: !(f (Distribution Double Int))
, sSpanLensCPU85EBndDistrib :: !(f (Distribution Double Int))
, sSpanLensCPU85RwdDistrib :: !(f (Distribution Double Int))
, sResourceDistribs :: !(f (Resources (Distribution Double Word64)))
}
deriving (Generic)

Expand Down Expand Up @@ -206,7 +206,7 @@ data SlotStats
, slTxsAccepted :: !Word64
, slTxsRejected :: !Word64
, slUtxoSize :: !Word64
, slDensity :: !Float
, slDensity :: !Double
, slResources :: !(Resources (Maybe Word64))
}
deriving (Generic, Show, ToJSON)
Expand Down Expand Up @@ -308,7 +308,7 @@ instance RenderDistributions BlockPropagation where
r = nChunksEachOf aLen 6 "Slot-rel. Δt to adoption centile:"
aLen = length adoptionPcts + 1 -- +1 is for the implied 1.0 percentile

adoptionPcts :: [PercSpec Float]
adoptionPcts :: [PercSpec Double]
adoptionPcts =
[ Perc 0.5, Perc 0.8, Perc 0.9, Perc 0.92, Perc 0.94, Perc 0.96, Perc 0.98 ]

Expand Down Expand Up @@ -354,7 +354,7 @@ instance RenderTimeline BlockEvents where
m = nChunksEachOf 3 4 "Missing"
n = nChunksEachOf 2 4 "Negative"

percSpec :: Float -> Distribution Float NominalDiffTime -> NominalDiffTime
percSpec :: Double -> Distribution Double NominalDiffTime -> NominalDiffTime
percSpec ps d = dPercSpec (Perc ps) d
& fromMaybe (error $ printf "No percentile %f in distribution." ps)
af f = avg . fmap f
Expand Down Expand Up @@ -438,7 +438,7 @@ instance RenderTimeline SlotStats where
, Field 6 0 "productiv" "Produc" "tivity" $ IText
(\SlotStats{..}->
f 4 $ calcProd <$> (min 6 . -- workaround for ghc-8.10.2
fromIntegral <$> rCentiMut slResources :: Maybe Float)
fromIntegral <$> rCentiMut slResources :: Maybe Double)
<*> (fromIntegral <$> rCentiCpu slResources))
, Field 5 0 "rssMB" (m 5!!0) "RSS" $ IText (d 5.rRSS .slResources)
, Field 5 0 "heapMB" (m 5!!1) "Heap" $ IText (d 5.rHeap .slResources)
Expand All @@ -447,7 +447,7 @@ instance RenderTimeline SlotStats where
, Field 6 0 "allocMut" "Alloc/" "mutSec" $ IText
(\SlotStats{..}->
d 5 $
(ceiling :: Float -> Int)
(ceiling :: Double -> Int)
<$> ((/) <$> (fromIntegral . (100 *) <$> rAlloc slResources)
<*> (fromIntegral . max 1 . (1024 *) <$> rCentiMut slResources)))
, Field 7 0 "mempoolTxs" "Mempool" "txs" $ IWord64 slMempoolTxs
Expand All @@ -471,5 +471,5 @@ instance RenderTimeline SlotStats where
Just x -> T.pack $ printf ("%0."<>show width<>"f") x
Nothing -> mconcat (replicate width "-")

calcProd :: Float -> Float -> Float
calcProd :: Double -> Double -> Double
calcProd mut' cpu' = if cpu' == 0 then 1 else mut' / cpu'
12 changes: 6 additions & 6 deletions bench/locli/src/Cardano/Analysis/BlockProp.hs
Expand Up @@ -234,20 +234,20 @@ beForgedAt BlockEvents{beForge=BlockForge{..}} =
bfForged `afterSlot` bfSlotStart

mapChainToBlockEventCDF ::
(Real a, ToRealFrac a Float)
=> [PercSpec Float]
(Real a, ToRealFrac a Double)
=> [PercSpec Double]
-> [BlockEvents]
-> (BlockEvents -> Maybe a)
-> Distribution Float a
-> Distribution Double a
mapChainToBlockEventCDF percs cbes proj =
computeDistribution percs $ mapMaybe proj cbes

mapChainToPeerBlockObservationCDF ::
[PercSpec Float]
[PercSpec Double]
-> [BlockEvents]
-> (BlockObservation -> Maybe NominalDiffTime)
-> String
-> Distribution Float NominalDiffTime
-> Distribution Double NominalDiffTime
mapChainToPeerBlockObservationCDF percs cbes proj desc =
computeDistribution percs allObservations
where
Expand Down Expand Up @@ -456,7 +456,7 @@ blockProp run@Run{genesis} chain domSlot domBlock = do
, bpVersion = getVersion
}
where
forgerEventsCDF :: (Real a, ToRealFrac a Float) => (BlockEvents -> Maybe a) -> Distribution Float a
forgerEventsCDF :: (Real a, ToRealFrac a Double) => (BlockEvents -> Maybe a) -> Distribution Double a
forgerEventsCDF = mapChainToBlockEventCDF stdPercSpecs chain
observerEventsCDF = mapChainToPeerBlockObservationCDF stdPercSpecs chain

Expand Down
6 changes: 3 additions & 3 deletions bench/locli/src/Cardano/Analysis/MachTimeline.hs
Expand Up @@ -36,7 +36,7 @@ data RunScalars
= RunScalars
{ rsElapsed :: Maybe NominalDiffTime
, rsSubmitted :: Maybe Word64
, rsThreadwiseTps :: Maybe (Vector Float)
, rsThreadwiseTps :: Maybe (Vector Double)
}
deriving stock Generic
deriving anyclass NFData
Expand Down Expand Up @@ -95,7 +95,7 @@ slotStatsSummary _ (f, slots) =
}
where
i = Identity
dist :: (Real a, ToRealFrac a Float) => [a] -> Identity (Distribution Float a)
dist :: (Real a, ToRealFrac a Double) => [a] -> Identity (Distribution Double a)
dist = i . computeDistribution stdPercSpecs
sSpanLensCPU85EBnd = Vec.length <$>
filter (spanContainsEpochSlot 3) spansCPU85
Expand Down Expand Up @@ -134,7 +134,7 @@ slotStatsSummary _ (f, slots) =
, rThreads = rThreads . slResources
}

missRatio :: Word64 -> Float
missRatio :: Word64 -> Double
missRatio = (/ fromIntegral maxChecks) . fromIntegral

-- The "fold" state that accumulates as we process 'LogObject's into a stream
Expand Down
4 changes: 2 additions & 2 deletions bench/locli/src/Cardano/Unlog/LogObject.hs
Expand Up @@ -207,14 +207,14 @@ logObjectStreamInterpreterKeysLegacy = Map.keys (fst interpreters)
logObjectStreamInterpreterKeys = Map.keys (snd interpreters)

data LOBody
= LOTraceStartLeadershipCheck !SlotNo !Word64 !Float
= LOTraceStartLeadershipCheck !SlotNo !Word64 !Double
| LOTraceLeadershipDecided !SlotNo !Bool
| LOResources !ResourceStats
| LOMempoolTxs !Word64
| LOMempoolRejectedTx
| LOLedgerTookSnapshot
| LOBlockContext !Word64
| LOGeneratorSummary !Bool !Word64 !NominalDiffTime (Vector Float)
| LOGeneratorSummary !Bool !Word64 !NominalDiffTime (Vector Double)
| LOTxsAcked !(Vector Text)
| LOTxsCollected !Word64
| LOTxsProcessed !Word64 !Int
Expand Down
21 changes: 11 additions & 10 deletions bench/locli/src/Cardano/Unlog/Render.hs
Expand Up @@ -48,19 +48,19 @@ type DField a = Field DSelect a
type IField a = Field ISelect a

data DSelect a
= DInt (a -> Distribution Float Int)
| DWord64 (a -> Distribution Float Word64)
| DFloat (a -> Distribution Float Float)
| DDeltaT (a -> Distribution Float NominalDiffTime)
= DInt (a -> Distribution Double Int)
| DWord64 (a -> Distribution Double Word64)
| DFloat (a -> Distribution Double Double)
| DDeltaT (a -> Distribution Double NominalDiffTime)

data ISelect a
= IInt (a -> Int)
| IWord64 (a -> Word64)
| IFloat (a -> Float)
| IFloat (a -> Double)
| IDeltaT (a -> NominalDiffTime)
| IText (a -> Text)

mapSomeFieldDistribution :: (forall b. Distribution Float b -> c) -> a -> DSelect a -> c
mapSomeFieldDistribution :: (forall b. Distribution Double b -> c) -> a -> DSelect a -> c
mapSomeFieldDistribution f a = \case
DInt s -> f (s a)
DWord64 s -> f (s a)
Expand Down Expand Up @@ -104,7 +104,7 @@ renderTimeline run flt withCommentary xs =
renderField lpfn wfn rfn f = T.replicate (lpfn f) " " <> T.center (wfn f) ' ' (rfn f)

renderDistributions :: forall a. RenderDistributions a =>
Run -> RenderMode -> (DField a -> Bool) -> Maybe [PercSpec Float] -> a
Run -> RenderMode -> (DField a -> Bool) -> Maybe [PercSpec Double] -> a
-> [Text]
renderDistributions run mode flt mPercs x =
case mode of
Expand All @@ -113,13 +113,13 @@ renderDistributions run mode flt mPercs x =
where headCsv = T.intercalate "," $ fId <$> fields

where
percSpecs :: [PercSpec Float]
percSpecs :: [PercSpec Double]
percSpecs = maybe (mapSomeFieldDistribution distribPercSpecs x (fSelect . head $ rdFields run))
id
mPercs

-- XXX: very expensive, the way it's used below..
subsetDistrib :: Distribution Float b -> Distribution Float b
subsetDistrib :: Distribution Double b -> Distribution Double b
subsetDistrib = maybe id subsetDistribution mPercs

pLines :: [Text]
Expand Down Expand Up @@ -185,11 +185,12 @@ renderDistributions run mode flt mPercs x =
nPercs = length $ dPercentiles percsDistrib
percsDistrib = mapSomeFieldDistribution
(distribPercsAsDistrib . subsetDistrib) x (fSelect $ head (rdFields run))
distribPercsAsDistrib :: Distribution Float b -> Distribution Float Float
distribPercsAsDistrib :: Distribution Double b -> Distribution Double Double
distribPercsAsDistrib Distribution{..} =
Distribution
(length dPercentiles)
0.5
0.5
(head dPercentiles & psFrac . pctSpec,
last dPercentiles & psFrac . pctSpec)
$ (\p -> p {pctSample = psFrac (pctSpec p)}) <$> dPercentiles
Expand Down
6 changes: 3 additions & 3 deletions bench/locli/src/Cardano/Unlog/Resources.hs
Expand Up @@ -52,14 +52,14 @@ type ResDistribProjections a = Resources (a -> Maybe Word64)

computeResDistrib ::
forall a
. [PercSpec Float]
. [PercSpec Double]
-> ResDistribProjections a
-> [a]
-> Resources (Distribution Float Word64)
-> Resources (Distribution Double Word64)
computeResDistrib percentiles projs xs =
compDist <$> projs
where
compDist :: (a -> Maybe Word64) -> Distribution Float Word64
compDist :: (a -> Maybe Word64) -> Distribution Double Word64
compDist proj = computeDistribution percentiles
(catMaybes . toList $ proj <$> xs)

Expand Down

0 comments on commit e12b786

Please sign in to comment.