按进程获取电池使用情况 [英] Get Battery Usage By Process

查看:43
本文介绍了按进程获取电池使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码(在 c# 中)用于管理在我的计算机中启动的所有进程.

I have a code ( in c# ) for managed all process starded in my computer.

我使用 PerformanceCounter 用于查找在一个特定过程中链接的所有值的类.

I use the PerformanceCounter class for find all values linked in one specific process.

例如,此代码检索了 firefox 的处理器时间使用:

For sample, this code retrived the Processor Time use for firefox:

PerformanceCounter processorTime = new PerformanceCounter("Process", "% Processor Time", "firefox");

double processTime = 0;

while(true){
    processTime = processorTime.NextValue();
}

另外,我知道如何检索我的电池百分比:

Also, I know how to retrieved the percentage of my battery :

PowerStatus power = SystemInformation.PowerStatus;
float secondsRemaining = power.BatteryLifePercent;
if (secondsRemaining >= 0)
{
    kpiBattery.batteryLevel = (secondsRemaining * 100).ToString();
}

我想按流程获取电池使用情况,而不是全局.

I want to get the usage battery BY PROCESS, and not global.

例如,在使用firefox"的过程中,谁使用了多少电池?

For sample, during the process "firefox" is use, who many battery was using?

我知道我想在进程启动和进程终止时获取电池电量,并有所作为,但是,这不是真正的电量使用水平,因为在开始和结束时间进程之间,可能还有很多其他进程运行,也消耗电池.

I KNOW I want to get Battery level when process was started and when process was killed, and make the difference, but, it's NOT true level battery use, bacause, between start and end time process, maybe lot of other process was running, and consumes battery too.

如果您有任何想法,或者您知道解决方案,我非常感兴趣.

If you have any idea, or if you know the solution, I'm very interested.

谢谢.

推荐答案

正如您已经说过的,许多进程可以同时运行.此外,电池使用率与 CPU 使用率没有直接关系.它可能是硬盘活动、图形芯片等.因此,无法计算每个进程的充足电池使用量.

As you have already said, a lot of process could be running simultaneously. Moreover, the battery usage is not directly related to the CPU usage. It could be HDD activity, graphic chip and so on. So, there are no way to calculate an adequate battery usage per process.

这篇关于按进程获取电池使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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