获取特定进程在c ++/windows中的当前cpu用法 [英] Getting current cpu usage in c++/windows for particular process

查看:207
本文介绍了获取特定进程在c ++/windows中的当前cpu用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在代码中计算特定应用程序的当前cpu使用率.我在互联网上查找并找到了用于Windows的pdh库.当我尝试使用它时,我得到的是总体CPU使用率,而不是一个进程的CPU使用率.

I want to calculate current cpu usage for particular application in my code. I looked up on internet and found pdh library for windows. When I tried it I am getting overall cpu usage not cpu usage for one process.

PdhAddCounter(hquery, TEXT("\\Processor(_Total)\\% Processor Time"),0,&counter);

那么我要如何使用此行来获取特定进程的cpu使用率?我尝试将 _Total 替换为进程名称(浏览器).当时我的CPU使用率为0.但是我检查了资源监视器,一次打开许多窗口将cpu的使用率提高了20%.仍然在日志文件中,CPU使用率显示为0.

So what I do with this line to get cpu usage for particular process? I tried replacing _Total with process name(explorer). At that time I am getting 0 cpu usage. But I checked in resource monitor that opening many windows at a time increased cpu usage upto 20%. Still in log file cpu usage is showing 0.

有人可以帮我吗?

提前谢谢.

推荐答案

您可以检查.解释了该项目中的所有内容.它将基于进程ID(与任务管理器中显示的方式相同)提供内存

You can check this for example. Explained everything in that project. It will give memory based on process id(same way shown in task manager)

谢谢, 达山

这篇关于获取特定进程在c ++/windows中的当前cpu用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