using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using Aitex.Core.RT.Log; using Aitex.Core.Util; namespace MECF.Framework.Common.Utilities { public class PerformanceMonitor { public static DeviceTimer _timer = new DeviceTimer(); public static void TraceLog() { if (_timer.GetElapseTime() < 1000 && !_timer.IsIdle()) return; _timer.Start(0); Action act = () => { try { Process[] processes = Process.GetProcesses(); StringBuilder sb = new StringBuilder(); sb.Append("【System Performance Monitor Report】\r\n"); sb.Append(string.Format("{0,30}", "ProcessName")); sb.Append(string.Format("{0,10}", "PID")); sb.Append(string.Format("{0,10}", "Priority")); sb.Append(string.Format("{0,10}", "Handle")); sb.Append(string.Format("{0,10}", "Thread")); sb.Append(string.Format("{0,15}", "PriMemory(MB)")); sb.Append(string.Format("{0,15}", " WorkingSet(MB)\r\n")); for (int i = 0; i < processes.Length - 1; i++) { var process = processes[i]; sb.Append(string.Format("{0,30}", process.ProcessName)); sb.Append(string.Format("{0,10}", Convert.ToString(process.Id.ToString("0000")))); sb.Append(string.Format("{0,10}", process.BasePriority)); sb.Append(string.Format("{0,10}", process.HandleCount)); sb.Append(string.Format("{0,10}", process.Threads.Count)); sb.Append(string.Format("{0,15}", (process.PrivateMemorySize64 / 1000000.0).ToString("F1"))); ; sb.Append(string.Format("{0,15}", (process.WorkingSet64 / 1000000.0).ToString("F1"))); sb.Append("\r\n"); } LOG.Write(sb.ToString()); } catch (Exception ex) { LOG.Write(ex); } }; act.BeginInvoke(null, null); } } }