@@ -14,7 +14,7 @@ import Data.ByteString.Char8 qualified as BSS
14
14
import Data.ByteString.Lazy.Char8 qualified as BS
15
15
import Data.Either (partitionEithers )
16
16
import Data.Foldable (toList )
17
- import Data.List (foldl' , maximumBy )
17
+ import Data.List (foldl' , maximumBy , sortBy )
18
18
import Data.Map (Map )
19
19
import Data.Map qualified as Map
20
20
import Data.Maybe (mapMaybe )
@@ -61,22 +61,10 @@ data Command
61
61
Filter [ContextFilter ]
62
62
-- | find repeated rule/equation contexts in lines
63
63
| FindRecursions
64
+ -- | compute total times spent on applying certain rules/equations (top-level)
65
+ | TimesPerRule
64
66
deriving (Show )
65
67
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
-
80
68
parse :: ParserInfo Options
81
69
parse =
82
70
info
@@ -118,6 +106,13 @@ parse =
118
106
(progDesc " find repeated contexts in log lines" )
119
107
)
120
108
)
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
+ )
121
116
122
117
parseContextFilter =
123
118
argument
@@ -142,6 +137,26 @@ process FindRecursions =
142
137
BS. pack $ printf " | %22s | %7d | %5d | %s" (show ctx) len cnt (showCtx pfx)
143
138
144
139
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
+
145
160
146
161
encodeLogLine :: LogLine -> BS. ByteString
147
162
encodeLogLine = JSON. encodePretty' rpcJsonConfig{JSON. confIndent = JSON. Spaces 0 }
@@ -203,13 +218,22 @@ findRecursions ls = Map.assocs resultMap
203
218
------------------------------------------------------------
204
219
-- rule statistics
205
220
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
+
206
230
data RuleStats =
207
231
RuleStats
208
232
{ -- counts of:
209
233
nSuccess :: ! Int -- successful application
210
234
, nFailure :: ! Int -- failure to apply
211
235
, nAbort :: ! Int -- failure, leading to abort
212
- , -- total times for these categores
236
+ , -- total times for these categories
213
237
tSuccess :: ! Double
214
238
, tFailure :: ! Double
215
239
, tAbort :: ! Double
@@ -255,7 +279,8 @@ ruleStats = Map.fromListWith (<>) . collect
255
279
fromCtxSpan :: Seq CLContext -> [LogLine ] -> (RuleStats , [LogLine ])
256
280
fromCtxSpan prefix ls
257
281
| 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
259
284
| otherwise =
260
285
(mkOutcome (head prefixLines) (last prefixLines), rest)
261
286
where
0 commit comments