Reputation: 3308
I have a code ( in c# ) for managed all process starded in my computer.
I use the PerformanceCounter class for find all values linked in one specific process.
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.
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.
Thanks.
Upvotes: 4
Views: 973
Reputation: 6101
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.
Upvotes: 4