Skip to content

Commit 06fc91f

Browse files
committed
bench: cardano-recon-framework configurable timeunits in formulas
1 parent 126efd5 commit 06fc91f

4 files changed

Lines changed: 57 additions & 9 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for cardano-trace-ltl
22

3+
## 1.1.0 -- March 2026
4+
5+
* Support configurable timeunits in formulas via a CLI option.
6+
37
## 1.0.0 -- Feb 2026
48

59
* First version.

bench/cardano-recon-framework/app/Cardano/ReCon.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Cardano.Logging
77
import Cardano.Logging.Prometheus.TCPServer (TracePrometheusSimple (..),
88
runPrometheusSimple)
99
import Cardano.Logging.Types.TraceMessage (TraceMessage (..))
10-
import Cardano.ReCon.Cli (CliOptions (..), Mode (..), opts)
10+
import Cardano.ReCon.Cli (CliOptions (..), Mode (..), opts, timeunitToMicrosecond)
1111
import Cardano.ReCon.Common (extractProps)
1212
import Cardano.ReCon.LTL.Check (checkFormula, prettyError)
1313
import Cardano.ReCon.LTL.Lang.Formula
@@ -37,13 +37,13 @@ import Data.Maybe (fromMaybe, isJust, listToMaybe)
3737
import Data.Text (Text, unpack)
3838
import qualified Data.Text as Text
3939
import Data.Traversable (for)
40+
import GHC.IO.Encoding (setLocaleEncoding, utf8)
4041
import Network.HostName (HostName)
4142
import Network.Socket (PortNumber)
4243
import Options.Applicative hiding (Success)
4344
import System.Exit (die)
4445
import qualified System.Metrics as EKG
4546

46-
import GHC.IO.Encoding (setLocaleEncoding, utf8)
4747
import Streaming
4848

4949

@@ -107,10 +107,6 @@ checkOffline tr eventDuration file phis = do
107107
check idx tr phi events
108108
threadDelay 200_000 -- Give the tracer a grace period to output the logs to whatever backend
109109

110-
-- | Convert time unit used in the yaml (currently second) input to μs.
111-
unitToMicrosecond :: Word -> Word
112-
unitToMicrosecond = (1_000_000 *)
113-
114110
setupTraceDispatcher :: Maybe FilePath -> IO (Trace IO App.TraceMessage)
115111
setupTraceDispatcher optTraceDispatcherConfigFile = do
116112
stdTr <- standardTracer
@@ -164,7 +160,7 @@ main = do
164160
<> " is syntactically invalid:\n"
165161
<> Text.unlines (fmap (("" <>) . prettyError) (e : es))
166162
(_, []) -> pure ()
167-
let formulas' = fmap (interpTimeunit (\u -> unitToMicrosecond u `div` fromIntegral options.duration)) formulas
163+
let formulas' = fmap (interpTimeunit (\u -> timeunitToMicrosecond options.timeunit u `div` fromIntegral options.duration)) formulas
168164
tr <- setupTraceDispatcher options.traceDispatcherCfg
169165
case options.mode of
170166
Offline -> do

bench/cardano-recon-framework/app/Cardano/ReCon/Cli.hs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Cardano.ReCon.Cli(Mode(..), CliOptions(..), opts) where
1+
module Cardano.ReCon.Cli(Timeunit(..), timeunitToMicrosecond, Mode(..), CliOptions(..), opts) where
22

33

44
import Control.Arrow ((>>>))
@@ -20,6 +20,7 @@ readMode = eitherReader $ \case
2020
"online" -> Right Online
2121
_ -> Left "Expected either of: 'offline' or 'online'"
2222

23+
2324
readBool :: ReadM Bool
2425
readBool = eitherReader $ fmap toLower >>> \case
2526
"true" -> Right True
@@ -31,6 +32,51 @@ readBool = eitherReader $ fmap toLower >>> \case
3132
parseMode :: Parser Mode
3233
parseMode = option readMode (long "mode" <> metavar "<offline|online>" <> help "mode")
3334

35+
data Timeunit = Hour | Minute | Second | Millisecond | Microsecond deriving (Ord, Eq)
36+
37+
-- | Convert `Timeunit` to μs.
38+
timeunitToMicrosecond :: Timeunit -> Word -> Word
39+
timeunitToMicrosecond Hour = (3_600_000_000 *)
40+
timeunitToMicrosecond Minute = (60_000_000 *)
41+
timeunitToMicrosecond Second = (1_000_000 *)
42+
timeunitToMicrosecond Millisecond = (1_000 *)
43+
timeunitToMicrosecond Microsecond = id
44+
45+
instance Show Timeunit where
46+
show Hour = "hour"
47+
show Minute = "minute"
48+
show Second = "second"
49+
show Millisecond = "millisecond"
50+
show Microsecond = "microsecond"
51+
52+
readTimeunit :: ReadM Timeunit
53+
readTimeunit = eitherReader $ fmap toLower >>> \case
54+
"hour" -> Right Hour
55+
"h" -> Right Hour
56+
"minute" -> Right Minute
57+
"min" -> Right Minute
58+
"m" -> Right Minute
59+
"second" -> Right Second
60+
"sec" -> Right Second
61+
"s" -> Right Second
62+
"millisecond" -> Right Millisecond
63+
"millisec" -> Right Millisecond
64+
"millis" -> Right Millisecond
65+
"ms" -> Right Millisecond
66+
"microsecond" -> Right Microsecond
67+
"microsec" -> Right Microsecond
68+
"micros" -> Right Microsecond
69+
"μs" -> Right Microsecond
70+
_ -> Left "Can't read a Timeunit"
71+
72+
parseTimeunit :: Parser Timeunit
73+
parseTimeunit = option readTimeunit $
74+
long "timeunit"
75+
<> metavar "<hour|minute|second|millisecond|microsecond>"
76+
<> showDefault
77+
<> value Second
78+
<> help "timeunit"
79+
3480
parseEventDuration :: Parser Word
3581
parseEventDuration = option auto (long "duration" <> metavar "INT" <> help "temporal event duration (μs)")
3682

@@ -82,6 +128,7 @@ data CliOptions = CliOptions
82128
, context :: Maybe FilePath
83129
, enableProgressDumps :: Bool
84130
, enableSeekToEnd :: Bool
131+
, timeunit :: Timeunit
85132
}
86133

87134
parseCliOptions :: Parser CliOptions
@@ -95,6 +142,7 @@ parseCliOptions = CliOptions
95142
<*> parseContext
96143
<*> parseDumpMetrics
97144
<*> parseSeekToEnd
145+
<*> parseTimeunit
98146

99147
opts :: ParserInfo CliOptions
100148
opts = info (parseCliOptions <**> helper)

bench/cardano-recon-framework/cardano-recon-framework.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Cardano Re(altime) Con(formance) Framework based on Linear T
44
category: Cardano
55
Testing
66
copyright: 2026 Intersect.
7-
version: 1.0.0
7+
version: 1.1.0
88
license: Apache-2.0
99
license-files: LICENSE
1010
NOTICE

0 commit comments

Comments
 (0)