Add threading-related runtime counters (#24304)
authorSung Yoon Whang <suwhang@microsoft.com>
Thu, 2 May 2019 06:47:04 +0000 (23:47 -0700)
committerGitHub <noreply@github.com>
Thu, 2 May 2019 06:47:04 +0000 (23:47 -0700)
* Add threadpool/contention counters

* fix build error

src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs

index 2ed3400..12b1f9f 100644 (file)
@@ -3,6 +3,9 @@
 // See the LICENSE file in the project root for more information.
 
 #nullable enable
+
+using System.Threading;
+
 namespace System.Diagnostics.Tracing
 {
     /// <summary>
@@ -19,6 +22,9 @@ namespace System.Diagnostics.Tracing
         private IncrementingPollingCounter? _exceptionCounter;
         private PollingCounter? _cpuTimeCounter;
         private PollingCounter? _workingSetCounter;
+        private PollingCounter? _threadPoolThreadCounter;
+        private IncrementingPollingCounter? _monitorContentionCounter;
+        private PollingCounter? _threadPoolQueueCounter;
 
         private const int EnabledPollingIntervalMilliseconds = 1000; // 1 second
 
@@ -47,6 +53,9 @@ namespace System.Diagnostics.Tracing
                 _gen1GCCounter = _gen1GCCounter ?? new IncrementingPollingCounter("gen-1-gc-count", this, () => GC.CollectionCount(1)) { DisplayName = "Gen 1 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0) };
                 _gen2GCCounter = _gen2GCCounter ?? new IncrementingPollingCounter("gen-2-gc-count", this, () => GC.CollectionCount(2)) { DisplayName = "Gen 2 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0) };
                 _exceptionCounter = _exceptionCounter ?? new IncrementingPollingCounter("exception-count", this, () => Exception.GetExceptionCount()) { DisplayName = "Exception Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
+                _threadPoolThreadCounter = _threadPoolThreadCounter ?? new PollingCounter("threadpool-thread-count", this, () => ThreadPool.ThreadCount) { DisplayName = "ThreadPool Thread Count" };
+                _monitorContentionCounter = _monitorContentionCounter ?? new IncrementingPollingCounter("monitor-lock-contention-count", this, () => Monitor.LockContentionCount) { DisplayName = "Monitor Lock Contention Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; 
+                _threadPoolQueueCounter = _threadPoolQueueCounter ?? new PollingCounter("threadpool-queue-length", this, () => ThreadPool.PendingWorkItemCount) { DisplayName = "ThreadPool Queue Length" };
             }
         }
     }