aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Diagnostics/EventSources/AddressTableEventSource.cs
blob: 201a25623c174c45456dcc2058284298d11a4052 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Diagnostics.Tracing;

namespace ARMeilleure.Diagnostics.EventSources
{
    [EventSource(Name = "ARMeilleure")]
    class AddressTableEventSource : EventSource
    {
        public static readonly AddressTableEventSource Log = new();

        private ulong _size;
        private ulong _leafSize;
        private PollingCounter _sizeCounter;
        private PollingCounter _leafSizeCounter;

        public AddressTableEventSource()
        {
            _sizeCounter = new PollingCounter("addr-tab-alloc", this, () => _size / 1024d / 1024d)
            {
                DisplayName = "AddressTable Total Bytes Allocated",
                DisplayUnits = "MB"
            };

            _leafSizeCounter = new PollingCounter("addr-tab-leaf-alloc", this, () => _leafSize / 1024d / 1024d)
            {
                DisplayName = "AddressTable Total Leaf Bytes Allocated",
                DisplayUnits = "MB"
            };
        }

        public void Allocated(int bytes, bool leaf)
        {
            _size += (uint)bytes;

            if (leaf)
            {
                _leafSize += (uint)bytes;
            }
        }

        protected override void Dispose(bool disposing)
        {
            _leafSizeCounter.Dispose();
            _leafSizeCounter = null;

            _sizeCounter.Dispose();
            _sizeCounter = null;

            base.Dispose(disposing);
        }
    }
}