I am writing code for a C++ application foo.exe. Inside the application, I want to log its address space usage. So the performance counter I want to look at is "\Process(foo)\Virtual Bytes". The problem I am encountering is that there may be multiple instances of foo.exe running on the system. In perfmon, I can see that these are referenced as "\Process(foo#2)\Virtual Bytes" where the #2 could be any number depending on the number of processes.
How can I construct a counter path to get the virtual bytes for the current process that handles the case where there are multiples instances of the process?