diff --git a/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager-Events.cs b/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager-Events.cs index 9c10abd..50352ef 100644 --- a/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager-Events.cs +++ b/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager-Events.cs @@ -60,63 +60,7 @@ public void Dispose() {} internal sealed partial class RecyclableMemoryStreamManager { public static readonly Events EventsWriter = new Events(); - private Counters Counter { get; } - - public sealed class Counters : IDisposable - { - private ReadOnlyCollection Polls { get;} - - public Counters(RecyclableMemoryStreamManager instance) - { - // ReSharper disable once UnusedParameter.Local - PollingCounter Create(string name, Func poll, string description) => - new PollingCounter(name, EventsWriter, poll) - // ReSharper disable once RedundantEmptyObjectOrCollectionInitializer - { -#if !NETSTANDARD2_0 && !NETFRAMEWORK - DisplayName = description -#endif - }; - - - var polls = new List() - { - { Create("blocks", () => _blocks, "Pooled blocks active")}, - { Create("large-buffers", () => _largeBuffers, "Large buffers active")}, - { Create("large-buffers-free", () => instance.LargeBuffersFree, "Large buffers free")}, - { Create("large-pool-inuse", () => instance.LargePoolInUseSize, "Large pool in use size")}, - { Create("small-pool-free", () => instance.SmallBlocksFree, "Small pool free blocks")}, - { Create("small-pool-inuse", () => instance.SmallPoolInUseSize, "Small pool in use size")}, - { Create("small-pool-free", () => instance.SmallPoolFreeSize, "Small pool free size")}, - { Create("small-pool-max", () => instance.MaximumFreeSmallPoolBytes, "Small pool max size")}, - { Create("memory-streams", () => _memoryStreams, "Active memory streams")}, - }; - Polls = new ReadOnlyCollection(polls); - - - } - - private long _blocks; - internal void ReportBlockCreated() => Interlocked.Increment(ref _blocks); - - internal void ReportBlockDiscarded() => Interlocked.Decrement(ref _blocks); - - private long _largeBuffers; - internal void ReportLargeBufferCreated() => Interlocked.Increment(ref _largeBuffers); - - internal void ReportLargeBufferDiscarded() => Interlocked.Decrement(ref _largeBuffers); - - private long _memoryStreams; - internal void ReportStreamCreated() => Interlocked.Increment(ref _memoryStreams); - - internal void ReportStreamDisposed() => Interlocked.Decrement(ref _memoryStreams); - - public void Dispose() - { - foreach(var p in Polls) p.Dispose(); - } - } - + [EventSource(Name = "Elastic-Transport-RecyclableMemoryStream", Guid = "{AD44FDAC-D3FC-460A-9EBE-E55A3569A8F6}")] public sealed class Events : EventSource { diff --git a/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager.cs b/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager.cs index 6a64119..32fe11b 100644 --- a/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager.cs +++ b/src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager.cs @@ -162,7 +162,6 @@ public RecyclableMemoryStreamManager(int blockSize, int largeBufferMultiple, int for (var i = 0; i < _largePools.Length; ++i) _largePools[i] = new ConcurrentStack(); - Counter = new Counters(this); EventsWriter.MemoryStreamManagerInitialized(blockSize, largeBufferMultiple, maximumBufferSize); } @@ -479,41 +478,17 @@ internal void ReturnBlocks(ICollection blocks, string tag) LargePoolFreeSize); } - internal void ReportBlockCreated() - { - Counter.ReportBlockCreated(); - BlockCreated?.Invoke(); - } + internal void ReportBlockCreated() => BlockCreated?.Invoke(); - internal void ReportBlockDiscarded() - { - Counter.ReportBlockDiscarded(); - BlockDiscarded?.Invoke(); - } + internal void ReportBlockDiscarded() => BlockDiscarded?.Invoke(); - internal void ReportLargeBufferCreated() - { - Counter.ReportLargeBufferCreated(); - LargeBufferCreated?.Invoke(); - } + internal void ReportLargeBufferCreated() => LargeBufferCreated?.Invoke(); - internal void ReportLargeBufferDiscarded(Events.MemoryStreamDiscardReason reason) - { - Counter.ReportLargeBufferDiscarded(); - LargeBufferDiscarded?.Invoke(reason); - } + internal void ReportLargeBufferDiscarded(Events.MemoryStreamDiscardReason reason) => LargeBufferDiscarded?.Invoke(reason); - internal void ReportStreamCreated() - { - Counter.ReportStreamCreated(); - StreamCreated?.Invoke(); - } + internal void ReportStreamCreated() => StreamCreated?.Invoke(); - internal void ReportStreamDisposed() - { - Counter.ReportStreamDisposed(); - StreamDisposed?.Invoke(); - } + internal void ReportStreamDisposed() => StreamDisposed?.Invoke(); internal void ReportStreamFinalized() => StreamFinalized?.Invoke(); @@ -536,14 +511,7 @@ private class ReportingMemoryStream : MemoryStream { private readonly RecyclableMemoryStreamManager _instance; - public ReportingMemoryStream(byte[] bytes, RecyclableMemoryStreamManager instance) : base(bytes) - { - _instance = instance; - _instance.Counter.ReportStreamCreated(); - } - - //NOTE DisposeAsync calls Dispose as well - protected override void Dispose(bool disposing) => _instance.Counter.ReportStreamDisposed(); + public ReportingMemoryStream(byte[] bytes, RecyclableMemoryStreamManager instance) : base(bytes) => _instance = instance; } ///