Is it possible/easy to determine how much power a program is using?
Asked Answered
D

2

6

Is it possible to determine or even reasonably estimate how much power a program is using? The idea being to profile my code in terms of power consumption instead of just typical performance.

Is it enough to measure CPU use, GPU use and memory access?

Delineator answered 3/1, 2014 at 15:51 Comment(5)
run the program standalone and use activity monitor(mac) or task manager/processes(windows)Pyrrhotite
You'd also need to take into account the program's share of the monitor use, sound output, networking (both WiFi and wired), increased use of AC and lighting in the room the machine is in, etc. Would the computer be asleep or off if the program were not running, i.e., is the computer on solely to run the program or are you multitasking? If multitasking, how much efficency is lost switching between processes?Barto
This is a very interesting question, just a lot to consider. I read a report some years ago that tried to calculate how much energy a single Google search used. Of course, I don't have a reference or remember what the result was, but it was surprisingly high for one button click.Barto
@SamD, as far as I can tell Activity Monitor doesn't have a "power" column. Is there some other way to use Activity Monitor to find this?Delineator
@iamnotmaynard, it'd be great to even know which of these different contributor's were the "power bottleneck" for a given program. Is there a way to determine even that?Delineator
G
4

There are many aspects that can influence the power consumption of an application, and these will vary a lot depending on the used hardware.

The easiest way to get an idea is to measure it. If your program is doing heavy calculations, it is quite simple to measure the difference. Just read out the usage while the app is running, and subtract the usage while not.

If your app is not of the heavy calculations kind, then the challenge is allot bigger, since a simple 1 point in time comparison will not do the trick. You could get a measuring device that can log usage over time, which log you would need to compare with the logged process activity of your machine and try to filter all other scheduled tasks (checks for updates etc) out.

Just a tip if you want to go this way, APC's UPS's come with this functionality built-in, and the PowerChute software stores a power consumption log in an Access Database (C:\Program Files\APC\PowerChute Personal Edition\EnergyLog.mdb). I'm not sure if this is true for all models, but it was a nice extra feature that came with mine (Pro 550). I would lay the data alongside an Xperf trace (the free built in profiler in Windows, look here for an overview), in order to correlate power variations with your applications activity, and filter out scheduled jobs etc...

That said, remember you will get different results on different hardware. An ssd will differ from a tradational harddisk, and the used grafix adapter can also make a difference, so you could only get a rough estimation overall, by measuring on a "typical" system. Desktop systems will consume allot more than laptops, etc... (also see this blogpost).

Power consumption profiling tools are allot more common for mobile devices. I'm not an expert in that field, but I know there are quite some tools out there.

Greenlet answered 4/1, 2014 at 11:44 Comment(0)
C
1

There is a project that allows you to get power consumption of a given program of PID on Linux, requiring no hardware: scaphandre

With that you could create grafana dashboards to follow the power consumption of a given project from one release to another. Examples can be seen here.

Connaught answered 11/1, 2021 at 11:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.