Skip to content

Commit b7b1e7f

Browse files
committed
add shakeDatabaseSize function and update logging to include database size
1 parent d4567ca commit b7b1e7f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ import Development.IDE.Graph.Database (ShakeDatabase,
142142
instantiateDelayedAction,
143143
mkDelayedAction,
144144
shakeComputeToPreserve,
145+
shakeDatabaseSize,
145146
shakeGetActionQueueLength,
146147
shakeGetBuildStep,
147148
shakeGetDatabaseKeys,
@@ -211,7 +212,7 @@ import Data.Foldable (foldl')
211212
data Log
212213
= LogCreateHieDbExportsMapStart
213214
| LogCreateHieDbExportsMapFinish !Int
214-
| LogBuildSessionRestart !ShakeRestartArgs ![DelayedActionInternal] !KeySet !Seconds !Seconds !Int !(Maybe FilePath) !Int ![DeliverStatus] !Seconds ![Key]
215+
| LogBuildSessionRestart !ShakeRestartArgs ![DelayedActionInternal] !KeySet !Seconds !Seconds !Int !(Maybe FilePath) !Int ![DeliverStatus] !Seconds ![Key] !Int
215216
| LogBuildSessionRestartTakingTooLong !Seconds
216217
| LogDelayedAction !(DelayedAction ()) !Seconds
217218
| LogBuildSessionFinish !Step !(Either SomeException [Either SomeException ()])
@@ -255,7 +256,7 @@ instance Pretty Log where
255256
"Initializing exports map from hiedb"
256257
LogCreateHieDbExportsMapFinish exportsMapSize ->
257258
"Done initializing exports map from hiedb. Size:" <+> pretty exportsMapSize
258-
LogBuildSessionRestart restartArgs actionQueue _keyBackLog abortDuration computeToPreserveTime lookupNums shakeProfilePath step _delivers prepare _oldUpSweepDirties ->
259+
LogBuildSessionRestart restartArgs actionQueue _keyBackLog abortDuration computeToPreserveTime lookupNums shakeProfilePath step _delivers prepare _oldUpSweepDirties dbSize ->
259260
vcat
260261
[ "Restarting build session due to" <+> pretty (sraReason restartArgs)
261262
, "Restarts num:" <+> pretty (sraCount $ restartArgs)
@@ -264,9 +265,10 @@ instance Pretty Log where
264265
-- , "Keys:" <+> pretty (length $ toListKeySet keyBackLog)
265266
-- , "Deliveries still alive:" <+> pretty delivers
266267
, "Current step:" <+> pretty (show step)
267-
, "Aborting previous build session took" <+> pretty (showDuration abortDuration) <+> "(" <> pretty (showDuration computeToPreserveTime) <+> "to compute preserved keys," <+> pretty lookupNums <+> "lookups)"
268+
, "Aborting previous build session took" <+> pretty (showDuration abortDuration) <+> "(" <> pretty (showDuration computeToPreserveTime) <+> "to compute preserved keys," <+> pretty lookupNums <+>"/" <+> pretty dbSize <+> " lookups)"
268269
<+> pretty shakeProfilePath
269270
, "prepare new session took" <+> pretty (showDuration prepare)
271+
, "Database size:" <+> pretty dbSize
270272
-- , "old upsweep dirties:" <+> pretty (oldUpSweepDirties)
271273
]
272274
LogBuildSessionRestartTakingTooLong seconds ->
@@ -984,6 +986,7 @@ runRestartTask recorder ideStateVar shakeRestartArgs = do
984986
logErrorAfter 10 $ can dirties
985987
return (toUpSweepKeys, computePreserveTime, lookupsNum, oldUpSweepDirties)
986988
survivedDelivers <- shakePeekAsyncsDelivers shakeDb
989+
dbSize <- shakeDatabaseSize shakeDb
987990
-- it is every important to update the dirty keys after we enter the critical section
988991
-- see Note [Housekeeping rule cache and dirty key outside of hls-graph]
989992
atomically $ modifyTVar' (dirtyKeys shakeExtras) $ \x -> foldl' (flip insertKeySet) x newDirtyKeys
@@ -995,7 +998,7 @@ runRestartTask recorder ideStateVar shakeRestartArgs = do
995998
step <- shakeGetBuildStep shakeDb
996999

9971000
-- let logRestart x = logWith recorder Info $ LogBuildSessionRestart shakeRestartArgs queue backlog stopTime computePreserveTime lookupsNum res step survivedDelivers x $ preservekvs
998-
let logRestart x = logWith recorder Info $ LogBuildSessionRestart shakeRestartArgs queue backlog stopTime computePreserveTime lookupsNum res step survivedDelivers x oldUpSweepDirties
1001+
let logRestart x = logWith recorder Info $ LogBuildSessionRestart shakeRestartArgs queue backlog stopTime computePreserveTime lookupsNum res step survivedDelivers x oldUpSweepDirties dbSize
9991002
return (shakeRestartArgs, toUpSweepKeys, fromListKeySet $ map deliverKey survivedDelivers, logRestart)
10001003
)
10011004
-- It is crucial to be masked here, otherwise we can get killed

hls-graph/src/Development/IDE/Graph/Database.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module Development.IDE.Graph.Database(
1818
shakePeekAsyncsDelivers,
1919
instantiateDelayedAction,
2020
mkDelayedAction,
21-
upsweepAction) where
21+
upsweepAction,
22+
shakeDatabaseSize) where
2223
import Control.Concurrent.Extra (Barrier, newBarrier,
2324
signalBarrier,
2425
waitBarrierMaybe)
@@ -43,6 +44,7 @@ import Development.IDE.Graph.Internal.Scheduler
4344
import Development.IDE.Graph.Internal.Types
4445
import qualified Development.IDE.Graph.Internal.Types as Logger
4546
import Development.IDE.WorkerThread (DeliverStatus)
47+
import qualified StmContainers.Map as SMap
4648
import System.Time.Extra (duration,
4749
showDuration)
4850

@@ -143,6 +145,12 @@ shakeRunDatabaseForKeys (Just x) sdb as2 =
143145
shakePeekAsyncsDelivers :: ShakeDatabase -> IO [DeliverStatus]
144146
shakePeekAsyncsDelivers (ShakeDatabase _ _ db) = peekAsyncsDelivers db
145147

148+
shakeDatabaseSize :: ShakeDatabase -> IO Int
149+
shakeDatabaseSize (ShakeDatabase _ _ db) = databaseSize db
150+
151+
databaseSize :: Database -> IO Int
152+
databaseSize db = atomically $ SMap.size $ databaseValues db
153+
146154
-- | Given a 'ShakeDatabase', write an HTML profile to the given file about the latest run.
147155
shakeProfileDatabase :: ShakeDatabase -> FilePath -> IO ()
148156
shakeProfileDatabase (ShakeDatabase _ _ db) file = writeProfile file db

0 commit comments

Comments
 (0)