From 06fc91f0bd8be482ea97ad22dfe3870d5ff617ca Mon Sep 17 00:00:00 2001 From: Russoul Date: Fri, 13 Mar 2026 15:14:59 +0300 Subject: [PATCH] bench: cardano-recon-framework configurable timeunits in formulas --- bench/cardano-recon-framework/CHANGELOG.md | 4 ++ .../app/Cardano/ReCon.hs | 10 ++-- .../app/Cardano/ReCon/Cli.hs | 50 ++++++++++++++++++- .../cardano-recon-framework.cabal | 2 +- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/bench/cardano-recon-framework/CHANGELOG.md b/bench/cardano-recon-framework/CHANGELOG.md index d8a905440ba..b8e29f7b0e7 100644 --- a/bench/cardano-recon-framework/CHANGELOG.md +++ b/bench/cardano-recon-framework/CHANGELOG.md @@ -1,5 +1,9 @@ # Revision history for cardano-trace-ltl +## 1.1.0 -- March 2026 + +* Support configurable timeunits in formulas via a CLI option. + ## 1.0.0 -- Feb 2026 * First version. diff --git a/bench/cardano-recon-framework/app/Cardano/ReCon.hs b/bench/cardano-recon-framework/app/Cardano/ReCon.hs index a3d10111ba2..fc0244334de 100644 --- a/bench/cardano-recon-framework/app/Cardano/ReCon.hs +++ b/bench/cardano-recon-framework/app/Cardano/ReCon.hs @@ -7,7 +7,7 @@ import Cardano.Logging import Cardano.Logging.Prometheus.TCPServer (TracePrometheusSimple (..), runPrometheusSimple) import Cardano.Logging.Types.TraceMessage (TraceMessage (..)) -import Cardano.ReCon.Cli (CliOptions (..), Mode (..), opts) +import Cardano.ReCon.Cli (CliOptions (..), Mode (..), opts, timeunitToMicrosecond) import Cardano.ReCon.Common (extractProps) import Cardano.ReCon.LTL.Check (checkFormula, prettyError) import Cardano.ReCon.LTL.Lang.Formula @@ -37,13 +37,13 @@ import Data.Maybe (fromMaybe, isJust, listToMaybe) import Data.Text (Text, unpack) import qualified Data.Text as Text import Data.Traversable (for) +import GHC.IO.Encoding (setLocaleEncoding, utf8) import Network.HostName (HostName) import Network.Socket (PortNumber) import Options.Applicative hiding (Success) import System.Exit (die) import qualified System.Metrics as EKG -import GHC.IO.Encoding (setLocaleEncoding, utf8) import Streaming @@ -107,10 +107,6 @@ checkOffline tr eventDuration file phis = do check idx tr phi events threadDelay 200_000 -- Give the tracer a grace period to output the logs to whatever backend --- | Convert time unit used in the yaml (currently second) input to μs. -unitToMicrosecond :: Word -> Word -unitToMicrosecond = (1_000_000 *) - setupTraceDispatcher :: Maybe FilePath -> IO (Trace IO App.TraceMessage) setupTraceDispatcher optTraceDispatcherConfigFile = do stdTr <- standardTracer @@ -164,7 +160,7 @@ main = do <> " is syntactically invalid:\n" <> Text.unlines (fmap (("— " <>) . prettyError) (e : es)) (_, []) -> pure () - let formulas' = fmap (interpTimeunit (\u -> unitToMicrosecond u `div` fromIntegral options.duration)) formulas + let formulas' = fmap (interpTimeunit (\u -> timeunitToMicrosecond options.timeunit u `div` fromIntegral options.duration)) formulas tr <- setupTraceDispatcher options.traceDispatcherCfg case options.mode of Offline -> do diff --git a/bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs b/bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs index 86e725b31ea..4f68f2becd2 100644 --- a/bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs +++ b/bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs @@ -1,4 +1,4 @@ -module Cardano.ReCon.Cli(Mode(..), CliOptions(..), opts) where +module Cardano.ReCon.Cli(Timeunit(..), timeunitToMicrosecond, Mode(..), CliOptions(..), opts) where import Control.Arrow ((>>>)) @@ -20,6 +20,7 @@ readMode = eitherReader $ \case "online" -> Right Online _ -> Left "Expected either of: 'offline' or 'online'" + readBool :: ReadM Bool readBool = eitherReader $ fmap toLower >>> \case "true" -> Right True @@ -31,6 +32,51 @@ readBool = eitherReader $ fmap toLower >>> \case parseMode :: Parser Mode parseMode = option readMode (long "mode" <> metavar "" <> help "mode") +data Timeunit = Hour | Minute | Second | Millisecond | Microsecond deriving (Ord, Eq) + +-- | Convert `Timeunit` to μs. +timeunitToMicrosecond :: Timeunit -> Word -> Word +timeunitToMicrosecond Hour = (3_600_000_000 *) +timeunitToMicrosecond Minute = (60_000_000 *) +timeunitToMicrosecond Second = (1_000_000 *) +timeunitToMicrosecond Millisecond = (1_000 *) +timeunitToMicrosecond Microsecond = id + +instance Show Timeunit where + show Hour = "hour" + show Minute = "minute" + show Second = "second" + show Millisecond = "millisecond" + show Microsecond = "microsecond" + +readTimeunit :: ReadM Timeunit +readTimeunit = eitherReader $ fmap toLower >>> \case + "hour" -> Right Hour + "h" -> Right Hour + "minute" -> Right Minute + "min" -> Right Minute + "m" -> Right Minute + "second" -> Right Second + "sec" -> Right Second + "s" -> Right Second + "millisecond" -> Right Millisecond + "millisec" -> Right Millisecond + "millis" -> Right Millisecond + "ms" -> Right Millisecond + "microsecond" -> Right Microsecond + "microsec" -> Right Microsecond + "micros" -> Right Microsecond + "μs" -> Right Microsecond + _ -> Left "Can't read a Timeunit" + +parseTimeunit :: Parser Timeunit +parseTimeunit = option readTimeunit $ + long "timeunit" + <> metavar "" + <> showDefault + <> value Second + <> help "timeunit" + parseEventDuration :: Parser Word parseEventDuration = option auto (long "duration" <> metavar "INT" <> help "temporal event duration (μs)") @@ -82,6 +128,7 @@ data CliOptions = CliOptions , context :: Maybe FilePath , enableProgressDumps :: Bool , enableSeekToEnd :: Bool + , timeunit :: Timeunit } parseCliOptions :: Parser CliOptions @@ -95,6 +142,7 @@ parseCliOptions = CliOptions <*> parseContext <*> parseDumpMetrics <*> parseSeekToEnd + <*> parseTimeunit opts :: ParserInfo CliOptions opts = info (parseCliOptions <**> helper) diff --git a/bench/cardano-recon-framework/cardano-recon-framework.cabal b/bench/cardano-recon-framework/cardano-recon-framework.cabal index 6c729ec13d2..9090f66e306 100644 --- a/bench/cardano-recon-framework/cardano-recon-framework.cabal +++ b/bench/cardano-recon-framework/cardano-recon-framework.cabal @@ -4,7 +4,7 @@ description: Cardano Re(altime) Con(formance) Framework based on Linear T category: Cardano Testing copyright: 2026 Intersect. -version: 1.0.0 +version: 1.1.0 license: Apache-2.0 license-files: LICENSE NOTICE