2013-04-24 17 views
8

Belirli bir işlem için CPU, Bellek ve Ağ kullanımı için .NET performans sayacını kullanan bir program yazıyorum.Belirli bir işlem için ağ performansını izleyin

Örneğin, Explorer için CPU ve Bellek veri almak için, böyle performans sayaçlarını oluşturun:

PerformanceCounter PC = new PerformanceCounter(); 
PC.CategoryName = "Process"; 
PC.CounterName = "% Processor Time"; 
PC.InstanceName = "Explorer"; 

PerformanceCounter PC = new PerformanceCounter(); 
PC.CategoryName = "Process"; 
PC.CounterName = "Working Set - Private"; 
PC.InstanceName = "Explorer"; 

Maalesef bana bunun için ağ kullanımını ulaşmasını sağlar Süreci categoryName için hiçbir özellik yoktur süreci. Belirli bir NIC'de genel ağ kullanımı elde etmek için Ağ Arabirimi categoryName'u kullanabilirim, ancak herhangi bir belirli Süreç'e ayıramaz.

+0

Daha önce sorulan benzer bir şey var gibi görünüyor: http: //stackoverflow.com/questions/438240/monitor-a-processs-network-usage – Dilshod

+2

Bu bir mimari sınırlamadır. Bu sayaçlar ağ sürücüsü yığını tarafından uygulanır. Hangi çekirdek modunda çalışır, bu süreçte usermode sahip değildir. FileSystemWatcher'ın, hangi işlemin bir dosyayı değiştirdiğini size söyleyememesinin de bir nedeni. –

cevap

0

Sanırım yalnızca tüm sistem için ağ kullanımını alabilirsiniz. Yalnızca Microsoft erişmesini 's istediğiniz değerleri alabilir, PerformanceCounters ile

GetCounterValue(_netRecvCounters[index], "Network Interface", "Bytes Received/sec",  _instanceNames[index]): 

double GetCounterValue(PerformanceCounter pc, string categoryName, string counterName, string instanceName) 
{ 
    pc.CategoryName = categoryName; 
    pc.CounterName = counterName; 
    pc.InstanceName = instanceName; 
    return pc.NextValue(); 
} 

: Bu kodu kullanabilirsiniz.

İlgili konular