Commit ccc1e1a3 authored by Marc Gravell's avatar Marc Gravell

Merge pull request #363 from JonCole/master

Capture client system CPU percentage in timeout error messages
parents 59a7cb68 dc201866
......@@ -1968,6 +1968,8 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser
add("ThreadPool-IO-Completion", "IOCP", iocp);
add("ThreadPool-Workers", "WORKER", worker);
data.Add(Tuple.Create("Busy-Workers", busyWorkerCount.ToString()));
add("Local-CPU", "Local-CPU", GetSystemCpuPercent());
#endif
errMessage = sb.ToString();
if (stormLogThreshold >= 0 && queue >= stormLogThreshold && Interlocked.CompareExchange(ref haveStormLog, 1, 0) == 0)
......@@ -2000,6 +2002,16 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser
}
#if !CORE_CLR
private static string GetSystemCpuPercent()
{
float systemCPU;
if (PerfCounterHelper.TryGetSystemCPU(out systemCPU))
{
return Math.Round(systemCPU, 2) + "%";
}
return "unavailable";
}
private static int GetThreadPoolStats(out string iocp, out string worker)
{
//BusyThreads = TP.GetMaxThreads() –TP.GetAVailable();
......
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
......@@ -297,6 +298,53 @@ public enum CompletionType
Async = 2
}
#if !CORE_CLR
internal static class PerfCounterHelper
{
static object staticLock = new object();
static volatile PerformanceCounter _cpu;
static volatile bool _disabled;
public static bool TryGetSystemCPU(out float value)
{
value = -1;
try
{
if (!_disabled && _cpu == null)
{
lock (staticLock)
{
if (_cpu == null)
{
_cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
// First call always returns 0, so get that out of the way.
_cpu.NextValue();
}
}
}
}
catch (UnauthorizedAccessException)
{
// Some environments don't allow access to Performance Counters, so stop trying.
_disabled = true;
}
catch (Exception)
{
// this shouldn't happen, but just being safe...
}
if (_cpu != null)
{
value = _cpu.NextValue();
return true;
}
return false;
}
}
internal class CompletionTypeHelper
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment