Skip to content

Commit cb3ae44

Browse files
committed
more WIP per-rule statistics. RAM-hungry on larger log files
1 parent 7fe3d88 commit cb3ae44

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

dev-tools/process-logs/Main.hs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Data.ByteString.Char8 qualified as BSS
1414
import Data.ByteString.Lazy.Char8 qualified as BS
1515
import Data.Either (partitionEithers)
1616
import Data.Foldable (toList)
17-
import Data.List (foldl', maximumBy)
17+
import Data.List (foldl', maximumBy, sortBy)
1818
import Data.Map (Map)
1919
import Data.Map qualified as Map
2020
import Data.Maybe (mapMaybe)
@@ -61,22 +61,10 @@ data Command
6161
Filter [ContextFilter]
6262
-- | find repeated rule/equation contexts in lines
6363
| FindRecursions
64+
-- | compute total times spent on applying certain rules/equations (top-level)
65+
| TimesPerRule
6466
deriving (Show)
6567

66-
{-
67-
brainstorm only
68-
| -- | sort lines by timestamp
69-
SortByTime Int -- insertion window size
70-
| -- | identify simplification and function rules that are recursively applied
71-
FindRecursions -- specific targets
72-
| -- | select subtrees below specific rules by ID
73-
Select [UniqueId]
74-
75-
canStream :: Command -> Bool
76-
canStream Filter = True
77-
canStream _ = False
78-
-}
79-
8068
parse :: ParserInfo Options
8169
parse =
8270
info
@@ -118,6 +106,13 @@ parse =
118106
(progDesc "find repeated contexts in log lines")
119107
)
120108
)
109+
<> ( command
110+
"times-per-rule"
111+
( info
112+
(pure TimesPerRule <**> helper)
113+
(progDesc "compute total times spent per (top-level) rule/equation")
114+
)
115+
)
121116

122117
parseContextFilter =
123118
argument
@@ -142,6 +137,26 @@ process FindRecursions =
142137
BS.pack $ printf "| %22s | %7d | %5d | %s" (show ctx) len cnt (showCtx pfx)
143138

144139
showCtx = concatMap (show . (: []))
140+
process TimesPerRule =
141+
(heading <>) . map renderResult . ruleStatistics
142+
where
143+
heading =
144+
[ "| Rule/Equation | Success | Failure | Abort"
145+
, "|----------------------- | ----------------- | ----------------- | ----------------"
146+
]
147+
renderResult :: (IdContext, RuleStats) -> BS.ByteString
148+
renderResult (ctx, stats) =
149+
BS.pack $
150+
printf
151+
"| %22s | %3.3fs (%4d) | %3.3fs (%4d) | %3.3fs (%4d)"
152+
(show ctx)
153+
stats.tSuccess
154+
stats.nSuccess
155+
stats.tFailure
156+
stats.nFailure
157+
stats.tAbort
158+
stats.nAbort
159+
145160

146161
encodeLogLine :: LogLine -> BS.ByteString
147162
encodeLogLine = JSON.encodePretty' rpcJsonConfig{JSON.confIndent = JSON.Spaces 0}
@@ -203,13 +218,22 @@ findRecursions ls = Map.assocs resultMap
203218
------------------------------------------------------------
204219
-- rule statistics
205220

221+
ruleStatistics :: [LogLine] -> [(IdContext, RuleStats)]
222+
ruleStatistics =
223+
sortBy (comparing $ allTimes . snd)
224+
. Map.assocs
225+
. ruleStats
226+
where
227+
allTimes :: RuleStats -> Double
228+
allTimes stats = stats.tSuccess + stats.tFailure + stats.tAbort
229+
206230
data RuleStats =
207231
RuleStats
208232
{ -- counts of:
209233
nSuccess :: !Int -- successful application
210234
, nFailure :: !Int -- failure to apply
211235
, nAbort :: !Int -- failure, leading to abort
212-
, -- total times for these categores
236+
, -- total times for these categories
213237
tSuccess :: !Double
214238
, tFailure :: !Double
215239
, tAbort :: !Double
@@ -255,7 +279,8 @@ ruleStats = Map.fromListWith (<>) . collect
255279
fromCtxSpan :: Seq CLContext -> [LogLine] -> (RuleStats, [LogLine])
256280
fromCtxSpan prefix ls
257281
| null prefixLines =
258-
error "Should have at least one line with the prefix" -- see above
282+
(RuleStats 0 0 0 0 0 0, ls) -- HACK
283+
-- error "Should have at least one line with the prefix" -- see above
259284
| otherwise =
260285
(mkOutcome (head prefixLines) (last prefixLines), rest)
261286
where

0 commit comments

Comments
 (0)