aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Diagnostics/TranslatorEventSource.cs
blob: 2e1be8c51db0756495b5264b7108b9e4c6c90f20 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Diagnostics.Tracing;
using System.Threading;

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

        private int _rejitQueue;
        private ulong _funcTabSize;
        private ulong _funcTabLeafSize;
        private PollingCounter _rejitQueueCounter;
        private PollingCounter _funcTabSizeCounter;
        private PollingCounter _funcTabLeafSizeCounter;

        public TranslatorEventSource()
        {
            _rejitQueueCounter = new PollingCounter("rejit-queue-length", this, () => _rejitQueue)
            {
                DisplayName = "Rejit Queue Length",
            };

            _funcTabSizeCounter = new PollingCounter("addr-tab-alloc", this, () => _funcTabSize / 1024d / 1024d)
            {
                DisplayName = "AddressTable Total Bytes Allocated",
                DisplayUnits = "MiB",
            };

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

        public void RejitQueueAdd(int count)
        {
            Interlocked.Add(ref _rejitQueue, count);
        }

        public void AddressTableAllocated(int bytes, bool leaf)
        {
            _funcTabSize += (uint)bytes;

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

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

            _funcTabLeafSizeCounter.Dispose();
            _funcTabLeafSizeCounter = null;

            _funcTabSizeCounter.Dispose();
            _funcTabSizeCounter = null;

            base.Dispose(disposing);
        }
    }
}