<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.thinkwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matt+garman</id>
	<title>ThinkWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.thinkwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matt+garman"/>
	<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/wiki/Special:Contributions/Matt_garman"/>
	<updated>2026-05-01T22:32:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.12</generator>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Category_talk:T43&amp;diff=29096</id>
		<title>Category talk:T43</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Category_talk:T43&amp;diff=29096"/>
		<updated>2007-04-06T02:03:11Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;After some more investigation into the SATA vs PATA issue, I have come to the conslusion that while the controller is SATA, that it is using PATA passthrough, so the actual disk is still PATA, but you need Linux SATA drivers.&lt;br /&gt;
&lt;br /&gt;
Tonko&lt;br /&gt;
----&lt;br /&gt;
Yes, so if you wanted to buy a hard drive to replace it, you'd have to get a PATA hard drive.  This page suggests that people who want to upgrade will need a new hard drive that is SATA-native.  Imagine the ruckus that this description can be causing to a current T4x/p user who already has an upgraded PATA hard drive (or want to use their current 7k60) seeing this page; they will be under the impression that their upgrade will not function with their T43/p purchase.  Granted, T43/p's might not accept this upgrade because new BIOS'es simply do not allow them (the reason specifically being that the T43/p machines use a PATA &amp;lt;-&amp;gt; SATA bridge chip; cite: http://forum.thinkpads.com/viewtopic.php?p=79779&amp;amp;highlight=#79779), but I think you should still clearly indicate that the hard drive is PATA native.  &lt;br /&gt;
&lt;br /&gt;
Your comment about the TABOOK.pdf referring that the hard drive is most definitely SATA; I see no text of this anywhere.  The optical drive's connection is out question; the interface it uses is clearly independent of the hard drive's interface.  Another way to verify this: take your hard drive's model and search it under its manufacturer's site.  It will most definitely list your hard drive as ATA-6, an IDE/PATA drive.  (And if it starts with HTS, then it's definitely ATA-6; HGST only has 2.5&amp;quot; TravelStars that are SATA-native on their 100GB drives, which Thinkpads do not even come with.)&lt;br /&gt;
&lt;br /&gt;
Linux implements ICH6 (the PATA/SATA chipset) within the SATA driver, so my second modification, &amp;quot;40, 60 or 80GB PATA HDD (using ICH6/SATA drivers on linux)&amp;quot; is the best way to go.  It also does not infer that the drive appears SATA on Windows, because it doesn't; it says IDE in the device tree, which correctly indicates that hard drive is a PATA device.&lt;br /&gt;
&lt;br /&gt;
Hopefully awaiting your consensus.&lt;br /&gt;
&lt;br /&gt;
Qubit&lt;br /&gt;
----&lt;br /&gt;
Right I had come to a simular conslusion, simply due to checking upgrade HDD partnumbers with those of other T40 series machines. Since they use the same HDD's they must all be PATA.&lt;br /&gt;
&lt;br /&gt;
In addition for them to switch to SATA would probably also require a new UltraBay revision, since the HDD's can be used in the UltraBay with a UltraBay HDD adapter, and the 'UltraBay Slim' does not include a SATA connector.&lt;br /&gt;
&lt;br /&gt;
Machines that appear to have this PATA passthrough:&lt;br /&gt;
* R52&lt;br /&gt;
* T43, T43p&lt;br /&gt;
* X41, X41 Tablet&lt;br /&gt;
&lt;br /&gt;
Tonko&lt;br /&gt;
----&lt;br /&gt;
I've got the 2668-89U model (15&amp;quot; screen, ATI x300 video), and I can NOT get suspend to RAM or disk (hibernate) to work reliably.  I've been through all the relevant pages on this wiki many times.  Is anyone kind enough to post their working kernel config, xorg config, /etc/hibernate/* config files, boot commandline and module settings, along with distribution (name and version), and any other relevant information?  I've reached the point of desperation!  Thanks.&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Talk:Script_for_monitoring_power_consumption&amp;diff=24295</id>
		<title>Talk:Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Talk:Script_for_monitoring_power_consumption&amp;diff=24295"/>
		<updated>2006-08-20T08:34:24Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I think you should move the actual code to a dedicated download page, to make easier to download it. See [[:Category:Code]] for examples and instructions.&lt;br /&gt;
&lt;br /&gt;
--[[User:Thinker|Thinker]] 20:55, 15 August 2006 (CEST)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You're missing the 3 &amp;quot;extra&amp;quot; ACPI [[thermal sensors]].&lt;br /&gt;
&lt;br /&gt;
--[[User:Thinker|Thinker]] 20:58, 15 August 2006 (CEST)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Hopefully this is now correctly posted in the Code Category.  This is my first time contributing to a Wiki, so I'm still getting used to it!  Thanks.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Looks great. I made a tiny fix in the code's Talk page. BTW, you can sign your messages here by typing &amp;lt;nowiki&amp;gt;--~~~~&amp;lt;/nowiki&amp;gt; (or clicking the second-to-rightmost button in the edit bar) when entrying your comment.&lt;br /&gt;
&lt;br /&gt;
--[[User:Thinker|Thinker]] 09:37, 20 August 2006 (CEST)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Thank you!  Don't hesitate to make any more suggestions---I may be slow to respond, but I'll eventually get to it!  This site has been so helpful to me, I hope at least *someone* gets some use out of the script.  Thanks again, you all rule!&lt;br /&gt;
--[[User:Matt garman|Matt garman]] 10:34, 20 August 2006 (CEST)&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Talk:Script_for_monitoring_power_consumption&amp;diff=24289</id>
		<title>Talk:Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Talk:Script_for_monitoring_power_consumption&amp;diff=24289"/>
		<updated>2006-08-19T21:55:04Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I think you should move the actual code to a dedicated download page, to make easier to download it. See [[:Category:Code]] for examples and instructions.&lt;br /&gt;
&lt;br /&gt;
--[[User:Thinker|Thinker]] 20:55, 15 August 2006 (CEST)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You're missing the 3 &amp;quot;extra&amp;quot; ACPI [[thermal sensors]].&lt;br /&gt;
&lt;br /&gt;
--[[User:Thinker|Thinker]] 20:58, 15 August 2006 (CEST)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Hopefully this is now correctly posted in the Code Category.  This is my first time contributing to a Wiki, so I'm still getting used to it!  Thanks.&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24288</id>
		<title>Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24288"/>
		<updated>2006-08-19T21:53:04Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
The script is written in Python.&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
{{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 &amp;quot;tpPowerMonitorDataSource&amp;quot; class be extended so that instances of that class know how to interpret their own data (from which nice reports can be generated).}}&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
==The script==&lt;br /&gt;
{{CodeRef|tp_power_monitor.py}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24287</id>
		<title>Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24287"/>
		<updated>2006-08-19T21:50:53Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
The script is written in Python.&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
{{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 &amp;quot;tpPowerMonitorDataSource&amp;quot; class be extended so that instances of that class know how to interpret their own data (from which nice reports can be generated).}}&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
{{CodeRef|tp_power_monitor.py}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Talk:Code/tp_power_monitor.py&amp;diff=24286</id>
		<title>Talk:Code/tp power monitor.py</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Talk:Code/tp_power_monitor.py&amp;diff=24286"/>
		<updated>2006-08-19T21:44:29Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{CodeHeader|&lt;br /&gt;
|filename=tp_power_monitor.py&lt;br /&gt;
|context=[[Script_for_monitoring_power_consumption]]&lt;br /&gt;
|author=[[User:Matt garman]]&lt;br /&gt;
|license=MIT)&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Talk:Code/tp_power_monitor.py&amp;diff=24285</id>
		<title>Talk:Code/tp power monitor.py</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Talk:Code/tp_power_monitor.py&amp;diff=24285"/>
		<updated>2006-08-19T21:43:47Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{CodeHeader|&lt;br /&gt;
|filename=tp_power_monitor.py)&lt;br /&gt;
|context=[[Script_for_monitoring_power_consumption]]&lt;br /&gt;
|author=[[User:Matt garman]]&lt;br /&gt;
|license=MIT)&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Code/tp_power_monitor.py&amp;diff=24284</id>
		<title>Code/tp power monitor.py</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Code/tp_power_monitor.py&amp;diff=24284"/>
		<updated>2006-08-19T21:35:23Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# COPYRIGHT (C) 2006 Matthew Garman&lt;br /&gt;
# matthew (dot) garman (at) gmail (dot) com&lt;br /&gt;
# License: MIT &amp;lt;http://www.opensource.org/licenses/mit-license.php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import sys, time, getopt, os, re&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class tpPowerMonitorDataSource:&lt;br /&gt;
&lt;br /&gt;
    # The name of the file to parse for needed data (data_source_file) OR&lt;br /&gt;
    # the name of a command whose output will be read as a file&lt;br /&gt;
    # (os.popen(shell_command)).&lt;br /&gt;
    #&lt;br /&gt;
    # Typically, data_source_file will be something from /proc (or&lt;br /&gt;
    # possibly /sys), and shell_command will be a utility+arguments such&lt;br /&gt;
    # as &amp;quot;iwconfig eth1 power&amp;quot;.&lt;br /&gt;
    #&lt;br /&gt;
    # Note that you should set EITHER data_source_file OR shell_command,&lt;br /&gt;
    # but not both.&lt;br /&gt;
    data_source_file    = None&lt;br /&gt;
    shell_command       = None&lt;br /&gt;
&lt;br /&gt;
    # The line number of the data file containing our data OR the string&lt;br /&gt;
    # that marks the beginning of the line in which we're interested&lt;br /&gt;
    # (startswith_string) OR a regular expression to key the data for&lt;br /&gt;
    # which we're looking (regexp_pattern).&lt;br /&gt;
    line_number         = None&lt;br /&gt;
    startswith_string   = None&lt;br /&gt;
    regexp_pattern      = None&lt;br /&gt;
&lt;br /&gt;
    # The string that delimits the line containing our data.  This will be&lt;br /&gt;
    # used as the parameter to split().  Note that you can leave this as&lt;br /&gt;
    # None to split on whitespace.&lt;br /&gt;
    split_string        = None&lt;br /&gt;
&lt;br /&gt;
    # A mapping of data names to indices in the split string.&lt;br /&gt;
    name_index_map      = dict()&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, file, cmd, line, swstr, pat, splstr, map):&lt;br /&gt;
        self.data_source_file    = file&lt;br /&gt;
        self.shell_command       = cmd&lt;br /&gt;
        self.line_number         = line&lt;br /&gt;
        self.startswith_string   = swstr&lt;br /&gt;
        self.regexp_pattern      = pat&lt;br /&gt;
        self.split_string        = splstr&lt;br /&gt;
        self.name_index_map      = map&lt;br /&gt;
&lt;br /&gt;
    def printMembers(self):&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.data_source_file = ' + str(self.data_source_file)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.shell_command = ' + str(self.shell_command)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.line_number = ' + str(self.line_number)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.startswith_string = ' + str(self.startswith_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.regexp_pattern = ' + str(self.regexp_pattern)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.split_string = ' + str(self.split_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.name_index_map = ' + str(self.name_index_map)&lt;br /&gt;
&lt;br /&gt;
    def readData(self, d):&lt;br /&gt;
        # open the data source file or run the command that will produce&lt;br /&gt;
        # the data&lt;br /&gt;
        file = None&lt;br /&gt;
        if self.data_source_file:&lt;br /&gt;
            file = open(self.data_source_file, 'r')&lt;br /&gt;
        elif self.shell_command:&lt;br /&gt;
            file = os.popen(self.shell_command)&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no data source defined'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # read the contents of the file into a list and close the file&lt;br /&gt;
        lines = None&lt;br /&gt;
        if file:&lt;br /&gt;
            lines = file.readlines()&lt;br /&gt;
            file.close()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: data file not opened'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the line in the file with our data&lt;br /&gt;
        line = None&lt;br /&gt;
        if lines:&lt;br /&gt;
            if None != self.line_number:&lt;br /&gt;
                line = lines[self.line_number]&lt;br /&gt;
            elif self.startswith_string:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if l.startswith(self.startswith_string):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
            elif self.regexp_pattern:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if re.compile(self.regexp_pattern).match(l):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no lines in data file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the data we want from the line itself&lt;br /&gt;
        if line:&lt;br /&gt;
            fields = line.split(self.split_string)&lt;br /&gt;
            for key in self.name_index_map.keys():&lt;br /&gt;
                d[key] = fields[self.name_index_map[key]].strip()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: could not find line with data in file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
&lt;br /&gt;
# END --- class tpPowerMonitorDataSource&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
tp_data_sources = [&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/cpuinfo',             # data file&lt;br /&gt;
        None,                        # shell command&lt;br /&gt;
        None,                        # line index&lt;br /&gt;
        'cpu MHz',                   # startswith() string&lt;br /&gt;
        None,                        # regexp pattern&lt;br /&gt;
        ':',                         # split string&lt;br /&gt;
        {'proc_cpuinfo_cpu_mhz': 1}  # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Ipw2200#Power_Management&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,                          # data file&lt;br /&gt;
        '/sbin/iwpriv eth1 get_power', # shell command&lt;br /&gt;
        0,                             # line index&lt;br /&gt;
        None,                          # startswith() string&lt;br /&gt;
        None,                          # regexp pattern&lt;br /&gt;
        ':',                           # split string&lt;br /&gt;
        {'iwpriv_get_power': 2}        # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-447841.html&lt;br /&gt;
    # see post from ruben on Wed Mar 29, 2006 4:09 am&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /sbin/hdparm -C /dev/sda',&lt;br /&gt;
        None,&lt;br /&gt;
        ' drive state is',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'hard_drive_power_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Thermal_sensors&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/ibm/thermal',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'ibm_thermal_cpu':     1,&lt;br /&gt;
         'ibm_thermal_hdaps':   2,&lt;br /&gt;
         'ibm_thermal_pmcia':   3,&lt;br /&gt;
         'ibm_thermal_gpu':     4,&lt;br /&gt;
         'ibm_thermal_batt_fl': 5,&lt;br /&gt;
         'ibm_thermal_batt_br': 7 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://mailman.linux-thinkpad.org/pipermail/linux-thinkpad/2006-July/034738.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/processor/CPU/power',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'bus master activity',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'bus_master_activity': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/battery/BAT0/state',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'present rate:',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'battery0_state_present_rate': 2}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool dac',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_dac_ext_vga': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool light',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_light_lcd': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-343029-highlight-rovclock.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/rovclock -i',&lt;br /&gt;
        None,&lt;br /&gt;
        'Core: ',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'rovclock_gpu_clock': 1,&lt;br /&gt;
         'rovclock_mem_clock': 4 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/sbin/iwconfig eth1',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        '.*Power Management.*',&lt;br /&gt;
        ':',&lt;br /&gt;
        {'wireless_power_mgmt_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/loadavg',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'proc_loadavg_1min': 0,&lt;br /&gt;
         'proc_loadavg_5min': 1,&lt;br /&gt;
         'proc_loadavg_15min': 2 }&lt;br /&gt;
    ),&lt;br /&gt;
]&lt;br /&gt;
log_data = list()&lt;br /&gt;
poll_freq_hz = 1&lt;br /&gt;
run_time_sec = 60*60&lt;br /&gt;
logfile = None&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def collectPowerData():&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    global tp_data_sources&lt;br /&gt;
&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'w')&lt;br /&gt;
        log.write(&amp;quot;time, data\n&amp;quot;)&lt;br /&gt;
    end_t = time.time()+run_time_sec&lt;br /&gt;
    while time.time() &amp;lt; end_t:&lt;br /&gt;
        datum = dict()&lt;br /&gt;
        for dsrc in tp_data_sources:&lt;br /&gt;
            dsrc.readData(datum)&lt;br /&gt;
        log_data.append(datum)&lt;br /&gt;
        if log: log.write(str(time.time()) + ', ' + str(datum) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
        time.sleep(1.0/float(poll_freq_hz))&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def createStats():&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'a')&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def usage():&lt;br /&gt;
    print 'Usage: ' + sys.argv[0] + \&lt;br /&gt;
        '[-h] [-f freq_hz] [-t time_min] [-l logfile]'&lt;br /&gt;
    print &amp;quot;\t-h            Display this help&amp;quot;&lt;br /&gt;
    print &amp;quot;\t-f freq_hz    The polling frequency in Hertz, default=&amp;quot; \&lt;br /&gt;
        + str(poll_freq_hz)&lt;br /&gt;
    print &amp;quot;\t-t time_min   Total poll time in minutes, default=&amp;quot; \&lt;br /&gt;
        + str(run_time_sec/60)&lt;br /&gt;
    print &amp;quot;\t-l logfile    Write poll data to indicated log file&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global logfile&lt;br /&gt;
&lt;br /&gt;
    # parse options&lt;br /&gt;
    # see: http://docs.python.org/lib/module-getopt.html&lt;br /&gt;
    try:&lt;br /&gt;
        opts, args = getopt.getopt(sys.argv[1:], &amp;quot;hf:t:l:&amp;quot;)&lt;br /&gt;
    except getopt.GetoptError:&lt;br /&gt;
        usage()&lt;br /&gt;
        sys.exit(2)&lt;br /&gt;
    for o, a in opts:&lt;br /&gt;
        if '-h' == o:&lt;br /&gt;
            usage()&lt;br /&gt;
            sys.exit()&lt;br /&gt;
        if '-f' == o:&lt;br /&gt;
            poll_freq_hz = int(a)&lt;br /&gt;
        if '-t' == o:&lt;br /&gt;
            run_time_sec = int(a)*60&lt;br /&gt;
        if '-l' == o:&lt;br /&gt;
            logfile = a&lt;br /&gt;
&lt;br /&gt;
    # do stuff&lt;br /&gt;
    print 'running for ' + str(run_time_sec/60) + ' minutes'&lt;br /&gt;
    print 'poll rate:  ' + str(poll_freq_hz) + ' Hz'&lt;br /&gt;
    print 'logfile:    ' + str(logfile)&lt;br /&gt;
    collectPowerData()&lt;br /&gt;
    print '...done!'&lt;br /&gt;
    print 'Data points collected: ' + str(len(log_data))&lt;br /&gt;
    sum = 0&lt;br /&gt;
    for d in log_data:&lt;br /&gt;
        sum += int(d['battery0_state_present_rate'])&lt;br /&gt;
    avg = float(sum) / float(len(log_data))&lt;br /&gt;
    print 'Average power draw:    ' + str(avg)&lt;br /&gt;
    if logfile:     log = open(logfile, 'a')&lt;br /&gt;
    if log:&lt;br /&gt;
        log.write('Average power draw:    ' + str(avg))&lt;br /&gt;
        log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24141</id>
		<title>Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24141"/>
		<updated>2006-08-15T18:04:09Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
The script is written in Python.&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
{{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 &amp;quot;tpPowerMonitorDataSource&amp;quot; class be extended so that instances of that class know how to interpret their own data (from which nice reports can be generated).}}&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# COPYRIGHT (C) 2006 Matthew Garman&lt;br /&gt;
# matthew (dot) garman (at) gmail (dot) com&lt;br /&gt;
# License: MIT &amp;lt;http://www.opensource.org/licenses/mit-license.php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import sys, time, getopt, os, re&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class tpPowerMonitorDataSource:&lt;br /&gt;
&lt;br /&gt;
    # The name of the file to parse for needed data (data_source_file) OR&lt;br /&gt;
    # the name of a command whose output will be read as a file&lt;br /&gt;
    # (os.popen(shell_command)).&lt;br /&gt;
    #&lt;br /&gt;
    # Typically, data_source_file will be something from /proc (or&lt;br /&gt;
    # possibly /sys), and shell_command will be a utility+arguments such&lt;br /&gt;
    # as &amp;quot;iwconfig eth1 power&amp;quot;.&lt;br /&gt;
    #&lt;br /&gt;
    # Note that you should set EITHER data_source_file OR shell_command,&lt;br /&gt;
    # but not both.&lt;br /&gt;
    data_source_file    = None&lt;br /&gt;
    shell_command       = None&lt;br /&gt;
&lt;br /&gt;
    # The line number of the data file containing our data OR the string&lt;br /&gt;
    # that marks the beginning of the line in which we're interested&lt;br /&gt;
    # (startswith_string) OR a regular expression to key the data for&lt;br /&gt;
    # which we're looking (regexp_pattern).&lt;br /&gt;
    line_number         = None&lt;br /&gt;
    startswith_string   = None&lt;br /&gt;
    regexp_pattern      = None&lt;br /&gt;
&lt;br /&gt;
    # The string that delimits the line containing our data.  This will be&lt;br /&gt;
    # used as the parameter to split().  Note that you can leave this as&lt;br /&gt;
    # None to split on whitespace.&lt;br /&gt;
    split_string        = None&lt;br /&gt;
&lt;br /&gt;
    # A mapping of data names to indices in the split string.&lt;br /&gt;
    name_index_map      = dict()&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, file, cmd, line, swstr, pat, splstr, map):&lt;br /&gt;
        self.data_source_file    = file&lt;br /&gt;
        self.shell_command       = cmd&lt;br /&gt;
        self.line_number         = line&lt;br /&gt;
        self.startswith_string   = swstr&lt;br /&gt;
        self.regexp_pattern      = pat&lt;br /&gt;
        self.split_string        = splstr&lt;br /&gt;
        self.name_index_map      = map&lt;br /&gt;
&lt;br /&gt;
    def printMembers(self):&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.data_source_file = ' + str(self.data_source_file)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.shell_command = ' + str(self.shell_command)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.line_number = ' + str(self.line_number)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.startswith_string = ' + str(self.startswith_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.regexp_pattern = ' + str(self.regexp_pattern)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.split_string = ' + str(self.split_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.name_index_map = ' + str(self.name_index_map)&lt;br /&gt;
&lt;br /&gt;
    def readData(self, d):&lt;br /&gt;
        # open the data source file or run the command that will produce&lt;br /&gt;
        # the data&lt;br /&gt;
        file = None&lt;br /&gt;
        if self.data_source_file:&lt;br /&gt;
            file = open(self.data_source_file, 'r')&lt;br /&gt;
        elif self.shell_command:&lt;br /&gt;
            file = os.popen(self.shell_command)&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no data source defined'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # read the contents of the file into a list and close the file&lt;br /&gt;
        lines = None&lt;br /&gt;
        if file:&lt;br /&gt;
            lines = file.readlines()&lt;br /&gt;
            file.close()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: data file not opened'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the line in the file with our data&lt;br /&gt;
        line = None&lt;br /&gt;
        if lines:&lt;br /&gt;
            if None != self.line_number:&lt;br /&gt;
                line = lines[self.line_number]&lt;br /&gt;
            elif self.startswith_string:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if l.startswith(self.startswith_string):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
            elif self.regexp_pattern:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if re.compile(self.regexp_pattern).match(l):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no lines in data file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the data we want from the line itself&lt;br /&gt;
        if line:&lt;br /&gt;
            fields = line.split(self.split_string)&lt;br /&gt;
            for key in self.name_index_map.keys():&lt;br /&gt;
                d[key] = fields[self.name_index_map[key]].strip()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: could not find line with data in file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
&lt;br /&gt;
# END --- class tpPowerMonitorDataSource&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
tp_data_sources = [&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/cpuinfo',             # data file&lt;br /&gt;
        None,                        # shell command&lt;br /&gt;
        None,                        # line index&lt;br /&gt;
        'cpu MHz',                   # startswith() string&lt;br /&gt;
        None,                        # regexp pattern&lt;br /&gt;
        ':',                         # split string&lt;br /&gt;
        {'proc_cpuinfo_cpu_mhz': 1}  # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Ipw2200#Power_Management&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,                          # data file&lt;br /&gt;
        '/sbin/iwpriv eth1 get_power', # shell command&lt;br /&gt;
        0,                             # line index&lt;br /&gt;
        None,                          # startswith() string&lt;br /&gt;
        None,                          # regexp pattern&lt;br /&gt;
        ':',                           # split string&lt;br /&gt;
        {'iwpriv_get_power': 2}        # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-447841.html&lt;br /&gt;
    # see post from ruben on Wed Mar 29, 2006 4:09 am&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /sbin/hdparm -C /dev/sda',&lt;br /&gt;
        None,&lt;br /&gt;
        ' drive state is',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'hard_drive_power_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Thermal_sensors&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/ibm/thermal',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'ibm_thermal_cpu':     1,&lt;br /&gt;
         'ibm_thermal_hdaps':   2,&lt;br /&gt;
         'ibm_thermal_pmcia':   3,&lt;br /&gt;
         'ibm_thermal_gpu':     4,&lt;br /&gt;
         'ibm_thermal_batt_fl': 5,&lt;br /&gt;
         'ibm_thermal_batt_br': 7 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://mailman.linux-thinkpad.org/pipermail/linux-thinkpad/2006-July/034738.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/processor/CPU/power',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'bus master activity',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'bus_master_activity': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/battery/BAT0/state',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'present rate:',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'battery0_state_present_rate': 2}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool dac',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_dac_ext_vga': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool light',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_light_lcd': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-343029-highlight-rovclock.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/rovclock -i',&lt;br /&gt;
        None,&lt;br /&gt;
        'Core: ',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'rovclock_gpu_clock': 1,&lt;br /&gt;
         'rovclock_mem_clock': 4 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/sbin/iwconfig eth1',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        '.*Power Management.*',&lt;br /&gt;
        ':',&lt;br /&gt;
        {'wireless_power_mgmt_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/loadavg',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'proc_loadavg_1min': 0,&lt;br /&gt;
         'proc_loadavg_5min': 1,&lt;br /&gt;
         'proc_loadavg_15min': 2 }&lt;br /&gt;
    ),&lt;br /&gt;
]&lt;br /&gt;
log_data = list()&lt;br /&gt;
poll_freq_hz = 1&lt;br /&gt;
run_time_sec = 60*60&lt;br /&gt;
logfile = None&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def collectPowerData():&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    global tp_data_sources&lt;br /&gt;
&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'w')&lt;br /&gt;
        log.write(&amp;quot;time, data\n&amp;quot;)&lt;br /&gt;
    end_t = time.time()+run_time_sec&lt;br /&gt;
    while time.time() &amp;lt; end_t:&lt;br /&gt;
        datum = dict()&lt;br /&gt;
        for dsrc in tp_data_sources:&lt;br /&gt;
            dsrc.readData(datum)&lt;br /&gt;
        log_data.append(datum)&lt;br /&gt;
        if log: log.write(str(time.time()) + ', ' + str(datum) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
        time.sleep(1.0/float(poll_freq_hz))&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def createStats():&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'a')&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def usage():&lt;br /&gt;
    print 'Usage: ' + sys.argv[0] + \&lt;br /&gt;
        '[-h] [-f freq_hz] [-t time_min] [-l logfile]'&lt;br /&gt;
    print &amp;quot;\t-h            Display this help&amp;quot;&lt;br /&gt;
    print &amp;quot;\t-f freq_hz    The polling frequency in Hertz, default=&amp;quot; \&lt;br /&gt;
        + str(poll_freq_hz)&lt;br /&gt;
    print &amp;quot;\t-t time_min   Total poll time in minutes, default=&amp;quot; \&lt;br /&gt;
        + str(run_time_sec/60)&lt;br /&gt;
    print &amp;quot;\t-l logfile    Write poll data to indicated log file&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global logfile&lt;br /&gt;
&lt;br /&gt;
    # parse options&lt;br /&gt;
    # see: http://docs.python.org/lib/module-getopt.html&lt;br /&gt;
    try:&lt;br /&gt;
        opts, args = getopt.getopt(sys.argv[1:], &amp;quot;hf:t:l:&amp;quot;)&lt;br /&gt;
    except getopt.GetoptError:&lt;br /&gt;
        usage()&lt;br /&gt;
        sys.exit(2)&lt;br /&gt;
    for o, a in opts:&lt;br /&gt;
        if '-h' == o:&lt;br /&gt;
            usage()&lt;br /&gt;
            sys.exit()&lt;br /&gt;
        if '-f' == o:&lt;br /&gt;
            poll_freq_hz = int(a)&lt;br /&gt;
        if '-t' == o:&lt;br /&gt;
            run_time_sec = int(a)*60&lt;br /&gt;
        if '-l' == o:&lt;br /&gt;
            logfile = a&lt;br /&gt;
&lt;br /&gt;
    # do stuff&lt;br /&gt;
    print 'running for ' + str(run_time_sec/60) + ' minutes'&lt;br /&gt;
    print 'poll rate:  ' + str(poll_freq_hz) + ' Hz'&lt;br /&gt;
    print 'logfile:    ' + str(logfile)&lt;br /&gt;
    collectPowerData()&lt;br /&gt;
    print '...done!'&lt;br /&gt;
    print 'Data points collected: ' + str(len(log_data))&lt;br /&gt;
    sum = 0&lt;br /&gt;
    for d in log_data:&lt;br /&gt;
        sum += int(d['battery0_state_present_rate'])&lt;br /&gt;
    avg = float(sum) / float(len(log_data))&lt;br /&gt;
    print 'Average power draw:    ' + str(avg)&lt;br /&gt;
    if logfile:     log = open(logfile, 'a')&lt;br /&gt;
    if log:&lt;br /&gt;
        log.write('Average power draw:    ' + str(avg))&lt;br /&gt;
        log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=How_to_measure_power_consumption&amp;diff=24140</id>
		<title>How to measure power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=How_to_measure_power_consumption&amp;diff=24140"/>
		<updated>2006-08-15T18:02:15Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To monitor the laptop's power consumption while it is running, unplug the AC power and run:&lt;br /&gt;
:{{cmdroot|watch -n1 'cat /proc/acpi/battery/BAT0/*'}}&lt;br /&gt;
&lt;br /&gt;
This requires ACPI to be enabled. The value given is (roughly) an averge over the last minute.&lt;br /&gt;
&lt;br /&gt;
Alternatively, load the [[tp_smapi]] module and run the following with AC power unplugged:&lt;br /&gt;
:{{cmdroot|watch -n1 'cat /sys/devices/platform/smapi/BAT0/power_now'}}&lt;br /&gt;
or&lt;br /&gt;
:{{cmdroot|watch -n1 'cat /sys/devices/platform/smapi/BAT0/power_avg'}}&lt;br /&gt;
&lt;br /&gt;
The former provides the instantaneous power draw, and the latter is (roughly) an average over the last minute. It's OK to use  [[tp_smapi]]'s &amp;lt;tt&amp;gt;force_discharge&amp;lt;/tt&amp;gt; function instead of physically disconnecting AC power.&lt;br /&gt;
&lt;br /&gt;
Note that running on battery power may activate power-saving mechanisms, so unless you take care to deactivate them this does not reflect power consumption under AC power.&lt;br /&gt;
&lt;br /&gt;
To measure power consumption while the laptop is suspended, use the [[ACPI sleep power drain test script]].&lt;br /&gt;
&lt;br /&gt;
For reducing power consumption, see [[How to reduce power consumption]] and [[Script_for_monitoring_power_consumption]].&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=How_to_reduce_power_consumption&amp;diff=24139</id>
		<title>How to reduce power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=How_to_reduce_power_consumption&amp;diff=24139"/>
		<updated>2006-08-15T18:01:32Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: /* Related toptics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Reducing system power consumption will extend battery life, reduce system temperature and (on some models) reduce system fan noise. This page summarizes the known techniques for reducing power consumption on ThinkPad laptops under Linux. The power numbers given (in Watt) are very rough and model-specific.&lt;br /&gt;
&lt;br /&gt;
===System power states===&lt;br /&gt;
* [[Power Management]]&lt;br /&gt;
* [[How to make use of Power Management features]]&lt;br /&gt;
&lt;br /&gt;
===CPU===&lt;br /&gt;
* [[How to make use of Dynamic Frequency Scaling]]&lt;br /&gt;
* [[Pentium M undervolting and underclocking]]&lt;br /&gt;
&lt;br /&gt;
===Graphics===&lt;br /&gt;
* [[How to make use of Graphics Chips Power Management features]]&lt;br /&gt;
* [[Problem with high power drain in ACPI sleep]]&lt;br /&gt;
* [[Rovclock]]&lt;br /&gt;
* Reduce LCD brightness (~1-4W difference)&lt;br /&gt;
* Disable CRT output (~0.5W difference)&lt;br /&gt;
&lt;br /&gt;
===Hard disk===&lt;br /&gt;
Spinning down the disk saves about 1W.&lt;br /&gt;
* [[Laptop-mode]]&lt;br /&gt;
* [[How to make use of Harddisk Power Management features]]&lt;br /&gt;
&lt;br /&gt;
===Optical drive===&lt;br /&gt;
The optical drive consumes about 1W even when not accessed.&lt;br /&gt;
* [[How to hotswap UltraBay devices|Eject the UltraBay optical drive]], or just turn off its power supply (i.e., run the appropriate eject script but leave the drive inserted).&lt;br /&gt;
&lt;br /&gt;
===System fan===&lt;br /&gt;
Consumes about 0.5W when running.&lt;br /&gt;
* [[ACPI fan control script]]&lt;br /&gt;
&lt;br /&gt;
===Wireless network===&lt;br /&gt;
Consumes up to ~4W.&lt;br /&gt;
* Activate power saving on the wireless network card&lt;br /&gt;
** For [[Intel PRO/Wireless 2200BG Mini-PCI Adapter]] and [[Intel PRO/Wireless 2915ABG Mini-PCI Adapter]], see instructions for the [[ipw2200]] driver.&lt;br /&gt;
&lt;br /&gt;
==Related toptics==&lt;br /&gt;
* [[How to measure power consumption]]&lt;br /&gt;
* [[Script_for_monitoring_power_consumption]]&lt;br /&gt;
* Battery [[maintenance]]&lt;br /&gt;
&lt;br /&gt;
==External resources==&lt;br /&gt;
* [http://www.gentoo.org/doc/en/power-management-guide.xml Power Management Guide] from the Gentoo Linux documentation&lt;br /&gt;
* [http://mailman.linux-thinkpad.org/pipermail/linux-thinkpad/2005-November/030478.html When/where/what for low power consumption?] (thread on Linux-Thinkpad)&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24138</id>
		<title>Script for monitoring power consumption</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=Script_for_monitoring_power_consumption&amp;diff=24138"/>
		<updated>2006-08-15T17:59:21Z</updated>

		<summary type="html">&lt;p&gt;Matt garman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
The script is written in Python.&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
{{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 &amp;quot;tpPowerMonitorDataSource&amp;quot; class be extended so that instances of that class know how to interpret their own data (from which nice reports can be generated).}}&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# COPYRIGHT (C) 2006 Matthew Garman&lt;br /&gt;
# matthew (dot) garman (at) gmail (dot) com&lt;br /&gt;
# License: MIT &amp;lt;http://www.opensource.org/licenses/mit-license.php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import sys, time, getopt, os, re&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class tpPowerMonitorDataSource:&lt;br /&gt;
&lt;br /&gt;
    # The name of the file to parse for needed data (data_source_file) OR&lt;br /&gt;
    # the name of a command whose output will be read as a file&lt;br /&gt;
    # (os.popen(shell_command)).&lt;br /&gt;
    #&lt;br /&gt;
    # Typically, data_source_file will be something from /proc (or&lt;br /&gt;
    # possibly /sys), and shell_command will be a utility+arguments such&lt;br /&gt;
    # as &amp;quot;iwconfig eth1 power&amp;quot;.&lt;br /&gt;
    #&lt;br /&gt;
    # Note that you should set EITHER data_source_file OR shell_command,&lt;br /&gt;
    # but not both.&lt;br /&gt;
    data_source_file    = None&lt;br /&gt;
    shell_command       = None&lt;br /&gt;
&lt;br /&gt;
    # The line number of the data file containing our data OR the string&lt;br /&gt;
    # that marks the beginning of the line in which we're interested&lt;br /&gt;
    # (startswith_string) OR a regular expression to key the data for&lt;br /&gt;
    # which we're looking (regexp_pattern).&lt;br /&gt;
    line_number         = None&lt;br /&gt;
    startswith_string   = None&lt;br /&gt;
    regexp_pattern      = None&lt;br /&gt;
&lt;br /&gt;
    # The string that delimits the line containing our data.  This will be&lt;br /&gt;
    # used as the parameter to split().  Note that you can leave this as&lt;br /&gt;
    # None to split on whitespace.&lt;br /&gt;
    split_string        = None&lt;br /&gt;
&lt;br /&gt;
    # A mapping of data names to indices in the split string.&lt;br /&gt;
    name_index_map      = dict()&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, file, cmd, line, swstr, pat, splstr, map):&lt;br /&gt;
        self.data_source_file    = file&lt;br /&gt;
        self.shell_command       = cmd&lt;br /&gt;
        self.line_number         = line&lt;br /&gt;
        self.startswith_string   = swstr&lt;br /&gt;
        self.regexp_pattern      = pat&lt;br /&gt;
        self.split_string        = splstr&lt;br /&gt;
        self.name_index_map      = map&lt;br /&gt;
&lt;br /&gt;
    def printMembers(self):&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.data_source_file = ' + str(self.data_source_file)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.shell_command = ' + str(self.shell_command)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.line_number = ' + str(self.line_number)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.startswith_string = ' + str(self.startswith_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.regexp_pattern = ' + str(self.regexp_pattern)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.split_string = ' + str(self.split_string)&lt;br /&gt;
        print &amp;quot;\t&amp;quot; + 'self.name_index_map = ' + str(self.name_index_map)&lt;br /&gt;
&lt;br /&gt;
    def readData(self, d):&lt;br /&gt;
        # open the data source file or run the command that will produce&lt;br /&gt;
        # the data&lt;br /&gt;
        file = None&lt;br /&gt;
        if self.data_source_file:&lt;br /&gt;
            file = open(self.data_source_file, 'r')&lt;br /&gt;
        elif self.shell_command:&lt;br /&gt;
            file = os.popen(self.shell_command)&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no data source defined'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # read the contents of the file into a list and close the file&lt;br /&gt;
        lines = None&lt;br /&gt;
        if file:&lt;br /&gt;
            lines = file.readlines()&lt;br /&gt;
            file.close()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: data file not opened'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the line in the file with our data&lt;br /&gt;
        line = None&lt;br /&gt;
        if lines:&lt;br /&gt;
            if None != self.line_number:&lt;br /&gt;
                line = lines[self.line_number]&lt;br /&gt;
            elif self.startswith_string:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if l.startswith(self.startswith_string):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
            elif self.regexp_pattern:&lt;br /&gt;
                for l in lines:&lt;br /&gt;
                    if re.compile(self.regexp_pattern).match(l):&lt;br /&gt;
                        line = l&lt;br /&gt;
                        break&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: no lines in data file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
        # now get the data we want from the line itself&lt;br /&gt;
        if line:&lt;br /&gt;
            fields = line.split(self.split_string)&lt;br /&gt;
            for key in self.name_index_map.keys():&lt;br /&gt;
                d[key] = fields[self.name_index_map[key]].strip()&lt;br /&gt;
        else:&lt;br /&gt;
            print 'error: could not find line with data in file'&lt;br /&gt;
            self.printMembers()&lt;br /&gt;
&lt;br /&gt;
# END --- class tpPowerMonitorDataSource&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
tp_data_sources = [&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/cpuinfo',             # data file&lt;br /&gt;
        None,                        # shell command&lt;br /&gt;
        None,                        # line index&lt;br /&gt;
        'cpu MHz',                   # startswith() string&lt;br /&gt;
        None,                        # regexp pattern&lt;br /&gt;
        ':',                         # split string&lt;br /&gt;
        {'proc_cpuinfo_cpu_mhz': 1}  # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Ipw2200#Power_Management&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,                          # data file&lt;br /&gt;
        '/sbin/iwpriv eth1 get_power', # shell command&lt;br /&gt;
        0,                             # line index&lt;br /&gt;
        None,                          # startswith() string&lt;br /&gt;
        None,                          # regexp pattern&lt;br /&gt;
        ':',                           # split string&lt;br /&gt;
        {'iwpriv_get_power': 2}        # name-to-index map&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-447841.html&lt;br /&gt;
    # see post from ruben on Wed Mar 29, 2006 4:09 am&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /sbin/hdparm -C /dev/sda',&lt;br /&gt;
        None,&lt;br /&gt;
        ' drive state is',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'hard_drive_power_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://thinkwiki.org/wiki/Thermal_sensors&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/ibm/thermal',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'ibm_thermal_cpu':     1,&lt;br /&gt;
         'ibm_thermal_hdaps':   2,&lt;br /&gt;
         'ibm_thermal_pmcia':   3,&lt;br /&gt;
         'ibm_thermal_gpu':     4,&lt;br /&gt;
         'ibm_thermal_batt_fl': 5,&lt;br /&gt;
         'ibm_thermal_batt_br': 7 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://mailman.linux-thinkpad.org/pipermail/linux-thinkpad/2006-July/034738.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/processor/CPU/power',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'bus master activity',&lt;br /&gt;
        None,&lt;br /&gt;
        ':',&lt;br /&gt;
        {'bus_master_activity': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/acpi/battery/BAT0/state',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        'present rate:',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'battery0_state_present_rate': 2}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool dac',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_dac_ext_vga': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/radeontool light',&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'radeontool_light_lcd': -1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    # http://forums.gentoo.org/viewtopic-t-343029-highlight-rovclock.html&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/usr/bin/sudo /usr/sbin/rovclock -i',&lt;br /&gt;
        None,&lt;br /&gt;
        'Core: ',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'rovclock_gpu_clock': 1,&lt;br /&gt;
         'rovclock_mem_clock': 4 }&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        None,&lt;br /&gt;
        '/sbin/iwconfig eth1',&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        '.*Power Management.*',&lt;br /&gt;
        ':',&lt;br /&gt;
        {'wireless_power_mgmt_state': 1}&lt;br /&gt;
    ),&lt;br /&gt;
&lt;br /&gt;
    tpPowerMonitorDataSource(&lt;br /&gt;
        '/proc/loadavg',&lt;br /&gt;
        None,&lt;br /&gt;
        0,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        None,&lt;br /&gt;
        {'proc_loadavg_1min': 0,&lt;br /&gt;
         'proc_loadavg_5min': 1,&lt;br /&gt;
         'proc_loadavg_15min': 2 }&lt;br /&gt;
    ),&lt;br /&gt;
]&lt;br /&gt;
log_data = list()&lt;br /&gt;
poll_freq_hz = 1&lt;br /&gt;
run_time_sec = 60*60&lt;br /&gt;
logfile = None&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def collectPowerData():&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    global tp_data_sources&lt;br /&gt;
&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'w')&lt;br /&gt;
        log.write(&amp;quot;time, data\n&amp;quot;)&lt;br /&gt;
    end_t = time.time()+run_time_sec&lt;br /&gt;
    while time.time() &amp;lt; end_t:&lt;br /&gt;
        datum = dict()&lt;br /&gt;
        for dsrc in tp_data_sources:&lt;br /&gt;
            dsrc.readData(datum)&lt;br /&gt;
        log_data.append(datum)&lt;br /&gt;
        if log: log.write(str(time.time()) + ', ' + str(datum) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
        time.sleep(1.0/float(poll_freq_hz))&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def createStats():&lt;br /&gt;
    global log_data&lt;br /&gt;
    global logfile&lt;br /&gt;
    log = None&lt;br /&gt;
    if logfile:&lt;br /&gt;
        log = open(logfile, 'a')&lt;br /&gt;
    if log: log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def usage():&lt;br /&gt;
    print 'Usage: ' + sys.argv[0] + \&lt;br /&gt;
        '[-h] [-f freq_hz] [-t time_min] [-l logfile]'&lt;br /&gt;
    print &amp;quot;\t-h            Display this help&amp;quot;&lt;br /&gt;
    print &amp;quot;\t-f freq_hz    The polling frequency in Hertz, default=&amp;quot; \&lt;br /&gt;
        + str(poll_freq_hz)&lt;br /&gt;
    print &amp;quot;\t-t time_min   Total poll time in minutes, default=&amp;quot; \&lt;br /&gt;
        + str(run_time_sec/60)&lt;br /&gt;
    print &amp;quot;\t-l logfile    Write poll data to indicated log file&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    global poll_freq_hz&lt;br /&gt;
    global run_time_sec&lt;br /&gt;
    global logfile&lt;br /&gt;
&lt;br /&gt;
    # parse options&lt;br /&gt;
    # see: http://docs.python.org/lib/module-getopt.html&lt;br /&gt;
    try:&lt;br /&gt;
        opts, args = getopt.getopt(sys.argv[1:], &amp;quot;hf:t:l:&amp;quot;)&lt;br /&gt;
    except getopt.GetoptError:&lt;br /&gt;
        usage()&lt;br /&gt;
        sys.exit(2)&lt;br /&gt;
    for o, a in opts:&lt;br /&gt;
        if '-h' == o:&lt;br /&gt;
            usage()&lt;br /&gt;
            sys.exit()&lt;br /&gt;
        if '-f' == o:&lt;br /&gt;
            poll_freq_hz = int(a)&lt;br /&gt;
        if '-t' == o:&lt;br /&gt;
            run_time_sec = int(a)*60&lt;br /&gt;
        if '-l' == o:&lt;br /&gt;
            logfile = a&lt;br /&gt;
&lt;br /&gt;
    # do stuff&lt;br /&gt;
    print 'running for ' + str(run_time_sec/60) + ' minutes'&lt;br /&gt;
    print 'poll rate:  ' + str(poll_freq_hz) + ' Hz'&lt;br /&gt;
    print 'logfile:    ' + str(logfile)&lt;br /&gt;
    collectPowerData()&lt;br /&gt;
    print '...done!'&lt;br /&gt;
    print 'Data points collected: ' + str(len(log_data))&lt;br /&gt;
    sum = 0&lt;br /&gt;
    for d in log_data:&lt;br /&gt;
        sum += int(d['battery0_state_present_rate'])&lt;br /&gt;
    avg = float(sum) / float(len(log_data))&lt;br /&gt;
    print 'Average power draw:    ' + str(avg)&lt;br /&gt;
    if logfile:     log = open(logfile, 'a')&lt;br /&gt;
    if log:&lt;br /&gt;
        log.write('Average power draw:    ' + str(avg))&lt;br /&gt;
        log.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Matt garman</name></author>
		
	</entry>
</feed>