Programing

프로세스의 CPU 및 메모리 사용량을 얻기위한 올바른 성능 카운터는 무엇입니까?

lottogame 2020. 11. 21. 08:19
반응형

프로세스의 CPU 및 메모리 사용량을 얻기위한 올바른 성능 카운터는 무엇입니까?


.NET 클래스를 사용하여 특정 프로세스 CPU메모리 사용량어떻게 얻을 수 PerformanceCounter있습니까? 그리고 또한 차이점은 무엇입니까

Processor\% Processor Time그리고 Process\% Processor Time?

이 둘 사이에 약간 혼란 스러워요.


에서 게시물 :

전체 PC CPU 및 메모리 사용량을 확인하려면 :

using System.Diagnostics;

그런 다음 전역 적으로 선언합니다.

private PerformanceCounter theCPUCounter = 
   new PerformanceCounter("Processor", "% Processor Time", "_Total"); 

그런 다음 CPU 시간을 얻으려면 NextValue()메서드 를 호출하면 됩니다.

this.theCPUCounter.NextValue();

이것은 당신에게 CPU 사용량을 얻을 것입니다

메모리 사용량에 관해서는 동일한 것이 적용됩니다.

private PerformanceCounter theMemCounter = 
   new PerformanceCounter("Memory", "Available MBytes");

그런 다음 메모리 사용량을 확인하려면 NextValue()메서드 를 호출하면 됩니다.

this.theMemCounter.NextValue();

특정 프로세스 CPU 및 메모리 사용량의 경우 :

private PerformanceCounter theCPUCounter = 
   new PerformanceCounter("Process", "% Processor Time",              
   Process.GetCurrentProcess().ProcessName);

Process.GetCurrentProcess().ProcessName정보를 얻으려는 프로세스 이름은 어디에 있습니까 ?

private PerformanceCounter theMemCounter = 
   new PerformanceCounter("Process", "Working Set",
   Process.GetCurrentProcess().ProcessName);

Process.GetCurrentProcess().ProcessName정보를 얻으려는 프로세스 이름은 어디에 있습니까 ?

참고 작업 집합은 프로세스의 메모리 풋 프린트를 결정하는 그 자체로 충분하지 않을 수 있습니다 참조 - 개인 바이트, 가상 바이트 작업 집합 무엇입니까?

모든 범주를 검색하려면 연습 : 범주 및 카운터 검색을 참조하십시오 .

차이 Processor\% Processor TimeProcess\% Processor Time된다 Processor는 PC 자체이며 Process개별 프로세스 당이다. 따라서 프로세서의 프로세서 시간은 PC에서의 사용량입니다. 프로세스의 프로세서 시간은 지정된 프로세스 사용량입니다. 범주 이름에 대한 전체 설명 : 성능 모니터 카운터

성능 카운터 사용에 대한 대안

사용 System.Diagnostics.Process.TotalProcessorTimeSystem.Diagnostics.ProcessThread.TotalProcessorTime의 이 같은 특성은 프로세서 사용량을 계산하는 문서 에 대해 설명합니다.


Pelo Hyper-V :

private PerformanceCounter theMemCounter = new PerformanceCounter(
    "Hyper-v Dynamic Memory VM",
    "Physical Memory",
    Process.GetCurrentProcess().ProcessName); 

참고 URL : https://stackoverflow.com/questions/4679962/what-is-the-correct-performance-counter-to-get-cpu-and-memory-usage-of-a-process

반응형