Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bench/cardano-recon-framework/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 3 additions & 7 deletions bench/cardano-recon-framework/app/Cardano/ReCon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 49 additions & 1 deletion bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs
Original file line number Diff line number Diff line change
@@ -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 ((>>>))
Expand All @@ -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
Expand All @@ -31,6 +32,51 @@ readBool = eitherReader $ fmap toLower >>> \case
parseMode :: Parser Mode
parseMode = option readMode (long "mode" <> metavar "<offline|online>" <> 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 "<hour|minute|second|millisecond|microsecond>"
<> showDefault
<> value Second
<> help "timeunit"

parseEventDuration :: Parser Word
parseEventDuration = option auto (long "duration" <> metavar "INT" <> help "temporal event duration (μs)")

Expand Down Expand Up @@ -82,6 +128,7 @@ data CliOptions = CliOptions
, context :: Maybe FilePath
, enableProgressDumps :: Bool
, enableSeekToEnd :: Bool
, timeunit :: Timeunit
}

parseCliOptions :: Parser CliOptions
Expand All @@ -95,6 +142,7 @@ parseCliOptions = CliOptions
<*> parseContext
<*> parseDumpMetrics
<*> parseSeekToEnd
<*> parseTimeunit

opts :: ParserInfo CliOptions
opts = info (parseCliOptions <**> helper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading