How can I get Windows data like CPU usage, etc.?
Asked Answered
O

2

5

How can I get Windows data like CPU usage, physical memory, and network utilization and bandwidth, similar to what I see in Task Manager? I'm using C++.

Ossetic answered 1/6, 2012 at 4:57 Comment(0)
A
7

You can get CPU usage using the performance data. If you want data for only one (or a few processes) it may be simpler to call GetProcessTimes every few seconds.

It's generally difficult to pin down exactly what physical memory usage even means. Until you do, trying to describe how to measure it is pretty pointless.

You can get some information about network utilization with GetIpStatistics.

You can get the rated bandwidths of the installed network adapters with GetIfTable.

Assiut answered 1/6, 2012 at 5:10 Comment(7)
Yes, I get cpu usage by GetProcessTimes, get memory usage by GlobalMemoryStatusExOssetic
Can you explain how to get bandwidth with those functions. I tried. But I can't. ThanksOssetic
GetIfTable gives you some MIB_IFROW structures. Each has a dwSpeed member, which is the rated speed of that interface.Assiut
It seem that dwSpeed is const (when I download something, it's not change value). It's not bit race of internet connection (Local Area Connection interface)Ossetic
My computer have some interface: Locale Area Connection, VMware Network Adapter VMnet1, VMware Network Adapter VMnet8, a VPN TAP-Win32 Adapter. I disable all excluded Locale Area Connection -> in Task Manager I just see information for Locale Area Connection. But when I run the example in GetIfTable's link, I got 26 interfaces -> How to determine which interface is for current connection to internet? Thanks a lot.Ossetic
@aviit: dwSpeed tells you the theoretical maximum bandwidth of the adapter. dwInOctets tells you how many bytes you've received, and dwOutOctets how many you've sent (you sample the latter at intervals to find how much you've sent/received per second). dwType will tell you what sort of interface you're looking at (you mostly care about Ethernet, WANPPP, 802.11, WANPPP2 and possibly PPP, but almost certainly not tunnels, ATM, FDDI, loopback, etc.)Assiut
@aviit: I should probably add: if you can restrict your code to Windows Vista (or newer), you might want to use GetIfTable2 instead. A MIB_IF_ROW2 includes quite a bit more information, including a member to specifically tell you whether an interface represents actual hardware.Assiut
S
2

Look Performance Counters in msdn

Synder answered 1/6, 2012 at 5:13 Comment(2)
I saw that. But, it too difficult to understand and use. :). ThanksOssetic
Though that's just what Process Explorer (and likely Task Manager) uses, too. :)Tramline

© 2022 - 2024 — McMap. All rights reserved.