The Windows Task Manager, in the "Details" tab, shows the "Dedicated GPU memory" usage for every process. For example, I can currently see that chrome.exe uses 1.4 GB Dedicated GPU memory, dwm.exe uses 1.3 GB Dedicated GPU memory, and firefox.exe uses 0.78 GB Dedicated GPU memory.
I want to get that exact same data from my own C code. How can I do that in the easiest way?
I know that the Windows Task Manager only has that data since Windows 10, and I am fine with a solution that only works on Windows 10 and above.
The exact goal of my code is to find every process that uses more than 0.2 GB of Dedicated GPU memory. I want to have that information to show a message to the user of my software recommending closing those specific processes, because my software will run better if it has as much VRAM as possible available for itself.
CodePudding user response:
Task manager and third party software are using performance counters to query the dedicated GPU memory information. For example you can execute these counters from powershell:
Get-Counter -Counter "\GPU Engine(*)\*"
Get-Counter -Counter "\GPU Engine(*)\Running Time"
Get-Counter -Counter "\GPU Engine(*)\Utilization Percentage"
Get-Counter -Counter "\GPU Local Adapter Memory(*)\*"
Get-Counter -Counter "\GPU Local Adapter Memory(*)\Local Usage"
Get-Counter -Counter "\GPU Non Local Adapter Memory(*)\*"
Get-Counter -Counter "\GPU Non Local Adapter Memory(*)\Non Local Usage"
Get-Counter -Counter "\GPU Process Memory(*)\*"
Get-Counter -Counter "\GPU Process Memory(*)\Dedicated Usage"
Get-Counter -Counter "\GPU Process Memory(*)\Local Usage"
Get-Counter -Counter "\GPU Process Memory(*)\Non Local Usage"
Get-Counter -Counter "\GPU Process Memory(*)\Shared Usage"
Get-Counter -Counter "\GPU Process Memory(*)\Total Committed"
You can query the same counters from c using the PdhAddCounter function. For example:
PdhAddCounter(..., L"\\GPU Process Memory(*)\\Dedicated Usage", ...)