Skip to content

Commit ecd1167

Browse files
committed
refactor log options into their own type
1 parent d4ceaae commit ecd1167

File tree

5 files changed

+83
-52
lines changed

5 files changed

+83
-52
lines changed

booster/library/Booster/CLOptions.hs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Booster.CLOptions (
77
CLOptions (..),
88
EquationOptions (..),
99
LogFormat (..),
10+
LogOptions (..),
1011
RewriteOptions (..),
1112
TimestampFormat (..),
1213
clOptionsParser,
@@ -43,25 +44,23 @@ data CLOptions = CLOptions
4344
, mainModuleName :: Text
4445
, llvmLibraryFile :: Maybe FilePath
4546
, port :: Int
46-
, logLevels :: [LogLevel]
47+
, logOptions :: LogOptions
48+
, smtOptions :: Maybe SMTOptions
49+
, equationOptions :: EquationOptions
50+
, rewriteOptions :: RewriteOptions
51+
}
52+
deriving stock (Show)
53+
54+
data LogOptions = LogOptions
55+
{ logLevels :: [LogLevel]
4756
, logTimeStamps :: Bool
4857
, timeStampsFormat :: TimestampFormat
4958
, logFormat :: LogFormat
5059
, logContexts :: [ContextFilter]
5160
, logFile :: Maybe FilePath
52-
, smtOptions :: Maybe SMTOptions
53-
, equationOptions :: EquationOptions
54-
, rewriteOptions :: RewriteOptions
5561
, prettyPrintOptions :: [ModifierT]
5662
}
57-
deriving (Show)
58-
59-
60-
data RewriteOptions = RewriteOptions
61-
{ indexCells :: [Text]
62-
, interimSimplification :: Maybe Natural
63-
}
64-
deriving stock (Show, Eq)
63+
deriving stock (Show)
6564

6665
data LogFormat
6766
= Standard
@@ -85,6 +84,12 @@ instance Show TimestampFormat where
8584
Pretty -> "pretty"
8685
Nanoseconds -> "nanoseconds"
8786

87+
data RewriteOptions = RewriteOptions
88+
{ indexCells :: [Text]
89+
, interimSimplification :: Maybe Natural
90+
}
91+
deriving stock (Show, Eq)
92+
8893
clOptionsParser :: Parser CLOptions
8994
clOptionsParser =
9095
CLOptions
@@ -112,7 +117,15 @@ clOptionsParser =
112117
<> help "Port for the RPC server to bind to"
113118
<> showDefault
114119
)
115-
<*> many
120+
<*> parseLogOptions
121+
<*> parseSMTOptions
122+
<*> parseEquationOptions
123+
<*> parseRewriteOptions
124+
125+
parseLogOptions :: Parser LogOptions
126+
parseLogOptions =
127+
LogOptions
128+
<$> many
116129
( option
117130
(eitherReader readLogLevel)
118131
( metavar "LEVEL"
@@ -163,9 +176,6 @@ clOptionsParser =
163176
"Log file to output the logs into"
164177
)
165178
)
166-
<*> parseSMTOptions
167-
<*> parseEquationOptions
168-
<*> parseRewriteOptions
169179
<*> option
170180
(eitherReader $ mapM (readModifierT . trim) . splitOn ",")
171181
( metavar "PRETTY_PRINT"
@@ -381,13 +391,6 @@ parseEquationOptions =
381391
defaultMaxIterations = 100
382392
defaultMaxRecursion = 5
383393

384-
nonnegativeInt :: Integral i => ReadM i
385-
nonnegativeInt =
386-
auto @Integer >>= \case
387-
i
388-
| i < 0 -> readerError "must be a non-negative integer."
389-
| otherwise -> pure (fromIntegral i)
390-
391394
parseRewriteOptions :: Parser RewriteOptions
392395
parseRewriteOptions =
393396
RewriteOptions
@@ -400,9 +403,9 @@ parseRewriteOptions =
400403
)
401404
<*> optional
402405
( option
403-
nonnegativeInt
406+
(intWith (> 0))
404407
( metavar "DEPTH"
405-
<> long "booster-interim-simplification"
408+
<> long "simplify-each"
406409
<> help "If given: Simplify the term each time the given rewrite depth is reached"
407410
)
408411
)
@@ -419,7 +422,15 @@ parseRewriteOptions =
419422

420423
enquote = decodeASCII . encodeLabel . BS.pack
421424

425+
intWith :: Integral i => (Integer -> Bool) -> ReadM i
426+
intWith p =
427+
auto >>= \case
428+
i
429+
| not (p i) -> readerError $ show i <> ": Invalid integer value."
430+
| otherwise -> pure (fromIntegral i)
422431

432+
nonnegativeInt :: Integral i => ReadM i
433+
nonnegativeInt = intWith (>= 0)
423434

424435

425436
versionInfoParser :: Parser (a -> a)

