Skip to content

Commit

Permalink
bench | locli | mach-timeline: drop legacy impl
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Jan 17, 2022
1 parent b3e913f commit 82c8eba
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 581 deletions.
4 changes: 2 additions & 2 deletions bench/locli/locli.cabal
Expand Up @@ -32,7 +32,6 @@ library
Cardano.Unlog.Render
Cardano.Unlog.Resources
Cardano.Unlog.Run
Cardano.Unlog.SlotStats

other-modules: Paths_locli

Expand All @@ -45,6 +44,7 @@ library
, bytestring
, cardano-config
, cardano-prelude
, iohk-monitoring
, cardano-slotting
, containers
, deepseq
Expand All @@ -53,7 +53,6 @@ library
, file-embed
, gnuplot
, Histogram
, iohk-monitoring
, optparse-applicative-fork
, optparse-generic
, ouroboros-network
Expand All @@ -66,6 +65,7 @@ library
, text
, text-short
, time
, trace-resources
, transformers
, transformers-except
, unordered-containers
Expand Down
140 changes: 133 additions & 7 deletions bench/locli/src/Cardano/Analysis/API.hs
Expand Up @@ -11,19 +11,21 @@ import Prelude ((!!), error)
import Cardano.Prelude hiding (head)

import Data.Aeson (ToJSON(..), FromJSON(..))
import Data.List.Split (splitOn)
import Data.Text qualified as T
import Data.Text.Short (toText)
import Data.Time.Clock (NominalDiffTime)
import Text.Printf (printf)
import Data.Time (UTCTime)
import Text.Printf (PrintfArg, printf)

import Cardano.Slotting.Slot (EpochNo(..), SlotNo(..))
import Ouroboros.Network.Block (BlockNo(..))

import Cardano.Analysis.ChainFilter
import Cardano.Analysis.Profile
import Cardano.Logging.Resources.Types
import Cardano.Unlog.LogObject hiding (Text)
import Cardano.Unlog.Render
import Cardano.Unlog.SlotStats

import Data.Distribution

Expand Down Expand Up @@ -130,14 +132,66 @@ data BPErrorKind

