Measuring my application's power consumption

S

Scott Gifford

Hello,

I'd like to try out a few different implementations of part of my
application to see which is most power efficient. I need to send data
across the network, and I'd like to experiment with UDP vs. TCP, cost
of setting up and tearing down the Internet connection every time,
etc.

To measure power consumption, I'm getting battery status information
by P/Invoking GetSystemPowerStatusEx2. I'm following this
example:

http://msdn2.microsoft.com/en-us/library/aa457088.aspx

and using this documentation for the fields:

http://msdn2.microsoft.com/en-us/library/ms941842.aspx

Everything seems to be working correctly, except that many of the
fields are always zero. In fact, for the primary battery (not the
backup) I only get BatteryVoltage, BatteryLifePercent, BatteryFlag,
and BatteryChemistry. And BatteryLifePercent seems to go down in 5%
intervals, which doesn't give much precision.

My questions are:

* Is there a better way to measure power consumption of an
application, or to get power status information from within .NET?

* Is it surprising that so many of these values would be zero? I'm
disappointed I can't get BatterymAHourConsumed, as it seemed like
it would measure exactly what I wanted.

* Is the delta in battery voltage a reasonable way to measure power
consumption, and is it linear? For example, if in one run
BatteryVoltage drops from 4000 to 3900, and in another it drops
from 3900 to 3800, is it reasonable to assume that they both
consumed about the same amount of power? Is there some place I
can find documentation on this?

Thanks for any thoughts!

---Scott.
 
P

patilmmilind

Hi,

1) Which device you are using ?

2) What is the return value from GetLastError() ?
//Pinvoke signature
[DllImport("coredll.dll", EntryPoint="GetSystemPowerStatusEx2",
SetLastError=true)]

Length of the data returned in the pSystemPowerStatusEx2 buffer
indicates success. Zero indicates failure

3) See the following example, If your application is interested in the
BatteryFlag, BackupBatteryFlag and/or BatteryChemistry elements, you
may wish to implement enum(s) similar to what author did for
ACLineStatus.

http://blogs.msdn.com/davidklinems/archive/2005/02/10/370591.aspx

Regards,
Milind :)
 
G

Guest

My questions are:
* Is there a better way to measure power consumption of an
application, or to get power status information from within .NET?

To measure actual power consumption the *best* way is with a ammeter inine
with the battery so you can determine exactly how much power is being drawn
at any given moment. Obviously this works well in a lab, but isn't so
realistic for a fielded device (unless you're custom designing it).
* Is it surprising that so many of these values would be zero? I'm
disappointed I can't get BatterymAHourConsumed, as it seemed like
it would measure exactly what I wanted.

No, it's not surprising. The generic battery driver shell provided by
Microsoft provides fields for a whole lot of things, but it's up to the
device OEM to implement these fields. Some of them require certain battery
controllers or smart batteries (or some other specific hardware) that would
add cost to the device for features few people would use. I've seen devices
that gave nothing but the % available, and it was simply a voltage
measurement (which isn't a good measure of "time" left in a battery).
* Is the delta in battery voltage a reasonable way to measure power
consumption, and is it linear?

Probably not and no.
For example, if in one run
BatteryVoltage drops from 4000 to 3900, and in another it drops
from 3900 to 3800, is it reasonable to assume that they both
consumed about the same amount of power?
No

Is there some place I
can find documentation on this?

There should be reasonable online resources to how batteries work and what
the power curves for the different chemistries are that you *might* be able
to use to derive some rough data. Google should get you there. That said,
power monitoring can be a huge ordeal all by itself, and if the device
doesn't have the proper hardware for really measuring it, the numbers you
get are going to be pure guesses that will change in accuracy from device to
device. The nature of many batteries can lead to different results even
from the same device over time (as lithium rechargeable batteries have
"memory").

I think what I'm trying to say here is that you might get some number, but
don't spend a lot of time trying to refine your algorithms and don't base
critical decisions on the data you get.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
H

Hilton

Full charge your battery, run it in a loop doing its thing and see how long
each can go for. Obviously make sure that you turn the screen off after a
fixed time, but keep the device on.

Keep it simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top