diff --git a/Framework/NethereumWorkflow/BlockUtils/BlockCache.cs b/Framework/NethereumWorkflow/BlockUtils/BlockCache.cs index 19549634..c902eda0 100644 --- a/Framework/NethereumWorkflow/BlockUtils/BlockCache.cs +++ b/Framework/NethereumWorkflow/BlockUtils/BlockCache.cs @@ -35,5 +35,7 @@ if (!entries.TryGetValue(number, out BlockTimeEntry? value)) return null; return value; } + + public int Size { get { return entries.Count; } } } } diff --git a/Framework/NethereumWorkflow/BlockUtils/BlockTimeFinder.cs b/Framework/NethereumWorkflow/BlockUtils/BlockTimeFinder.cs index f2a89c2a..3678cea8 100644 --- a/Framework/NethereumWorkflow/BlockUtils/BlockTimeFinder.cs +++ b/Framework/NethereumWorkflow/BlockUtils/BlockTimeFinder.cs @@ -24,7 +24,7 @@ namespace NethereumWorkflow.BlockUtils if (moment <= bounds.Genesis.Utc) return null; if (moment >= bounds.Current.Utc) return bounds.Current.BlockNumber; - return Search(bounds.Genesis, bounds.Current, moment, HighestBeforeSelector); + return Log(() => Search(bounds.Genesis, bounds.Current, moment, HighestBeforeSelector)); } public ulong? GetLowestBlockNumberAfter(DateTime moment) @@ -33,7 +33,16 @@ namespace NethereumWorkflow.BlockUtils if (moment >= bounds.Current.Utc) return null; if (moment <= bounds.Genesis.Utc) return bounds.Genesis.BlockNumber; - return Search(bounds.Genesis, bounds.Current, moment, LowestAfterSelector); + return Log(()=> Search(bounds.Genesis, bounds.Current, moment, LowestAfterSelector)); ; + } + + private ulong Log(Func operation) + { + var sw = Stopwatch.Begin(log, nameof(BlockTimeFinder)); + var result = operation(); + sw.End($"(Cache size: {cache.Size})"); + + return result; } private ulong Search(BlockTimeEntry lower, BlockTimeEntry upper, DateTime target, Func isWhatIwant)