data DataDomain
= DataDomain
{ ddRawSlotFirst :: SlotNo
, ddRawSlotLast :: SlotNo
, ddAnalysisSlotFirst :: SlotNo
, ddAnalysisSlotLast :: SlotNo
{ ddRawSlotFirst :: !SlotNo
, ddRawSlotLast :: !SlotNo
, ddAnalysisSlotFirst :: !SlotNo
, ddAnalysisSlotLast :: !SlotNo
}
deriving (Generic, Show, ToJSON)
-- Perhaps: Plutus.V1.Ledger.Slot.SlotRange = Interval Slot

-- | The top-level representation of the machine timeline analysis results.
data MachTimeline
= MachTimeline
{ sSlotRange :: (SlotNo, SlotNo) -- ^ Analysis range, inclusive.
, sMaxChecks :: !Word64
, sSlotMisses :: ![Word64]
, sSpanLensCPU85 :: ![Int]
, sSpanLensCPU85EBnd :: ![Int]
, sSpanLensCPU85Rwd :: ![Int]
-- distributions
, sMissDistrib :: !(Distribution Float Float)
, sLeadsDistrib :: !(Distribution Float Word64)
, sUtxoDistrib :: !(Distribution Float Word64)
, sDensityDistrib :: !(Distribution Float Float)
, sSpanCheckDistrib :: !(Distribution Float NominalDiffTime)
, sSpanLeadDistrib :: !(Distribution Float NominalDiffTime)
, sBlocklessDistrib :: !(Distribution Float Word64)
, sSpanLensCPU85Distrib
:: !(Distribution Float Int)
, sSpanLensCPU85EBndDistrib :: !(Distribution Float Int)
, sSpanLensCPU85RwdDistrib :: !(Distribution Float Int)
, sResourceDistribs :: !(Resources (Distribution Float Word64))
}
deriving (Generic, Show, ToJSON)

data SlotStats
= SlotStats
{ slSlot :: !SlotNo
, slEpoch :: !Word64
, slEpochSlot :: !Word64
, slStart :: !SlotStart
, slCountChecks :: !Word64
, slCountLeads :: !Word64
, slChainDBSnap :: !Word64
, slRejectedTx :: !Word64
, slBlockNo :: !Word64
, slBlockless :: !Word64
, slOrderViol :: !Word64
, slEarliest :: !UTCTime
, slSpanCheck :: !NominalDiffTime
, slSpanLead :: !NominalDiffTime
, slMempoolTxs :: !Word64
, slTxsMemSpan :: !(Maybe NominalDiffTime)
, slTxsCollected :: !Word64
, slTxsAccepted :: !Word64
, slTxsRejected :: !Word64
, slUtxoSize :: !Word64
, slDensity :: !Float
, slResources :: !(Resources (Maybe Word64))
}
deriving (Generic, Show, ToJSON)

--
-- * Key properties
--
Expand Down Expand Up @@ -171,8 +225,17 @@ isValidBlockObservation BlockObservation{..} =
-- 2. All timings account for processing of a single block
boChainDelta == 1

testSlotStats :: Profile -> SlotStats -> SlotCond -> Bool
testSlotStats Profile{genesis=GenesisProfile{}}
SlotStats{..} = \case
SlotGEq s -> slSlot >= s
SlotLEq s -> slSlot <= s
EpochGEq s -> fromIntegral slEpoch >= s
EpochLEq s -> fromIntegral slEpoch <= s
SlotHasLeaders -> slCountLeads > 0

--
-- * Instances
-- * Timeline rendering instances
--
instance RenderDistributions BlockPropagation where
rdFields _ =
Expand Down Expand Up @@ -271,3 +334,66 @@ instance RenderTimeline BlockEvents where
bpeIsNegative _ _ = False

rtCommentary BlockEvents{..} = (" " <>) . show <$> beErrors

instance RenderTimeline SlotStats where
rtFields _ =
-- Width LeftPad
[ Field 5 0 "abs.slot" "abs." "slot#" $ IWord64 (unSlotNo . slSlot)
, Field 4 0 "slot" " epo" "slot" $ IWord64 slEpochSlot
, Field 2 0 "epoch" "ch " "#" $ IWord64 slEpoch
, Field 5 0 "block" "block" "no." $ IWord64 slBlockNo
, Field 5 0 "blockGap" "block" "gap" $ IWord64 slBlockless
, Field 3 0 "leadChecks" "lead" "chk" $ IWord64 slCountChecks
, Field 3 0 "leadShips" "ship" "win" $ IWord64 slCountLeads
, Field 4 0 "CDBSnap" "CDB" "snap" $ IWord64 slChainDBSnap
, Field 3 0 "rejTxs" "rej" "txs" $ IWord64 slRejectedTx
, Field 7 0 "checkSpan" "check" "span" $ IDeltaT slSpanCheck
, Field 5 0 "leadSpan" "lead" "span" $ IDeltaT slSpanLead
, Field 4 0 "mempoolTxSpan" (t 4!!0) "span" $ IText (maybe "" show.slTxsMemSpan)
, Field 4 0 "txsColl" (t 4!!1) "cold" $ IWord64 slTxsCollected
, Field 4 0 "txsAcc" (t 4!!2) "accd" $ IWord64 slTxsAccepted
, Field 4 0 "txsRej" (t 4!!3) "rejd" $ IWord64 slTxsRejected
, Field 5 1 "chDensity" "chain" "dens." $ IFloat slDensity
, Field 3 0 "CPU%" (c 3!!0) "all" $ IText (d 3.rCentiCpu.slResources)
, Field 3 0 "GC%" (c 3!!1) "GC" $ IText (d 3.fmap (min 999).rCentiGC.slResources)
, Field 3 0 "MUT%" (c 3!!2) "mut" $ IText (d 3.fmap (min 999).rCentiMut.slResources)
, Field 3 0 "majFlt" (g 3!!0) "maj" $ IText (d 3.rGcsMajor.slResources)
, Field 3 0 "minFlt" (g 3!!1) "min" $ IText (d 3.rGcsMinor.slResources)
, 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 <$> 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)
, Field 5 0 "liveMB" (m 5!!2) "Live" $ IText (d 5.rLive .slResources)
, Field 5 0 "allocatedMB" "Allocd" "MB" $ IText (d 5.rAlloc.slResources)
, Field 6 0 "allocMut" "Alloc/" "mutSec" $ IText
(\SlotStats{..}->
d 5 $
(ceiling :: Float -> Int)
<$> ((/) <$> (fromIntegral . (100 *) <$> rAlloc slResources)
<*> (fromIntegral . max 1 . (1024 *) <$> rCentiMut slResources)))
, Field 7 0 "mempoolTxs" "Mempool" "txs" $ IWord64 slMempoolTxs
, Field 9 0 "utxoEntries" "UTxO" "entries" $ IWord64 slUtxoSize
, Field 10 0 "absSlotTime" "Absolute" "slot time" $ IText
(\SlotStats{..}->
T.pack $ " " `splitOn` show slStart !! 1)
]
where
t w = nChunksEachOf 4 (w + 1) "mempool tx"
c w = nChunksEachOf 3 (w + 1) "%CPU"
g w = nChunksEachOf 2 (w + 1) "GCs"
m w = nChunksEachOf 3 (w + 1) "Memory use, MB"

