/// <summary> /// Returns a string describing the Thread /// </summary> /// <returns></returns> public override string ToString() { return(String.Format("Usage Process/System: {5}%/{6}%; Name: {0}; ThreadID: {1}; IsCancelled: {2}; " + "IsUnResponsive: {3}; IsMarkedForRemoval: {4}", Name, ThreadID, Cancelled, _unresponsive, _markedForRemoval, ProcessCpuUsage.ToString("n1"), SystemCpuUsage.ToString("n1"))); }
public async Task ProcessCpuUsage_ProcessNotFound_Test() { var widget = new ProcessCpuUsage { ProcessName = "DoesNotExist" }; var request = MetricQueryRequest.Create(widget); var handler = new ProcessCpuUsageQuery(); await handler.Handle(request, CancellationToken.None).ConfigureAwait(false); }
public async Task ProcessCpuUsageTest() { var widget = new ProcessCpuUsage { ProcessName = "System", }; var request = MetricQueryRequest.Create(widget); var handler = new ProcessCpuUsageQuery(); await handler.Handle(request, CancellationToken.None).ConfigureAwait(false); Assert.AreEqual(State.Ok, widget.State); }
/// <summary> /// When used in .NET Core not supported monitoring of privileged time. /// </summary> /// <param name="monitorPrivilegedTime">If truth be monitored the privileged time. Not supported for .Net core.</param> /// <param name="monitorProcessorTime">If truth be monitored the processor time.</param> /// <param name="monitorUserTime">If truth be monitored the user time.</param> /// <param name="monitorPeriodInMilliseconds">The time interval between invocations of refresh, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.</param> public CPUMonitor(bool monitorPrivilegedTime, bool monitorProcessorTime, bool monitorUserTime, int monitorPeriodInMilliseconds = 500) { if (!monitorPrivilegedTime && !monitorProcessorTime && !monitorUserTime) { throw new ArgumentException("At least one flag has to be true."); } this.monitorPrivilegedTime = monitorPrivilegedTime; this.monitorProcessorTime = monitorProcessorTime; this.monitorUserTime = monitorUserTime; this.monitorPeriodInMilliseconds = monitorPeriodInMilliseconds; #if NETFX_CORE if (monitorPrivilegedTime) { throw new NotSupportedException("Not support in .Net Core."); } CurrentProcess = ProcessDiagnosticInfo.GetForCurrentProcess().CpuUsage; #else string processName = Process.GetCurrentProcess().ProcessName; if (monitorPrivilegedTime) { privilegedTimeCounter = new PerformanceCounter("Process", "% Privileged Time", processName); } if (monitorProcessorTime) { processorTimeCounter = new PerformanceCounter("Process", "% Processor Time", processName); } if (monitorUserTime) { userTimeCounter = new PerformanceCounter("Process", "% User Time", processName); } #endif timer = new Timer(DoMonitor, null, Timeout.Infinite, MonitorPeriodInMilliseconds); }