From 48e7f9895644ef375dc433e850e70bd679c92579 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 1 Apr 2024 13:46:30 +0200 Subject: [PATCH] Adds some logging --- .../NethereumWorkflow/BlockUtils/BlockCache.cs | 2 ++ .../NethereumWorkflow/BlockUtils/BlockTimeFinder.cs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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)