@@ -21,6 +21,7 @@ import Options.Applicative qualified as Opt
2121
2222import System.Directory (doesFileExist )
2323import System.FilePath
24+ import System.Mem qualified as Mem (performGC )
2425import System.Posix.Files qualified as IO
2526
2627import Cardano.Analysis.API
@@ -29,6 +30,8 @@ import Cardano.Analysis.MachPerf
2930import Cardano.Analysis.Summary
3031import Cardano.Render
3132import Cardano.Report
33+ import Cardano.Unlog.BackendDB
34+ import Cardano.Unlog.BackendFile
3235import Cardano.Unlog.LogObject
3336import Cardano.Util hiding (head )
3437
@@ -50,9 +53,10 @@ data ChainCommand
5053 = ReadMetaGenesis (JsonInputFile RunPartial ) (JsonInputFile Genesis )
5154 | WriteMetaGenesis TextOutputFile TextOutputFile
5255
53- | Unlog (JsonInputFile (RunLogs () )) Bool (Maybe [LOAnyType ])
56+ | Unlog (JsonInputFile (RunLogs () )) Bool (Maybe [LOAnyType ])
5457 | DumpLogObjects
55-
58+ | PrepareDB String [TextInputFile ] SqliteOutputFile
59+ | UnlogDB (JsonInputFile (RunLogs () ))
5660 | ValidateHashTimeline (JsonInputFile [LogObject ])
5761
5862 | BuildMachViews
@@ -122,6 +126,15 @@ parseChainCommand =
122126 (some
123127 (optLOAnyType " ok-loany" " [MULTI] Allow a particular LOAnyType" ))
124128 )
129+ , op " unlog-db" " Read logs from DBs"
130+ (UnlogDB
131+ <$> optJsonInputFile " run-logs" " Run log manifest (API/Types.hs:RunLogs)"
132+ )
133+ , op " prepare-db" " Prepare an SQLite DB from a host's log output"
134+ (PrepareDB
135+ <$> optString " mach" " host's machine name"
136+ <*> some (optTextInputFile " log" " [MULTI] host log file(s)" )
137+ <*> optSqliteOutputFile " db" " DB output file" )
125138 , op " dump-logobjects" " Dump lifted log object streams, alongside input files"
126139 (DumpLogObjects & pure )
127140 , op " hash-timeline" " Quickly validate timeline by hashes"
@@ -417,6 +430,19 @@ runChainCommand s
417430 & firstExceptT (CommandError c)
418431 pure s { sRunLogs = Just runLogs }
419432
433+ runChainCommand s
434+ c@ (UnlogDB rlf) = do
435+ progress " logs" (Q $ printf " reading run log manifest %s" $ unJsonInputFile rlf)
436+ runLogsBare <- Aeson. eitherDecode @ (RunLogs () )
437+ <$> LBS. readFile (unJsonInputFile rlf)
438+ & newExceptT
439+ & firstExceptT (CommandError c . pack)
440+ progress " logs" (Q $ printf " loading logs from DBs for %d hosts" $
441+ Map. size $ rlHostLogs runLogsBare)
442+ runLogs <- runLiftLogObjectsDB runLogsBare
443+ & firstExceptT (CommandError c)
444+ pure s { sRunLogs = Just runLogs }
445+
420446runChainCommand s@ State {sRunLogs= Just (rlLogs -> objs)}
421447 c@ DumpLogObjects = do
422448 progress " logobjs" (Q $ printf " dumping %d logobject streams" $ length objs)
@@ -427,6 +453,13 @@ runChainCommand _ c@DumpLogObjects = missingCommandData c
427453
428454-- runChainCommand s c@(ReadMachViews _ _) -- () -> [(JsonLogfile, MachView)]
429455
456+ runChainCommand s
457+ c@ (PrepareDB machName inFiles outFile) = do
458+ progress " prepare-db" (Q $ printf " preparing DB %s from '%s' logs" (unSqliteOutputFile outFile) machName)
459+ prepareDB machName (map unTextInputFile inFiles) (unSqliteOutputFile outFile)
460+ & firstExceptT (CommandError c)
461+ pure s
462+
430463runChainCommand s
431464 c@ (ValidateHashTimeline timelineJson) = do
432465 progress " logs" (Q $ printf " validating hash timeline" )
@@ -446,6 +479,7 @@ runChainCommand s
446479runChainCommand s@ State {sRun= Just run, sRunLogs= Just (rlLogs -> objs)}
447480 BuildMachViews = do
448481 progress " machviews" (Q $ printf " building %d machviews" $ length objs)
482+ performGC
449483 mvs <- buildMachViews run objs & liftIO
450484 pure s { sMachViews = Just mvs }
451485runChainCommand _ c@ BuildMachViews = missingCommandData c
@@ -520,7 +554,8 @@ runChainCommand s@State{sRun=Just run, sRunLogs=Just (rlLogs -> objs)}
520554 let nonIgnored = flip filter objs $ (`notElem` ignores) . fst
521555 forM_ ignores $
522556 progress " perf-ignored-log" . R . unJsonLogfile
523- progress " slots" (Q $ printf " building slot %d timelines" $ length objs)
557+ progress " slots" (Q $ printf " building %d slot timelines" $ length objs)
558+ performGC
524559 (scalars, slotsRaw) <-
525560 fmap (mapAndUnzip redistribute) <$> collectSlotStats run nonIgnored
526561 & newExceptT
@@ -648,6 +683,7 @@ runChainCommand _ c@RenderMultiPropagation{} = missingCommandData c
648683runChainCommand s@ State {sRun= Just run, sSlots= Just slots}
649684 c@ ComputeMachPerf = do
650685 progress " machperf" (Q $ printf " computing %d machine performances" $ length slots)
686+ performGC
651687 perf <- mapConcurrentlyPure (slotStatsMachPerf run) slots
652688 & fmap sequence
653689 & newExceptT
@@ -833,6 +869,10 @@ fromAnalysisError :: ChainCommand -> AnalysisCmdError -> CommandError
833869fromAnalysisError c (AnalysisCmdError t) = CommandError c t
834870fromAnalysisError c o = CommandError c (show o)
835871
872+
873+ performGC :: ExceptT CommandError IO ()
874+ performGC = liftIO Mem. performGC
875+
836876runCommand :: Command -> ExceptT CommandError IO ()
837877
838878runCommand (ChainCommand cs) = do
0 commit comments