1
- {-# OPTIONS_GHC -fmax-pmcheck-models=15000 #-}
1
+ {-# OPTIONS_GHC -fmax-pmcheck-models=25000 #-}
2
2
module Cardano.Command (module Cardano.Command ) where
3
3
4
4
import Cardano.Prelude hiding (State , head )
5
5
6
6
import Data.Aeson qualified as Aeson
7
7
import Data.ByteString qualified as BS
8
8
import Data.ByteString.Lazy.Char8 qualified as LBS
9
+ import Data.Map.Strict qualified as Map
9
10
import Data.Text (pack )
10
11
import Data.Text qualified as T
11
12
import Data.Text.Short (toText )
@@ -69,7 +70,6 @@ data ChainCommand
69
70
| ComputePropagation
70
71
| RenderPropagation RenderFormat TextOutputFile PropSubset
71
72
| ReadPropagations [JsonInputFile BlockPropOne ]
72
-
73
73
| ComputeMultiPropagation
74
74
| RenderMultiPropagation RenderFormat TextOutputFile PropSubset CDF2Aspect
75
75
@@ -79,10 +79,13 @@ data ChainCommand
79
79
| ComputeClusterPerf
80
80
| RenderClusterPerf RenderFormat TextOutputFile PerfSubset
81
81
| ReadClusterPerfs [JsonInputFile MultiClusterPerf ]
82
-
83
82
| ComputeMultiClusterPerf
84
83
| RenderMultiClusterPerf RenderFormat TextOutputFile PerfSubset CDF2Aspect
85
84
85
+ | ComputeSummary
86
+ | RenderSummary RenderFormat TextOutputFile
87
+ | ReadSummaries [JsonInputFile Summary ]
88
+
86
89
| Compare InputDir (Maybe TextInputFile ) TextOutputFile
87
90
[( JsonInputFile RunPartial
88
91
, JsonInputFile Genesis
@@ -212,7 +215,20 @@ parseChainCommand =
212
215
(writerOpts RenderMultiClusterPerf " Render"
213
216
<*> parsePerfSubset
214
217
<*> parseCDF2Aspect)
218
+ ]) <|>
219
+
220
+ subparser (mconcat [ commandGroup " Analysis summary"
221
+ , op " compute-summary" " Compute run analysis summary"
222
+ (ComputeSummary & pure )
223
+ , op " render-summary" " Render run analysis summary"
224
+ (writerOpts RenderSummary " Render" )
225
+ , op " read-summaries" " Read analysis summaries"
226
+ (ReadSummaries
227
+ <$> some
228
+ (optJsonInputFile " summary" " JSON block propagation input file" ))
229
+ ]) <|>
215
230
231
+ subparser (mconcat [ commandGroup " Run comparison"
216
232
, op " compare" " Generate a report comparing multiple runs"
217
233
(Compare
218
234
<$> optInputDir " ede" " Directory with EDE templates."
@@ -289,7 +305,7 @@ data State
289
305
= State
290
306
{ -- common
291
307
sWhen :: UTCTime
292
- , sFilters :: [FilterName ]
308
+ , sFilters :: ( [FilterName ], [ ChainFilter ])
293
309
, sTags :: [Text ]
294
310
, sRun :: Maybe Run
295
311
, sObjLists :: Maybe [(JsonLogfile , [LogObject ])]
@@ -308,8 +324,46 @@ data State
308
324
, sMachPerf :: Maybe [(JsonLogfile , MachPerfOne )]
309
325
, sClusterPerf :: Maybe [ClusterPerf ]
310
326
, sMultiClusterPerf :: Maybe MultiClusterPerf
327
+ --
328
+ , sSummaries :: Maybe [Summary ]
311
329
}
312
330
331
+ computeSummary :: State -> Summary
332
+ computeSummary =
333
+ \ case
334
+ State {sRun = Nothing } -> err " a run"
335
+ State {sObjLists = Nothing } -> err " logobjects"
336
+ State {sObjLists = Just [] } -> err " logobjects"
337
+ State {sClusterPerf = Nothing } -> err " cluster performance results"
338
+ State {sBlockProp = Nothing } -> err " block propagation results"
339
+ State {sChainRejecta = Nothing } -> err " chain rejects"
340
+ State {sDomSlots = Nothing } -> err " a slot domain"
341
+ State {sDomBlocks = Nothing } -> err " a block domain"
342
+ State { sObjLists = Just (fmap snd -> objLists)
343
+ -- , sClusterPerf = Just clusterPerf
344
+ -- , sBlockProp = Just blockProp
345
+ , sChainRejecta = Just chainRejecta
346
+ , sDomSlots = Just sumDomainSlots
347
+ , sDomBlocks = Just sumDomainBlocks
348
+ , .. } ->
349
+ Summary
350
+ { sumWhen = sWhen
351
+ , sumFilters = sFilters
352
+ , sumLogStreams = countOfList objLists
353
+ , sumLogObjects = countOfLists objLists
354
+ , sumBlocksRejected = countOfList chainRejecta
355
+ , ..
356
+ }
357
+ where
358
+ sumChainRejectionStats =
359
+ chainRejecta
360
+ <&> fmap fst . filter (not . snd ) . beAcceptance
361
+ & concat
362
+ & foldr' (\ k m -> Map. insertWith (+) k 1 m) Map. empty
363
+ & Map. toList
364
+ where
365
+ err = error . (" Summary of a run requires " <> )
366
+
313
367
sRunAnchor :: State -> Anchor
314
368
sRunAnchor State {sRun = Just run, sFilters, sWhen, sDomSlots, sDomBlocks}
315
369
= runAnchor run sWhen sFilters sDomSlots sDomBlocks
@@ -391,7 +445,7 @@ runChainCommand s@State{sRun=Just run, sMachViews=Just mvs}
391
445
, sChainRejecta = Just chainRejecta
392
446
, sDomSlots = Just domSlot
393
447
, sDomBlocks = Just domBlock
394
- , sFilters = fltNames
448
+ , sFilters = ( fltNames, flts)
395
449
}
396
450
-- pure s { sChain = Just chain }
397
451
runChainCommand _ c@ RebuildChain {} = missingCommandData c
@@ -467,7 +521,7 @@ runChainCommand s@State{sRun=Just run, sSlotsRaw=Just slotsRaw}
467
521
[ " All " , show $ maximum (length . snd <$> slotsRaw), " slots filtered out." ]
468
522
pure s { sSlots = Just fltrd
469
523
, sDomSlots = Just domSlots
470
- , sFilters = fltNames
524
+ , sFilters = ( fltNames, flts)
471
525
}
472
526
runChainCommand _ c@ FilterSlots {} = missingCommandData c
473
527
[" run metadata & genesis" , " unfiltered slot stats" ]
@@ -612,6 +666,28 @@ runChainCommand s@State{sMultiClusterPerf=Just (MultiClusterPerf perf)}
612
666
runChainCommand _ c@ RenderMultiClusterPerf {} = missingCommandData c
613
667
[" multi-run cluster preformance stats" ]
614
668
669
+ runChainCommand s ComputeSummary = do
670
+ progress " summary" (Q " summarising a run" )
671
+ pure s { sSummaries = Just [computeSummary s] }
672
+
673
+ runChainCommand s@ State {sSummaries = Just (_summary: _)} c@ (RenderSummary fmt f) = do
674
+ progress " summary" (Q $ printf " rendering summary" )
675
+ dumpText " summary" body (modeFilename f " " fmt)
676
+ & firstExceptT (CommandError c)
677
+ pure s
678
+ where body = [" " ] -- renderSummary summary
679
+ runChainCommand _ c@ RenderSummary {} = missingCommandData c
680
+ [" run summary" ]
681
+
682
+ runChainCommand s@ State {}
683
+ c@ (ReadSummaries fs) = do
684
+ progress " summaries" (Q $ printf " reading %d run summaries" $ length fs)
685
+ xs <- mapConcurrently (fmap (Aeson. eitherDecode @ Summary ) . LBS. readFile . unJsonInputFile) fs
686
+ & fmap sequence
687
+ & newExceptT
688
+ & firstExceptT (CommandError c . show )
689
+ pure s { sSummaries = Just xs }
690
+
615
691
runChainCommand s c@ (Compare ede mTmpl outf@ (TextOutputFile outfp) runs) = do
616
692
progress " report" (Q $ printf " rendering report for %d runs" $ length runs)
617
693
xs :: [(ClusterPerf , BlockPropOne , Run )] <- forM runs $
@@ -666,11 +742,11 @@ runCommand (ChainCommand cs) = do
666
742
where
667
743
initialState :: UTCTime -> State
668
744
initialState now =
669
- State now [] []
745
+ State now ([] , [] ) []
746
+ Nothing Nothing Nothing Nothing
670
747
Nothing Nothing Nothing Nothing
671
748
Nothing Nothing Nothing Nothing
672
749
Nothing Nothing Nothing Nothing
673
- Nothing Nothing Nothing
674
750
675
751
opts :: ParserInfo Command
676
752
opts =
0 commit comments