Skip to content

Commit

Permalink
locli: Summary analysis; tons more metrics; better reports; cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Nov 25, 2022
1 parent 5d8f0dd commit 9110079
Show file tree
Hide file tree
Showing 25 changed files with 1,063 additions and 653 deletions.
1 change: 1 addition & 0 deletions bench/locli/locli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ library
, extra
, file-embed
, filepath
, fingertree
, ghc
, gnuplot
, iohk-monitoring
Expand Down
4 changes: 3 additions & 1 deletion bench/locli/src/Cardano/Analysis/API.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Cardano.Analysis.API
( module Cardano.Analysis.API.Chain
( module Data.CDF
, module Cardano.Analysis.API.Chain
, module Cardano.Analysis.API.ChainFilter
, module Cardano.Analysis.API.Context
, module Cardano.Analysis.API.Dictionary
Expand All @@ -12,6 +13,7 @@ module Cardano.Analysis.API
)
where

import Data.CDF
import Cardano.Analysis.API.Chain
import Cardano.Analysis.API.ChainFilter
import Cardano.Analysis.API.Context
Expand Down
54 changes: 45 additions & 9 deletions bench/locli/src/Cardano/Analysis/API/Field.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Data.Text (unpack)
import Cardano.JSON
import Cardano.Util
import Cardano.Analysis.API.Ground
import Cardano.Analysis.API.Run


data Scale
Expand All @@ -23,6 +22,7 @@ data Range
= Free -- No range restriction
| Z0 Int -- 1-based range
| Z1 Int -- 1-based range
| R01
deriving (Eq, Show)

data Unit
Expand All @@ -33,6 +33,7 @@ data Unit
| MB -- Mibibyte: 2^20
| KBs -- Kibibyte/s
| MBs -- Mibibyte/s
| Era -- Era
| Epo -- Epoch
| Slo -- Slots
| Blk -- Blocks
Expand All @@ -41,10 +42,16 @@ data Unit
| Sig -- Sign: +/-
| Pct -- Unspecified ratio, percents
| Ev -- Events
| KEv -- Events: 10^3
| Dat -- Date
| Tim -- Time
| Ver -- Version
| Ix -- Unspecified index
| Len -- Unspecified length
| Cnt -- Unspecified count
| Rto -- Unspecified ratio
| Uni -- Unspecified unit
| Id -- Unspefified identifier
deriving (Eq, Show)

renderUnit :: Unit -> Text
Expand All @@ -56,21 +63,28 @@ renderUnit = \case
MB -> "MB"
KBs -> "KB/s"
MBs -> "MB/s"
Era -> "era"
Epo -> "epoch"
Slo -> "slots"
Blk -> "blocks"
Hsh -> "hash"
Hos -> "host"
Sig -> "+/-"
Pct -> "%"
Ev -> ""
Ix -> ""
Len -> ""
Rto -> ""
Uni -> ""
Ev -> "#"
KEv -> "#"
Dat -> "on"
Tim -> "at"
Ver -> "v"
Ix -> "[]"
Len -> "#"
Cnt -> "#"
Rto -> "/"
Uni -> "#"
Id -> ""

data Width
= W0
= Wno
| W1
| W2
| W3
Expand All @@ -83,6 +97,15 @@ data Width
| W10
| W11
| W12
| W13
| W14
| W15
| W16
| W17
| W18
| W19
| W20
| W21
deriving (Eq, Enum, Ord, Show)

data Precision
Expand All @@ -94,7 +117,8 @@ data Precision

{-# INLINE width #-}
width :: Width -> Int
width = fromEnum
width Wno = 80
width x = fromEnum x

-- | Encapsulate all metadata about a metric (a projection) of
-- a certain projectible (a kind of analysis results):
Expand Down Expand Up @@ -122,10 +146,14 @@ class CDFFields a p where

class TimelineFields a where
data TimelineComments a :: Type
timelineFields :: Run -> [Field ISelect I a]
timelineFields :: [Field ISelect I a]
rtCommentary :: a -> TimelineComments a -> [Text]
rtCommentary _ _ = []

data FSelect where
ISel :: TimelineFields a => (Field ISelect I a -> Bool) -> FSelect
DSel :: CDFFields a p => (Field DSelect p a -> Bool) -> FSelect

data DSelect p a
= DInt (a p -> CDF p Int)
| DWord64 (a p -> CDF p Word64)
Expand All @@ -139,8 +167,16 @@ data ISelect p a
| IFloat (a -> Double)
| IDeltaT (a -> NominalDiffTime)
| IDeltaTM (a -> SMaybe NominalDiffTime)
| IDate (a -> UTCTime)
| ITime (a -> UTCTime)
| IText (a -> Text)

dFields :: [FieldName] -> Field DSelect p a -> Bool
dFields fs Field{fId} = FieldName fId `elem` fs

iFields :: [FieldName] -> Field ISelect I a -> Bool
iFields fs Field{fId} = FieldName fId `elem` fs

filterFields :: CDFFields a p
=> (Field DSelect p a -> Bool) -> [Field DSelect p a]
filterFields f = filter f cdfFields
Expand Down
20 changes: 16 additions & 4 deletions bench/locli/src/Cardano/Analysis/API/Ground.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ import Data.DataDomain
import Cardano.Util


newtype FieldName = FieldName { unFieldName :: Text }
deriving (Eq, Generic, Ord)
deriving newtype (FromJSON, IsString, ToJSON)
deriving anyclass NFData
deriving Show via Quiet FieldName

newtype TId = TId { unTId :: ShortText }
deriving (Eq, Generic, Ord)
deriving newtype (FromJSON, ToJSON)
Expand All @@ -60,11 +66,17 @@ newtype Count a = Count { unCount :: Int }
deriving newtype (FromJSON, Num, ToJSON)
deriving anyclass NFData

countOfList :: [a] -> Count a
countOfList = Count . fromIntegral . length
countList :: (a -> Bool) -> [a] -> Count a
countList f = Count . fromIntegral . count f

countLists :: (a -> Bool) -> [[a]] -> Count a
countLists f = Count . fromIntegral . sum . fmap (count f)

countListAll :: [a] -> Count a
countListAll = Count . fromIntegral . length

countOfLists :: [[a]] -> Count a
countOfLists = Count . fromIntegral . sum . fmap length
countListsAll :: [[a]] -> Count a
countListsAll = Count . fromIntegral . sum . fmap length

unsafeCoerceCount :: Count a -> Count b
unsafeCoerceCount = Unsafe.unsafeCoerce
Expand Down
Loading

0 comments on commit 9110079

Please sign in to comment.