booster/tools/booster/Server.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,18 @@ main = do
126126
, mainModuleName
127127
, port
128128
, llvmLibraryFile
129-
, logLevels
130-
, logFormat
131-
, logTimeStamps
132-
, timeStampsFormat
133-
, logContexts
134-
, logFile
129+
, logOptions = LogOptions
130+
{ logLevels
131+
, logFormat
132+
, logTimeStamps
133+
, timeStampsFormat
134+
, logContexts
135+
, logFile
136+
, prettyPrintOptions
137+
}
135138
, smtOptions
136139
, equationOptions
137140
, rewriteOptions
138-
, prettyPrintOptions
139141
}
140142
, proxyOptions =
141143
ProxyOptions

dev-tools/booster-dev/Server.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ main = do
5050
let CLOptions
5151
{ definitionFile
5252
, mainModuleName
53-
, port
54-
, logLevels
55-
, logContexts
56-
, logTimeStamps
57-
, timeStampsFormat
58-
, logFormat
5953
, llvmLibraryFile
54+
, port
55+
, logOptions = LogOptions
56+
{ logLevels
57+
, logContexts
58+
, logTimeStamps
59+
, timeStampsFormat
60+
, logFormat
61+
, logFile
62+
, prettyPrintOptions
63+
}
6064
, smtOptions
6165
, equationOptions
6266
, rewriteOptions
63-
, prettyPrintOptions
64-
, logFile
6567
} = options
6668

6769
putStrLn $

dev-tools/kore-rpc-dev/Server.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ main = do
141141
{ clOptions =
142142
clOPts@CLOptions
143143
{ port
144-
, logLevels
145-
, logContexts
146-
, logFormat
144+
, logOptions = LogOptions
145+
{ logLevels
146+
, logContexts
147+
, logFormat
148+
, logFile
149+
, logTimeStamps
150+
, prettyPrintOptions
151+
}
147152
, smtOptions
148-
, logFile
149-
, logTimeStamps
150-
, prettyPrintOptions
151153
}
152154
} = options
153155
(logLevel, customLevels) = adjustLogLevels logLevels

scripts/performance-tests-kevm.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,30 @@ feature_shell "cd kevm-pyk && poetry run pytest src/tests/integration/test_prove
106106

107107
mkdir -p $SCRIPT_DIR/logs
108108

109+
# use special options if given, but restore KORE_RPC_OPTS afterwards
110+
if [ ! -z "${FEATURE_SERVER_OPTS}" ]; then
111+
echo "Using special options '${FEATURE_SERVER_OPTS}' via KORE_RPC_OPTS"
112+
if [ ! -z "${KORE_RPC_OPTS}" ]; then
113+
PRIOR_OPTS=${KORE_RPC_OPTS}
114+
fi
115+
export KORE_RPC_OPTS=${FEATURE_SERVER_OPTS}
116+
fi
117+
109118
feature_shell "make test-prove-rules PYTEST_PARALLEL=$PYTEST_PARALLEL PYTEST_ARGS='--maxfail=0 --timeout 7200 -vv $BUG_REPORT --kompiled-targets-dir $PREKOMPILED_DIR' | tee $SCRIPT_DIR/logs/kevm-$KEVM_VERSION-$FEATURE_BRANCH_NAME.log"
110119
killall kore-rpc-booster || echo "No zombie processes found"
111120

112121

113122
if [ -z "$BUG_REPORT" ]; then
114-
if [ ! -e "$SCRIPT_DIR/logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log" ]; then
115-
master_shell "make test-prove-rules PYTEST_PARALLEL=$PYTEST_PARALLEL PYTEST_ARGS='--maxfail=0 --timeout 7200 -vv --kompiled-targets-dir $PREKOMPILED_DIR' | tee $SCRIPT_DIR/logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log"
116-
killall kore-rpc-booster || echo "No zombie processes found"
117-
fi
123+
if [ ! -z "${PRIOR_OPTS}" ]; then
124+
export KORE_RPC_OPTS=${PRIOR_OPTS}
125+
else
126+
unset KORE_RPC_OPTS
127+
fi
128+
if [ ! -e "$SCRIPT_DIR/logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log" ]; then
129+
master_shell "make test-prove-rules PYTEST_PARALLEL=$PYTEST_PARALLEL PYTEST_ARGS='--maxfail=0 --timeout 7200 -vv --kompiled-targets-dir $PREKOMPILED_DIR' | tee $SCRIPT_DIR/logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log"
130+
killall kore-rpc-booster || echo "No zombie processes found"
131+
fi
118132

119-
cd $SCRIPT_DIR
120-
python3 compare.py logs/kevm-$KEVM_VERSION-$FEATURE_BRANCH_NAME.log logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log > logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT-$FEATURE_BRANCH_NAME-compare
133+
cd $SCRIPT_DIR
134+
python3 compare.py logs/kevm-$KEVM_VERSION-$FEATURE_BRANCH_NAME.log logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT.log > logs/kevm-$KEVM_VERSION-master-$MASTER_COMMIT_SHORT-$FEATURE_BRANCH_NAME-compare
121135
fi

0 commit comments

Comments
 (0)