TranslatorEventSource.cs 2.0 KB

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