简体   繁体   English

如何获取 Windows 中每个正在运行的进程的“专用 GPU 内存”编号(与 Windows 任务管理器中显示的编号相同)

[英]How to get the "Dedicated GPU memory" number for every running process in Windows (The same numbers that are shown in the Windows Task Manager)

The Windows Task Manager, in the "Details" tab, shows the "Dedicated GPU memory" usage for every process. Windows 任务管理器在“详细信息”选项卡中显示每个进程的“专用 GPU 内存”使用情况。 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. 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.我想从我自己的 C++ 代码中获得完全相同的数据。 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.我知道 Windows 任务管理器只有自 Windows 10 以来的数据,我对仅适用于 Windows 10 及更高版本的解决方案很好。

The exact goal of my code is to find every process that uses more than 0.2 GB of Dedicated GPU memory.我的代码的确切目标是找到每个使用超过 0.2 GB 专用 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.我希望这些信息向我的软件用户显示一条消息,建议关闭这些特定进程,因为如果我的软件有尽可能多的 VRAM 可供自己使用,它会运行得更好。

Task manager and third party software are using performance counters to query the dedicated GPU memory information.任务管理器和第三方软件正在使用性能计数器来查询专用的 GPU memory 信息。 For example you can execute these counters from powershell:例如,您可以从 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.您可以使用 PdhAddCounter function 从 c++ 查询相同的计数器。 For example:例如:

PdhAddCounter(..., L"\\GPU Process Memory(*)\\Dedicated Usage", ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM