Skip to content

Commit 64147e3

Browse files
committed
Factor-out duration
1 parent 2ef21ab commit 64147e3

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

booster/library/Booster/JsonRpc.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ respond stateVar request =
167167
case evaluatedInitialPattern of
168168
(Left ApplyEquations.SideConditionFalse{}, _) -> do
169169
stop <- liftIO $ getTime Monotonic
170-
let duration =
171-
if fromMaybe False req.logTiming
172-
then
173-
Just $
174-
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
175-
else Nothing
176-
pure $ execResponse duration req (0, mempty, RewriteTrivial substPat) substitution unsupported
170+
pure $
171+
execResponse
172+
(duration req.logTiming start stop)
173+
req
174+
(0, mempty, RewriteTrivial substPat)
175+
substitution
176+
unsupported
177177
(Left other, _) ->
178178
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ other)
179179
(Right newPattern, _simplifierCache) -> do
@@ -199,13 +199,7 @@ respond stateVar request =
199199
performRewrite rewriteConfig newPattern
200200
SMT.finaliseSolver solver
201201
stop <- liftIO $ getTime Monotonic
202-
let duration =
203-
if fromMaybe False req.logTiming
204-
then
205-
Just $
206-
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
207-
else Nothing
208-
pure $ execResponse duration req result substitution unsupported
202+
pure $ execResponse (duration req.logTiming start stop) req result substitution unsupported
209203
RpcTypes.AddModule RpcTypes.AddModuleRequest{_module, nameAsId = nameAsId'} -> Booster.Log.withContext CtxAddModule $ runExceptT $ do
210204
-- block other request executions while modifying the server state
211205
state <- liftIO $ takeMVar stateVar
@@ -271,9 +265,9 @@ respond stateVar request =
271265
start <- liftIO $ getTime Monotonic
272266
let internalised =
273267
runExcept $ internaliseTermOrPredicate DisallowAlias CheckSubsorts Nothing def req.state.term
274-
let mkTraces duration
268+
let mkTraces durationLog
275269
| Just True <- req.logTiming =
276-
Just [ProcessingTime (Just Booster) duration]
270+
Just [ProcessingTime (Just Booster) durationLog]
277271
| otherwise =
278272
Nothing
279273

@@ -351,11 +345,11 @@ respond stateVar request =
351345
SMT.finaliseSolver solver
352346
stop <- liftIO $ getTime Monotonic
353347

354-
let duration =
348+
let durationLog =
355349
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
356350
mkSimplifyResponse state =
357351
RpcTypes.Simplify
358-
RpcTypes.SimplifyResult{state, logs = mkTraces duration}
352+
RpcTypes.SimplifyResult{state, logs = mkTraces durationLog}
359353
pure $ second mkSimplifyResponse result
360354
RpcTypes.GetModel req -> withModule req._module $ \case
361355
(_, _, Nothing, _) -> do
@@ -591,6 +585,13 @@ respond stateVar request =
591585
, logs = Nothing
592586
}
593587

588+
duration mLogTiming start stop =
589+
if fromMaybe False mLogTiming
590+
then
591+
Just $
592+
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
593+
else Nothing
594+
594595
handleSmtError :: JsonRpcHandler
595596
handleSmtError = JsonRpcHandler $ \case
596597
SMT.GeneralSMTError err -> runtimeError "problem" err

0 commit comments

Comments
 (0)