Skip to content

Commit 145355e

Browse files
committed
fix-ups in formatting and collector for time-per-rule
1 parent cb3ae44 commit 145355e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

dev-tools/process-logs/Main.hs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Data.List (foldl', maximumBy, sortBy)
1818
import Data.Map (Map)
1919
import Data.Map qualified as Map
2020
import Data.Maybe (mapMaybe)
21-
import Data.Ord (comparing)
21+
import Data.Ord (comparing, Down (..))
2222
import Data.Sequence (Seq (..))
2323
import Data.Sequence qualified as Seq
2424
import Data.Time.Clock
@@ -141,14 +141,14 @@ process TimesPerRule =
141141
(heading <>) . map renderResult . ruleStatistics
142142
where
143143
heading =
144-
[ "| Rule/Equation | Success | Failure | Abort"
145-
, "|----------------------- | ----------------- | ----------------- | ----------------"
144+
[ "| Rule/Equation | Success | Failure | Abort"
145+
, "|----------------------- | ------------------- | ------------------- | -------------------"
146146
]
147147
renderResult :: (IdContext, RuleStats) -> BS.ByteString
148148
renderResult (ctx, stats) =
149149
BS.pack $
150150
printf
151-
"| %22s | %3.3fs (%4d) | %3.3fs (%4d) | %3.3fs (%4d)"
151+
"| %22s | %10.6fs (%5d) | %10.6fs (%5d) | %10.6fs (%5d)"
152152
(show ctx)
153153
stats.tSuccess
154154
stats.nSuccess
@@ -220,7 +220,7 @@ findRecursions ls = Map.assocs resultMap
220220

221221
ruleStatistics :: [LogLine] -> [(IdContext, RuleStats)]
222222
ruleStatistics =
223-
sortBy (comparing $ allTimes . snd)
223+
sortBy (comparing (Down . allTimes . snd))
224224
. Map.assocs
225225
. ruleStats
226226
where
@@ -279,8 +279,7 @@ ruleStats = Map.fromListWith (<>) . collect
279279
fromCtxSpan :: Seq CLContext -> [LogLine] -> (RuleStats, [LogLine])
280280
fromCtxSpan prefix ls
281281
| null prefixLines =
282-
(RuleStats 0 0 0 0 0 0, ls) -- HACK
283-
-- error "Should have at least one line with the prefix" -- see above
282+
error "Should have at least one line with the prefix" -- see above
284283
| otherwise =
285284
(mkOutcome (head prefixLines) (last prefixLines), rest)
286285
where
@@ -289,22 +288,30 @@ ruleStats = Map.fromListWith (<>) . collect
289288
hasPrefix :: LogLine -> Bool
290289
hasPrefix = (== prefix) . Seq.take len . (.context)
291290

292-
(prefixLines, rest) = span (not . hasPrefix) ls
291+
(prefixLines, rest) = span hasPrefix ls
293292

294293
mkOutcome :: LogLine -> LogLine -> RuleStats
295294
mkOutcome startLine endLine =
296295
let time =
297-
maybe 1 realToFrac $
296+
maybe
297+
1
298+
realToFrac
298299
(diffUTCTime
299300
<$> fmap systemToUTCTime endLine.timestamp
300301
<*> fmap systemToUTCTime startLine.timestamp
301302
)
302-
in case endLine.context of
303-
_ :|> CLNullary CtxSuccess ->
303+
in case Seq.drop len endLine.context of
304+
CLNullary CtxSuccess :<| _ ->
304305
RuleStats 1 0 0 time 0 0
306+
-- rewrite failures
305307
_ :|> CLNullary CtxFailure ->
306308
RuleStats 0 1 0 0 time 0
307-
_ :|> CLNullary CtxAbort ->
309+
_ :|> CLNullary CtxIndeterminate ->
310+
RuleStats 0 0 1 0 0 time
311+
-- equation failures
312+
_ :|> CLNullary CtxContinue ->
313+
RuleStats 0 1 0 0 time 0
314+
_ :|> CLNullary CtxBreak ->
308315
RuleStats 0 0 1 0 0 time
309316
other -> -- case not covered...
310-
error $ "Unexpected last context " <> show (Seq.drop len other)
317+
error $ "Unexpected last context " <> show other

0 commit comments

Comments
 (0)