/ src / ARMeilleure / Diagnostics / TranslatorEventSource.cs
TranslatorEventSource.cs
 1  using System.Diagnostics.Tracing;
 2  using System.Threading;
 3  
 4  namespace ARMeilleure.Diagnostics
 5  {
 6      [EventSource(Name = "ARMeilleure")]
 7      class TranslatorEventSource : EventSource
 8      {
 9          public static readonly TranslatorEventSource Log = new();
10  
11          private int _rejitQueue;
12          private ulong _funcTabSize;
13          private ulong _funcTabLeafSize;
14          private PollingCounter _rejitQueueCounter;
15          private PollingCounter _funcTabSizeCounter;
16          private PollingCounter _funcTabLeafSizeCounter;
17  
18          public TranslatorEventSource()
19          {
20              _rejitQueueCounter = new PollingCounter("rejit-queue-length", this, () => _rejitQueue)
21              {
22                  DisplayName = "Rejit Queue Length",
23              };
24  
25              _funcTabSizeCounter = new PollingCounter("addr-tab-alloc", this, () => _funcTabSize / 1024d / 1024d)
26              {
27                  DisplayName = "AddressTable Total Bytes Allocated",
28                  DisplayUnits = "MiB",
29              };
30  
31              _funcTabLeafSizeCounter = new PollingCounter("addr-tab-leaf-alloc", this, () => _funcTabLeafSize / 1024d / 1024d)
32              {
33                  DisplayName = "AddressTable Total Leaf Bytes Allocated",
34                  DisplayUnits = "MiB",
35              };
36          }
37  
38          public void RejitQueueAdd(int count)
39          {
40              Interlocked.Add(ref _rejitQueue, count);
41          }
42  
43          public void AddressTableAllocated(int bytes, bool leaf)
44          {
45              _funcTabSize += (uint)bytes;
46  
47              if (leaf)
48              {
49                  _funcTabLeafSize += (uint)bytes;
50              }
51          }
52  
53          protected override void Dispose(bool disposing)
54          {
55              _rejitQueueCounter.Dispose();
56              _rejitQueueCounter = null;
57  
58              _funcTabLeafSizeCounter.Dispose();
59              _funcTabLeafSizeCounter = null;
60  
61              _funcTabSizeCounter.Dispose();
62              _funcTabSizeCounter = null;
63  
64              base.Dispose(disposing);
65          }
66      }
67  }