https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&feed=atom&action=historyScript for monitoring power consumption - Revision history2024-03-28T16:13:28ZRevision history for this page on the wikiMediaWiki 1.31.12https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24288&oldid=prevMatt garman at 21:53, 19 August 20062006-08-19T21:53:04Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:53, 19 August 2006</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l9" >Line 9:</td>
<td colspan="2" class="diff-lineno">Line 9:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{NOTE|Please feel ''very free'' to improve/fix this script.  My intent for its posting is to make its ownership as public as possible.  There's no need to try to E-mail me to validate your changes.  If you feel they are in the best interest of the public, just make the changes.  The script attempts to employ pre-conditions to intelligently apply functionality only to those laptops that appear to support it.  Hopefully, its framework will allow for extension without heavy redesign.}}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{NOTE|Please feel ''very free'' to improve/fix this script.  My intent for its posting is to make its ownership as public as possible.  There's no need to try to E-mail me to validate your changes.  If you feel they are in the best interest of the public, just make the changes.  The script attempts to employ pre-conditions to intelligently apply functionality only to those laptops that appear to support it.  Hopefully, its framework will allow for extension without heavy redesign.}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">==The script==</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{CodeRef|tp_power_monitor.py}}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{CodeRef|tp_power_monitor.py}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Scripts]]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Scripts]]</div></td></tr>
</table>Matt garmanhttps://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24287&oldid=prevMatt garman at 21:50, 19 August 20062006-08-19T21:50:53Z<p></p>
<a href="https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24287&oldid=24215">Show changes</a>Matt garmanhttps://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24215&oldid=prevThinker: MoveToCode2006-08-17T07:29:17Z<p>MoveToCode</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 07:29, 17 August 2006</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l9" >Line 9:</td>
<td colspan="2" class="diff-lineno">Line 9:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{NOTE|Please feel ''very free'' to improve/fix this script.  My intent for its posting is to make its ownership as public as possible.  There's no need to try to E-mail me to validate your changes.  If you feel they are in the best interest of the public, just make the changes.  The script attempts to employ pre-conditions to intelligently apply functionality only to those laptops that appear to support it.  Hopefully, its framework will allow for extension without heavy redesign.}}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{NOTE|Please feel ''very free'' to improve/fix this script.  My intent for its posting is to make its ownership as public as possible.  There's no need to try to E-mail me to validate your changes.  If you feel they are in the best interest of the public, just make the changes.  The script attempts to employ pre-conditions to intelligently apply functionality only to those laptops that appear to support it.  Hopefully, its framework will allow for extension without heavy redesign.}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{MoveToCode}}</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#!/usr/bin/python</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#!/usr/bin/python</div></td></tr>
</table>Thinkerhttps://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24141&oldid=prevMatt garman at 18:04, 15 August 20062006-08-15T18:04:09Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 18:04, 15 August 2006</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l335" >Line 335:</td>
<td colspan="2" class="diff-lineno">Line 335:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     main()</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     main()</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></pre></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></pre></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Scripts]]</ins></div></td></tr>
</table>Matt garmanhttps://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&diff=24138&oldid=prevMatt garman at 17:59, 15 August 20062006-08-15T17:59:21Z<p></p>
<p><b>New page</b></p><div>The intent of this script is to provide Thinkpad power consumption data. Hopefully the data will allow you to identify areas with higher-than-expected power draw. The ultimate goal of this script is to act as a tool that will ultimately allow you to maximize your battery time under Linux.<br />
<br />
The script is written in Python.<br />
<br />
{{WARN|You will probably need to modify this script to suit your needs. The original script was written using a Thinkpad T43 2668-89U. So, for example, if your particular does not have an ATI video card, then you will definately need to modify the script.}}<br />
<br />
{{HELP|The major deficiency with the script, in its current form, is that it does not consolidate the collected data. I would suggest that the "tpPowerMonitorDataSource" class be extended so that instances of that class know how to interpret their own data (from which nice reports can be generated).}}<br />
<br />
{{NOTE|Please feel ''very free'' to improve/fix this script. My intent for its posting is to make its ownership as public as possible. There's no need to try to E-mail me to validate your changes. If you feel they are in the best interest of the public, just make the changes. The script attempts to employ pre-conditions to intelligently apply functionality only to those laptops that appear to support it. Hopefully, its framework will allow for extension without heavy redesign.}}<br />
<br />
<pre><br />
#!/usr/bin/python<br />
<br />
# COPYRIGHT (C) 2006 Matthew Garman<br />
# matthew (dot) garman (at) gmail (dot) com<br />
# License: MIT <http://www.opensource.org/licenses/mit-license.php><br />
<br />
import sys, time, getopt, os, re<br />
<br />
<br />
class tpPowerMonitorDataSource:<br />
<br />
# The name of the file to parse for needed data (data_source_file) OR<br />
# the name of a command whose output will be read as a file<br />
# (os.popen(shell_command)).<br />
#<br />
# Typically, data_source_file will be something from /proc (or<br />
# possibly /sys), and shell_command will be a utility+arguments such<br />
# as "iwconfig eth1 power".<br />
#<br />
# Note that you should set EITHER data_source_file OR shell_command,<br />
# but not both.<br />
data_source_file = None<br />
shell_command = None<br />
<br />
# The line number of the data file containing our data OR the string<br />
# that marks the beginning of the line in which we're interested<br />
# (startswith_string) OR a regular expression to key the data for<br />
# which we're looking (regexp_pattern).<br />
line_number = None<br />
startswith_string = None<br />
regexp_pattern = None<br />
<br />
# The string that delimits the line containing our data. This will be<br />
# used as the parameter to split(). Note that you can leave this as<br />
# None to split on whitespace.<br />
split_string = None<br />
<br />
# A mapping of data names to indices in the split string.<br />
name_index_map = dict()<br />
<br />
def __init__(self, file, cmd, line, swstr, pat, splstr, map):<br />
self.data_source_file = file<br />
self.shell_command = cmd<br />
self.line_number = line<br />
self.startswith_string = swstr<br />
self.regexp_pattern = pat<br />
self.split_string = splstr<br />
self.name_index_map = map<br />
<br />
def printMembers(self):<br />
print "\t" + 'self.data_source_file = ' + str(self.data_source_file)<br />
print "\t" + 'self.shell_command = ' + str(self.shell_command)<br />
print "\t" + 'self.line_number = ' + str(self.line_number)<br />
print "\t" + 'self.startswith_string = ' + str(self.startswith_string)<br />
print "\t" + 'self.regexp_pattern = ' + str(self.regexp_pattern)<br />
print "\t" + 'self.split_string = ' + str(self.split_string)<br />
print "\t" + 'self.name_index_map = ' + str(self.name_index_map)<br />
<br />
def readData(self, d):<br />
# open the data source file or run the command that will produce<br />
# the data<br />
file = None<br />
if self.data_source_file:<br />
file = open(self.data_source_file, 'r')<br />
elif self.shell_command:<br />
file = os.popen(self.shell_command)<br />
else:<br />
print 'error: no data source defined'<br />
self.printMembers()<br />
# read the contents of the file into a list and close the file<br />
lines = None<br />
if file:<br />
lines = file.readlines()<br />
file.close()<br />
else:<br />
print 'error: data file not opened'<br />
self.printMembers()<br />
# now get the line in the file with our data<br />
line = None<br />
if lines:<br />
if None != self.line_number:<br />
line = lines[self.line_number]<br />
elif self.startswith_string:<br />
for l in lines:<br />
if l.startswith(self.startswith_string):<br />
line = l<br />
break<br />
elif self.regexp_pattern:<br />
for l in lines:<br />
if re.compile(self.regexp_pattern).match(l):<br />
line = l<br />
break<br />
else:<br />
print 'error: no lines in data file'<br />
self.printMembers()<br />
# now get the data we want from the line itself<br />
if line:<br />
fields = line.split(self.split_string)<br />
for key in self.name_index_map.keys():<br />
d[key] = fields[self.name_index_map[key]].strip()<br />
else:<br />
print 'error: could not find line with data in file'<br />
self.printMembers()<br />
<br />
# END --- class tpPowerMonitorDataSource<br />
<br />
<br />
tp_data_sources = [<br />
<br />
tpPowerMonitorDataSource(<br />
'/proc/cpuinfo', # data file<br />
None, # shell command<br />
None, # line index<br />
'cpu MHz', # startswith() string<br />
None, # regexp pattern<br />
':', # split string<br />
{'proc_cpuinfo_cpu_mhz': 1} # name-to-index map<br />
),<br />
<br />
# http://thinkwiki.org/wiki/Ipw2200#Power_Management<br />
tpPowerMonitorDataSource(<br />
None, # data file<br />
'/sbin/iwpriv eth1 get_power', # shell command<br />
0, # line index<br />
None, # startswith() string<br />
None, # regexp pattern<br />
':', # split string<br />
{'iwpriv_get_power': 2} # name-to-index map<br />
),<br />
<br />
# http://forums.gentoo.org/viewtopic-t-447841.html<br />
# see post from ruben on Wed Mar 29, 2006 4:09 am<br />
tpPowerMonitorDataSource(<br />
None,<br />
'/usr/bin/sudo /sbin/hdparm -C /dev/sda',<br />
None,<br />
' drive state is',<br />
None,<br />
':',<br />
{'hard_drive_power_state': 1}<br />
),<br />
<br />
# http://thinkwiki.org/wiki/Thermal_sensors<br />
tpPowerMonitorDataSource(<br />
'/proc/acpi/ibm/thermal',<br />
None,<br />
0,<br />
None,<br />
None,<br />
None,<br />
{'ibm_thermal_cpu': 1,<br />
'ibm_thermal_hdaps': 2,<br />
'ibm_thermal_pmcia': 3,<br />
'ibm_thermal_gpu': 4,<br />
'ibm_thermal_batt_fl': 5,<br />
'ibm_thermal_batt_br': 7 }<br />
),<br />
<br />
# http://mailman.linux-thinkpad.org/pipermail/linux-thinkpad/2006-July/034738.html<br />
tpPowerMonitorDataSource(<br />
'/proc/acpi/processor/CPU/power',<br />
None,<br />
None,<br />
'bus master activity',<br />
None,<br />
':',<br />
{'bus_master_activity': 1}<br />
),<br />
<br />
tpPowerMonitorDataSource(<br />
'/proc/acpi/battery/BAT0/state',<br />
None,<br />
None,<br />
'present rate:',<br />
None,<br />
None,<br />
{'battery0_state_present_rate': 2}<br />
),<br />
<br />
tpPowerMonitorDataSource(<br />
None,<br />
'/usr/bin/sudo /usr/sbin/radeontool dac',<br />
0,<br />
None,<br />
None,<br />
None,<br />
{'radeontool_dac_ext_vga': -1}<br />
),<br />
<br />
tpPowerMonitorDataSource(<br />
None,<br />
'/usr/bin/sudo /usr/sbin/radeontool light',<br />
0,<br />
None,<br />
None,<br />
None,<br />
{'radeontool_light_lcd': -1}<br />
),<br />
<br />
# http://forums.gentoo.org/viewtopic-t-343029-highlight-rovclock.html<br />
tpPowerMonitorDataSource(<br />
None,<br />
'/usr/bin/sudo /usr/sbin/rovclock -i',<br />
None,<br />
'Core: ',<br />
None,<br />
None,<br />
{'rovclock_gpu_clock': 1,<br />
'rovclock_mem_clock': 4 }<br />
),<br />
<br />
tpPowerMonitorDataSource(<br />
None,<br />
'/sbin/iwconfig eth1',<br />
None,<br />
None,<br />
'.*Power Management.*',<br />
':',<br />
{'wireless_power_mgmt_state': 1}<br />
),<br />
<br />
tpPowerMonitorDataSource(<br />
'/proc/loadavg',<br />
None,<br />
0,<br />
None,<br />
None,<br />
None,<br />
{'proc_loadavg_1min': 0,<br />
'proc_loadavg_5min': 1,<br />
'proc_loadavg_15min': 2 }<br />
),<br />
]<br />
log_data = list()<br />
poll_freq_hz = 1<br />
run_time_sec = 60*60<br />
logfile = None<br />
<br />
<br />
def collectPowerData():<br />
global run_time_sec<br />
global poll_freq_hz<br />
global log_data<br />
global logfile<br />
global tp_data_sources<br />
<br />
log = None<br />
if logfile:<br />
log = open(logfile, 'w')<br />
log.write("time, data\n")<br />
end_t = time.time()+run_time_sec<br />
while time.time() < end_t:<br />
datum = dict()<br />
for dsrc in tp_data_sources:<br />
dsrc.readData(datum)<br />
log_data.append(datum)<br />
if log: log.write(str(time.time()) + ', ' + str(datum) + "\n")<br />
time.sleep(1.0/float(poll_freq_hz))<br />
if log: log.close()<br />
<br />
<br />
def createStats():<br />
global log_data<br />
global logfile<br />
log = None<br />
if logfile:<br />
log = open(logfile, 'a')<br />
if log: log.close()<br />
<br />
<br />
def usage():<br />
print 'Usage: ' + sys.argv[0] + \<br />
'[-h] [-f freq_hz] [-t time_min] [-l logfile]'<br />
print "\t-h Display this help"<br />
print "\t-f freq_hz The polling frequency in Hertz, default=" \<br />
+ str(poll_freq_hz)<br />
print "\t-t time_min Total poll time in minutes, default=" \<br />
+ str(run_time_sec/60)<br />
print "\t-l logfile Write poll data to indicated log file"<br />
<br />
<br />
def main():<br />
global poll_freq_hz<br />
global run_time_sec<br />
global logfile<br />
<br />
# parse options<br />
# see: http://docs.python.org/lib/module-getopt.html<br />
try:<br />
opts, args = getopt.getopt(sys.argv[1:], "hf:t:l:")<br />
except getopt.GetoptError:<br />
usage()<br />
sys.exit(2)<br />
for o, a in opts:<br />
if '-h' == o:<br />
usage()<br />
sys.exit()<br />
if '-f' == o:<br />
poll_freq_hz = int(a)<br />
if '-t' == o:<br />
run_time_sec = int(a)*60<br />
if '-l' == o:<br />
logfile = a<br />
<br />
# do stuff<br />
print 'running for ' + str(run_time_sec/60) + ' minutes'<br />
print 'poll rate: ' + str(poll_freq_hz) + ' Hz'<br />
print 'logfile: ' + str(logfile)<br />
collectPowerData()<br />
print '...done!'<br />
print 'Data points collected: ' + str(len(log_data))<br />
sum = 0<br />
for d in log_data:<br />
sum += int(d['battery0_state_present_rate'])<br />
avg = float(sum) / float(len(log_data))<br />
print 'Average power draw: ' + str(avg)<br />
if logfile: log = open(logfile, 'a')<br />
if log:<br />
log.write('Average power draw: ' + str(avg))<br />
log.close()<br />
<br />
<br />
if __name__ == '__main__':<br />
main()<br />
</pre></div>Matt garman