@@ -28,6 +28,8 @@ module Cardano.DbSync.Api (
28
28
getPruneConsume ,
29
29
getHasConsumedOrPruneTxOut ,
30
30
getSkipTxIn ,
31
+ initEpochStatistics ,
32
+ resetEpochStatistics ,
31
33
getPrunes ,
32
34
mkSyncEnvFromConfig ,
33
35
verifySnapshotPoint ,
@@ -52,7 +54,7 @@ import Control.Concurrent.Class.MonadSTM.Strict (
52
54
newTVarIO ,
53
55
readTVar ,
54
56
readTVarIO ,
55
- writeTVar ,
57
+ writeTVar , StrictTVar ,
56
58
)
57
59
import Control.Monad.Trans.Maybe (MaybeT (.. ))
58
60
import qualified Data.Strict.Maybe as Strict
@@ -77,7 +79,7 @@ import qualified Ouroboros.Network.Point as Point
77
79
78
80
import qualified Cardano.Db as DB
79
81
import Cardano.DbSync.Api.Types
80
- import Cardano.DbSync.Cache.Types (CacheCapacity (.. ), newEmptyCache , useNoCache )
82
+ import Cardano.DbSync.Cache.Types (CacheCapacity (.. ), newEmptyCache , useNoCache , initCacheStatistics )
81
83
import Cardano.DbSync.Config.Cardano
82
84
import Cardano.DbSync.Config.Shelley
83
85
import Cardano.DbSync.Config.Types
@@ -93,6 +95,7 @@ import Cardano.DbSync.Ledger.Types (HasLedgerEnv (..), LedgerStateFile (..), Sna
93
95
import Cardano.DbSync.LocalStateQuery
94
96
import Cardano.DbSync.Types
95
97
import Cardano.DbSync.Util
98
+ import qualified Data.Map.Strict as Map
96
99
97
100
setConsistentLevel :: SyncEnv -> ConsistentLevel -> IO ()
98
101
setConsistentLevel env cst = do
@@ -392,6 +395,7 @@ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfig
392
395
oarq <- newTBQueueIO 1000
393
396
epochVar <- newTVarIO initCurrentEpochNo
394
397
epochSyncTime <- newTVarIO =<< getCurrentTime
398
+ epochStatistics <- initEpochStatistics
395
399
ledgerEnvType <-
396
400
case (enpMaybeLedgerStateDir syncNP, hasLedger' syncNodeConfigFromFile) of
397
401
(Just dir, True ) ->
@@ -417,6 +421,7 @@ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfig
417
421
{ envDbEnv = dbEnv
418
422
, envBootstrap = bootstrapVar
419
423
, envCache = cache
424
+ , envEpochStatistics = epochStatistics
420
425
, envConsistentLevel = consistentLevelVar
421
426
, envDbConstraints = dbCNamesVar
422
427
, envCurrentEpochNo = epochVar
@@ -437,6 +442,25 @@ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfig
437
442
hasLedger' = hasLedger . sioLedger . dncInsertOptions
438
443
isTxOutConsumedBootstrap' = isTxOutConsumedBootstrap . sioTxOut . dncInsertOptions
439
444
445
+ initEpochStatistics :: MonadIO m => m (StrictTVar IO EpochStatistics )
446
+ initEpochStatistics = do
447
+ curTime <- liftIO getCurrentTime
448
+ liftIO $ newTVarIO $ EpochStatistics
449
+ { elsStartTime = curTime
450
+ , elsCaches = initCacheStatistics
451
+ , elsUnicodeNull = Map. empty
452
+ }
453
+
454
+ resetEpochStatistics :: MonadIO m => SyncEnv -> m ()
455
+ resetEpochStatistics syncEnv = liftIO $ do
456
+ curTime <- getCurrentTime
457
+ let newEpochStatsValue = EpochStatistics
458
+ { elsStartTime = curTime
459
+ , elsCaches = initCacheStatistics
460
+ , elsUnicodeNull = Map. empty
461
+ }
462
+ atomically $ writeTVar (envEpochStatistics syncEnv) newEpochStatsValue
463
+
440
464
-- | 'True' is for in memory points and 'False' for on disk
441
465
getLatestPoints :: SyncEnv -> IO [(CardanoPoint , Bool )]
442
466
getLatestPoints env = do
0 commit comments