Most efficient and fundamental way to get cpu % usage and network throughput on Windows?

1.6k views Asked by At

What is the most efficient and fundamental way to get cpu % usage and network throughput on windows platform?

Correct Me If I'm Wrong...

  1. windows api // Win32? SDK? (c/c++) #sorry, I have no idea...
  2. Windows Management Instrumentation (WMI),
    • Win32_PerfFormattedData_Tcpip_NetworkInterface class BytesReceivedPerSec
    • Win32_PerfRawData_PerfOS_Processor class PercentProcessorTime
  3. System.Diagnostics PerformanceCounter
  4. Performance Data Helper (PDH) , pdh.dll
  5. PerformanceCounter (c#/.net framework) or another nowaday method?
  6. NtQuerySystemInformation in ntdll.dll

So what is the best way to get this values, could I only import windows.h and kernel32.dll to get both cpu percent usage and network interface speed values?

thanks

2

There are 2 answers

0
AudioBubble On

In C++ I would use PdhOpenQuery, PdhAddCounter, etc... Don't know for C#, but I guess there is something available in .NET.

9
Richard On

what is the best way

Depends on the rest of the program. In .NET (noting the C# tag on the question) both WMI and Performance Counters are easy to access.

From Win32 API, if you are using COM already WMI might be the easiest as reading Performance Data needs significant boilerplate code (whatever API you start from).