PDA

View Full Version : سوال: PerformanceCounter class درصداستفاده ازcpu درسیستم های multi core



me_elsagh
دوشنبه 30 آذر 1388, 15:44 عصر
بااستفاده ازPerformanceCounter class درصداستفاده ازcpu به دست آمده اما برای سیتم هایی که چندهسته ای هستند جمع درصدها از100بیشترمیشود خواهشا راهنمایی کنید

AliRezaPro
دوشنبه 30 آذر 1388, 20:31 عصر
این یک متد بسیار مفید برای مونیتور کردن سیستم و درصد استفاده شده از رم و سی پی یو است.
First you have to create the 2 performance counters
using the System.Diagnostics.PerformanceCounter class.
*/

protected PerformanceCounter cpuCounter;
protected PerformanceCounter ramCounter;

cpuCounter = new PerformanceCounter();

cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";

ramCounter = new PerformanceCounter("Memory", "Available MBytes");

/*
Call this method every time you need to know
the current cpu usage.
*/

public string getCurrentCpuUsage(){
cpuCounter.NextValue()+"%";
}

/*
Call this method every time you need to get
the amount of the available RAM in Mb
*/
public string getAvailableRAM(){
ramCounter.NextValue()+"Mb";
}

me_elsagh
سه شنبه 01 دی 1388, 08:49 صبح
باتشکر این کد شمابرروی سیستم تک هسته ای جواب میدهد نه برروی چند هسته ای درضمن این کدزمان کل پروسس رانمایش می دهد نه هر پروسه جدا

AliRezaPro
سه شنبه 01 دی 1388, 09:24 صبح
این برای Multi Processor یا Multi Core است.

http://www.codeproject.com/KB/system/CpuUsage.aspx?msg=1898449