AddressTableEventSource.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Diagnostics.Tracing;
  2. namespace ARMeilleure.Diagnostics.EventSources
  3. {
  4. [EventSource(Name = "ARMeilleure")]
  5. class AddressTableEventSource : EventSource
  6. {
  7. public static readonly AddressTableEventSource Log = new();
  8. private ulong _size;
  9. private ulong _leafSize;
  10. private PollingCounter _sizeCounter;
  11. private PollingCounter _leafSizeCounter;
  12. public AddressTableEventSource()
  13. {
  14. _sizeCounter = new PollingCounter("addr-tab-alloc", this, () => _size / 1024d / 1024d)
  15. {
  16. DisplayName = "AddressTable Total Bytes Allocated",
  17. DisplayUnits = "MB"
  18. };
  19. _leafSizeCounter = new PollingCounter("addr-tab-leaf-alloc", this, () => _leafSize / 1024d / 1024d)
  20. {
  21. DisplayName = "AddressTable Total Leaf Bytes Allocated",
  22. DisplayUnits = "MB"
  23. };
  24. }
  25. public void Allocated(int bytes, bool leaf)
  26. {
  27. _size += (uint)bytes;
  28. if (leaf)
  29. {
  30. _leafSize += (uint)bytes;
  31. }
  32. }
  33. protected override void Dispose(bool disposing)
  34. {
  35. _leafSizeCounter.Dispose();
  36. _leafSizeCounter = null;
  37. _sizeCounter.Dispose();
  38. _sizeCounter = null;
  39. base.Dispose(disposing);
  40. }
  41. }
  42. }