public static PerfomanceInfoData GetPerformanceInfo() { PerfomanceInfoData data = new PerfomanceInfoData(); PsApiPerformanceInformation perfInfo = new PsApiPerformanceInformation(); if (GetPerformanceInfo(out perfInfo, Marshal.SizeOf(perfInfo))) { /// data in pages data.CommitTotalPages = perfInfo.CommitTotal.ToInt64(); data.CommitLimitPages = perfInfo.CommitLimit.ToInt64(); data.CommitPeakPages = perfInfo.CommitPeak.ToInt64(); /// data in bytes Int64 pageSize = perfInfo.PageSize.ToInt64(); data.PhysicalTotalBytes = perfInfo.PhysicalTotal.ToInt64() * pageSize; data.PhysicalAvailableBytes = perfInfo.PhysicalAvailable.ToInt64() * pageSize; data.SystemCacheBytes = perfInfo.SystemCache.ToInt64() * pageSize; data.KernelTotalBytes = perfInfo.KernelTotal.ToInt64() * pageSize; data.KernelPagedBytes = perfInfo.KernelPaged.ToInt64() * pageSize; data.KernelNonPagedBytes = perfInfo.KernelNonPaged.ToInt64() * pageSize; data.PageSizeBytes = pageSize; /// counters data.HandlesCount = perfInfo.HandlesCount; data.ProcessCount = perfInfo.ProcessCount; data.ThreadCount = perfInfo.ThreadCount; } return(data); }
public PerformanceInfo CheckParameters() { PerformanceInfo perfInfo = new PerformanceInfo(); var today = DateTime.Now; PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); PerfomanceInfoData perfData = PsApiWrapper.GetPerformanceInfo(); CounterSample cs1 = cpuCounter.NextSample(); System.Threading.Thread.Sleep(100); CounterSample cs2 = cpuCounter.NextSample(); perfInfo.CpuPercentUsage = CounterSample.Calculate(cs1, cs2); perfInfo.CommitTotalPages = perfData.CommitTotalPages; perfInfo.PageSizeMB = Math.Round((double)perfData.PageSizeBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero); perfInfo.PhysicalAvailableMB = Math.Round((double)perfData.PhysicalAvailableBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero); perfInfo.PhysicalTotalMB = Math.Round((double)perfData.PhysicalTotalBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero); perfInfo.ThreadCount = perfData.ThreadCount; perfInfo.ProcessCount = perfData.ProcessCount; perfInfo.Time = today.ToString("yyyy-MM-dd HH:mm:ss"); logger.Info("Performance details chcecked succesfully"); return(perfInfo); }