public CpuUsage(ProcessUsage processUsage = null, PerformanceCounter counter = null) { if (processUsage != null && counter != null) { SetPercentage(processUsage, counter); } }
public void SetPercentage(ProcessUsage process) { double memory = process.WorkingSet64; double percentage = (memory / SYSTEM_MEMORY) * 100; Percentage = percentage.ToString(); }
public MemoryUsage(ProcessUsage processUsage = null) { if (processUsage != null) { SetValues(processUsage); } }
public bool TryCollectInfo(ProcessUsage processUsageInfo) { if (!PerformanceCounters.ContainsKey(processUsageInfo.Name)) { PerformanceCounters.Add(processUsageInfo.Name, new PerformanceCounter("Process", "Working Set", processUsageInfo.Name, true)); } try { var ram = PerformanceCounters[processUsageInfo.Name].NextValue(); processUsageInfo.Ram = (ram / 1024 / 1024); return(true); } catch { PerformanceCounters[processUsageInfo.Name].Dispose(); PerformanceCounters.Remove(processUsageInfo.Name); } return(false); }
public bool TryCollectInfo(ProcessUsage processUsageInfo) { if (!PerformanceCounters.ContainsKey(processUsageInfo.Name)) { PerformanceCounters.Add(processUsageInfo.Name, new PerformanceCounter("Process", "% Processor Time", processUsageInfo.Name, true)); } try { var cpu = PerformanceCounters[processUsageInfo.Name].NextValue(); processUsageInfo.Cpu = cpu / Environment.ProcessorCount; return(true); } catch { PerformanceCounters[processUsageInfo.Name].Dispose(); PerformanceCounters.Remove(processUsageInfo.Name); } return(false); }
private void SetPercentage(ProcessUsage processUsage, PerformanceCounter counter) { Percentage = Math.Round(counter.NextValue() / Environment.ProcessorCount, 2).ToString(); }
private void SetValues(ProcessUsage processUsage) { SetMB(processUsage); SetPercentage(processUsage); }
public MemoryUsage Update(ProcessUsage processUsage) { SetValues(processUsage); return(this); }
public void SetMB(ProcessUsage processUsage) { MB = (processUsage.WorkingSet64 / BYTE_TO_MEGABYTE_DIVIDER).ToString(); }