d, f :: PrintfArg a => Int -> Maybe a -> Text
d width = \case
Just x -> T.pack $ printf ("%"<>"" --(if exportMode then "0" else "")
<>show width<>"d") x
Nothing -> mconcat (replicate width "-")
f width = \case
Just x -> T.pack $ printf ("%0."<>show width<>"f") x
Nothing -> mconcat (replicate width "-")

calcProd :: Float -> Float -> Float
calcProd mut' cpu' = if cpu' == 0 then 1 else mut' / cpu'
1 change: 0 additions & 1 deletion bench/locli/src/Cardano/Analysis/BlockProp.hs
Expand Up @@ -55,7 +55,6 @@ import Cardano.Analysis.Profile
import Cardano.Unlog.LogObject hiding (Text)
import Cardano.Unlog.Render
import Cardano.Unlog.Resources
import Cardano.Unlog.SlotStats


-- | Block's events, as seen by its forger.
Expand Down
29 changes: 20 additions & 9 deletions bench/locli/src/Cardano/Analysis/ChainFilter.hs
Expand Up @@ -3,15 +3,16 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-deprecations -Wno-orphans #-}
{- HLINT ignore "Use head" -}
module Cardano.Analysis.ChainFilter (module Cardano.Analysis.ChainFilter) where

import Cardano.Prelude hiding (head)
import Cardano.Prelude hiding (head)

import Data.Aeson
import Data.Aeson

import Cardano.Unlog.SlotStats
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..))


-- | Conditions for chain subsetting
Expand All @@ -22,13 +23,23 @@ data ChainFilter

-- | Block classification -- primary for validity as subjects of analysis.
data BlockCond
= BUnitaryChainDelta -- ^ All timings account for processing of a single block.
| BFullnessGEq Double -- ^ Block fullness is above fraction.
| BFullnessLEq Double -- ^ Block fullness is below fraction.
| BSizeGEq Word64
| BSizeLEq Word64
= BUnitaryChainDelta -- ^ All timings account for
-- processing of a single block.
| BFullnessGEq Double -- ^ Block fullness is above fraction.
| BFullnessLEq Double -- ^ Block fullness is below fraction.
| BSizeGEq Word64
| BSizeLEq Word64
deriving (FromJSON, Generic, NFData, Show, ToJSON)

deriving instance NFData EpochNo

data SlotCond
= SlotGEq SlotNo
| SlotLEq SlotNo
| EpochGEq EpochNo
| EpochLEq EpochNo
| SlotHasLeaders
deriving (FromJSON, Generic, NFData, Show, ToJSON)

cfIsSlotCond, cfIsBlockCond :: ChainFilter -> Bool
cfIsSlotCond = \case { CSlot{} -> True; _ -> False; }
Expand Down
1 change: 0 additions & 1 deletion bench/locli/src/Cardano/Analysis/Driver.hs
Expand Up @@ -39,7 +39,6 @@ import Cardano.Analysis.Profile
import Cardano.Unlog.Commands
import Cardano.Unlog.LogObject hiding (Text)
import Cardano.Unlog.Render
import Cardano.Unlog.SlotStats


data AnalysisCmdError
Expand Down
87 changes: 43 additions & 44 deletions bench/locli/src/Cardano/Analysis/MachTimeline.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
Expand All @@ -10,53 +9,27 @@
{- HLINT ignore "Use head" -}
module Cardano.Analysis.MachTimeline (module Cardano.Analysis.MachTimeline) where

import Prelude (String, (!!), error, head, last)
import Cardano.Prelude hiding (head)
import Prelude (String, (!!), error, head, last)
import Cardano.Prelude hiding (head)

