How to get a Windows performance counter for the current process

I am writing code for a C ++ application foo.exe. Inside the application, I want to write its address space. So the performance counter that I want to pay attention to is "\ Process (foo) \ Virtual Bytes". The problem I am facing is that there may be multiple instances of foo.exe in the system. In perfmon, I see that they are referenced as "\ Process (foo # 2) \ Virtual Bytes", where # 2 can be any number depending on the number of processes.

How can I build a counter path to get virtual bytes for the current process that handles the case when there are multiple process instances?

+3
source share
2 answers

Your instance has a counter value ID Processcorresponding to your current process ID. Unfortunately, there is no other way than to get all the instances and list them until you find an instance that is yours, but this is pretty trivial.

+4
source

If you need a virtual byte (or other memory statistics) for your process, it is much easier to use GetProcessMemoryInfo , as described in How to Define a Virtual Size (WinXP) Process? .

+1
source

Source: https://habr.com/ru/post/1779117/


All Articles