import Control.Arrow ((&&&), (***))
import Data.Aeson
import Data.Vector (Vector)
import qualified Data.Vector as Vec
import qualified Data.Map.Strict as Map
import Control.Arrow ((&&&), (***))
import Data.Vector (Vector)
import Data.Vector qualified as Vec
import Data.Map.Strict qualified as Map

import Data.Time.Clock (NominalDiffTime, UTCTime)
import qualified Data.Time.Clock as Time
import Data.Time.Clock (NominalDiffTime, UTCTime)
import Data.Time.Clock qualified as Time

import Ouroboros.Network.Block (SlotNo(..))
import Ouroboros.Network.Block (SlotNo(..))

import Data.Accum
import Data.Distribution
import Data.Accum
import Data.Distribution

import Cardano.Analysis.Profile
import Cardano.Unlog.LogObject hiding (Text)
import Cardano.Unlog.Render
import Cardano.Unlog.Resources
import Cardano.Unlog.SlotStats

-- | The top-level representation of the machine timeline analysis results.
data MachTimeline
= MachTimeline
{ sSlotRange :: (SlotNo, SlotNo) -- ^ Analysis range, inclusive.
, sMaxChecks :: !Word64
, sSlotMisses :: ![Word64]
, sSpanLensCPU85 :: ![Int]
, sSpanLensCPU85EBnd :: ![Int]
, sSpanLensCPU85Rwd :: ![Int]
-- distributions
, sMissDistrib :: !(Distribution Float Float)
, sLeadsDistrib :: !(Distribution Float Word64)
, sUtxoDistrib :: !(Distribution Float Word64)
, sDensityDistrib :: !(Distribution Float Float)
, sSpanCheckDistrib :: !(Distribution Float NominalDiffTime)
, sSpanLeadDistrib :: !(Distribution Float NominalDiffTime)
, sBlocklessDistrib :: !(Distribution Float Word64)
, sSpanLensCPU85Distrib
:: !(Distribution Float Int)
, sSpanLensCPU85EBndDistrib :: !(Distribution Float Int)
, sSpanLensCPU85RwdDistrib :: !(Distribution Float Int)
, sResourceDistribs :: !(Resources (Distribution Float Word64))
}
deriving (Generic, Show, ToJSON)
import Cardano.Analysis.API
import Cardano.Analysis.Profile
import Cardano.Unlog.LogObject hiding (Text)
import Cardano.Unlog.Render
import Cardano.Unlog.Resources

instance RenderDistributions MachTimeline where
rdFields _ =
Expand Down Expand Up @@ -194,6 +167,32 @@ timelineFromLogObjects ci =
}
zeroRunScalars :: RunScalars
zeroRunScalars = RunScalars Nothing Nothing Nothing
zeroSlotStats :: SlotStats
zeroSlotStats =
SlotStats
{ slSlot = 0
, slEpoch = 0
, slEpochSlot = 0
, slStart = SlotStart zeroUTCTime
, slCountChecks = 0
, slCountLeads = 0
, slOrderViol = 0
, slEarliest = zeroUTCTime
, slSpanCheck = realToFrac (0 :: Int)
, slSpanLead = realToFrac (0 :: Int)
, slMempoolTxs = 0
, slTxsMemSpan = Nothing
, slTxsCollected = 0
, slTxsAccepted = 0
, slTxsRejected = 0
, slUtxoSize = 0
, slDensity = 0
, slResources = pure Nothing
, slChainDBSnap = 0
, slRejectedTx = 0
, slBlockNo = 0
, slBlockless = 0
}

timelineStep :: ChainInfo -> TimelineAccum -> LogObject -> TimelineAccum
timelineStep ci a@TimelineAccum{aSlotStats=cur:rSLs, ..} = \case
Expand Down
4 changes: 2 additions & 2 deletions bench/locli/src/Cardano/Analysis/Profile.hs
Expand Up @@ -11,8 +11,8 @@
{-# OPTIONS_GHC -Wno-incomplete-patterns -Wno-name-shadowing #-}
module Cardano.Analysis.Profile (module Cardano.Analysis.Profile) where

import Prelude (String)
import Cardano.Prelude
import Prelude (String)
import Cardano.Prelude

import Data.Aeson.Types qualified as Aeson
import Data.Aeson (FromJSON(..), Object, ToJSON(..), withObject, (.:))
Expand Down

0 comments on commit 82c8eba

Please sign in to comment.