You are not logged in.

#1 2011-05-15 01:28:58

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

thinkwatt: record power consumption and visualize it with gnuplot

https://github.com/mikar/thinkwatt wrote:

Thinkwatt is a bash script for use with thinkpad laptops. However, as of v0.2, it works with all kinds of laptops as long as they've got a battery attached.

Thinkwatt can
* record your power consumption,
* calculate an average of that consumption
* and visualize that data in a 2D gnuplot graphic.

options:   
    -r, --record    record power consumption and optionally create a graph from the gathered data
    -p, --plot    create a plot image from a specified data file
    -a, --average    calculate the average power consumption from a specified data file
    -q, --quiet    makes thinkwatt less chatty
    -o, --output    the output file. can be prepended by a path.
    -h, --help    show this help text
   
examples:
    thinkwatt -r (will record to a temp file until cancelled)
    thinkwatt -r 300 -o /foo/bar/consumption.dat (will record for 5 minutes to the specified file)
    thinkwatt -p /foo/bar/consumption.dat (will create a graph from the specified file)

Thinkwatt works with all laptops, not just Thinkpads.
If you're running thinkwatt on a Thinkpad it is still recommended to use tp_smapi as it provides more accurate results than the generic acpi.

This is an example of what the graph can look like:
example_datafile.png

It's mainly useful for retracing power consumption during certain situations (e.g. measuring the influence of certain hardware or software (kernel comes to mind), or simply reliably gather typical power consumption for certain activity profiles like surfing, working, watching movies etc.)

I guess I'll add to the script when and if time and my bash skills allow it. Suggestions for improvement are always welcome.

You can get thinkwatt from my git repository here or the AUR here.

Regards,
demian

Last edited by demian (2011-05-28 21:10:30)


no place like /home
github

Offline

#2 2011-05-16 08:03:17

Hermano Arco
Member
Registered: 2009-08-19
Posts: 10

Re: thinkwatt: record power consumption and visualize it with gnuplot

Oh man.. this looked interesting enough to try, but sadly it seems that my X60s isn't fully supported by tp_smapi. /sys/devices/platform/smapi/BAT0/power_now reads always 0.

Controlling battery charging works ok though.

The script itself looked nice and clean smile

Offline

#3 2011-05-16 08:37:19

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

X60s is fully supported by tp_smapi. The only thinkpad models not fully supported are either very old ones (T22, X22, R40 and the likes) or brandnew ones (X220i for example can't load tp_smapi).

My guess is that you had your AC plugged in.
Recording power consumption only works when in battery mode.
If you were on battery, it's possible the correct path for you is "/sys/devices/platform/smapi/BAT1/power_now". There's a variable in the script to change that ($POWERFILE).

I'll add a check for AC so that doesn't happen again anymore.

Regards,
demian

Last edited by demian (2011-05-16 15:08:41)


no place like /home
github

Offline

#4 2011-05-16 08:44:06

Kpunkt
Member
Registered: 2009-06-08
Posts: 144

Re: thinkwatt: record power consumption and visualize it with gnuplot

Since I'm owning a x60s, I can say that the file reads a valid number with and without AC as long as the battery is mounted. Have to try the script!

Offline

#5 2011-05-16 09:00:10

toad
Member
From: if only I knew
Registered: 2008-12-22
Posts: 1,775
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

Shame it isn't in the AUR sad


never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::

Offline

#6 2011-05-16 09:02:30

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

Well, i was planning on creating an AUR entry for this once it's a little more sophisticated and tested but I'll see if I can't put it up there today.


no place like /home
github

Offline

#7 2011-05-16 09:03:39

Hermano Arco
Member
Registered: 2009-08-19
Posts: 10

Re: thinkwatt: record power consumption and visualize it with gnuplot

@demian: And right you were! With AC unplugged I get nice readings and a nice plot smile One suggestion would be to name the resulted image after the dat-file it was generated from; test1.dat -> test1.png. Other than that it seems ready for consumption smile

@Kpunkt: The X60s I'm typing this on gives valid data only when AC unplugged. When AC plugged I get only zeroes.

Offline

#8 2011-05-16 09:31:08

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

Well, if the AC is _charging_ the battery, tp_smapi reports a "consumption" too, it's just positive instead of negative.

I'll have to implement an AC check, that's very easily possible via proc/acpi/ac_adapter/AC/state.

Renaming the png file to the name of the input file is on my to-do-list.

Greets from a boring university lecture,
demian

P.S.:
I need the upload speed i got here at home too:
16.872 kbit/s (2.109 kByte/s, 2.1 MB/s)

Last edited by demian (2011-05-16 09:34:41)


no place like /home
github

Offline

#9 2011-05-16 09:41:37

Hermano Arco
Member
Registered: 2009-08-19
Posts: 10

Re: thinkwatt: record power consumption and visualize it with gnuplot

Ok. I now conclude that my battery is full smile

Good luck with the lecture big_smile

Offline

#10 2011-05-16 13:06:56

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

thinkwatt is now in the AUR.


no place like /home
github

Offline

#11 2011-05-16 13:23:43

toad
Member
From: if only I knew
Registered: 2008-12-22
Posts: 1,775
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

Weyhey! Many thanks for the incredibly quick service smile That lecture must have been riveting...


never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::

Offline

#12 2011-05-16 15:04:54

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

Great, testing it now!

Offline

#13 2011-05-16 15:29:06

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

akurei@joel: ~ $ LANG=C thinkwatt -r 60 /home/akurei/test
recording power consumption for the next 60 seconds
/usr/bin/thinkwatt: line 100: /tmp/thinkwatt/28606.dat: No such file or directory
mv: cannot stat `/tmp/thinkwatt/28606.dat': No such file or directory
error: file not found.
average consumption during the last 60 seconds was  W
do you want to create a graphic now, too? y/n y
error: file not found.
akurei@joel: ~ $ LANG=C thinkwatt -r 60
recording power consumption for the next 60 seconds
/usr/bin/thinkwatt: line 100: /tmp/thinkwatt/29019.dat: No such file or directory
error: file not found.
average consumption during the last 60 seconds was  W
do you want to create a graphic now, too? y/n y
error: file not found.
akurei@joel: ~ $ yaourt -Qi gnuplot
Name           : gnuplot
Version        : 4.4.3-1
URL            : http://www.gnuplot.info
Licenses       : custom
Groups         : None
Provides       : None
Depends On     : readline  gd  wxgtk  cairo  libjpeg  lua
Optional Deps  : None
Required By    : None
Conflicts With : None
Replaces       : None
Installed Size : 3016.00 K
Packager       : Ronald van Haren <ronald@archlinux.org>
Architecture   : x86_64
Build Date     : Fri May 6 10:55:29 2011
Install Date   : Mon May 16 17:04:26 2011
Install Reason : Explicitly installed
Install Script : Yes
Description    : Plotting package which outputs to X11, PostScript, PNG, GIF, and others

akurei@joel: ~ $ yaourt -Qi tp_smapi
Name           : tp_smapi
Version        : 0.40-5
URL            : http://tpctl.sourceforge.net/
Licenses       : GPL
Groups         : None
Provides       : None
Depends On     : mkinitcpio>=0.6.8  module-init-tools>=3.12-2
Optional Deps  : None
Required By    : None
Conflicts With : None
Replaces       : None
Installed Size : 220.00 K
Packager       : Michael Duell <akurei@luamail.net>
Architecture   : x86_64
Build Date     : Mon May 16 17:03:41 2011
Install Date   : Mon May 16 17:03:50 2011
Install Reason : Explicitly installed
Install Script : Yes
Description    : Modules for ThinkPad's SMAPI functionality

akurei@joel: ~ $ yaourt -Qi gawk
Name           : gawk
Version        : 3.1.8-2
URL            : http://www.gnu.org/directory/GNU/gawk.html
Licenses       : GPL
Groups         : base
Provides       : awk
Depends On     : sh  glibc
Optional Deps  : None
Required By    : autoconf  syslog-ng  sysvinit  thinkwatt
Conflicts With : None
Replaces       : None
Installed Size : 2224.00 K
Packager       : St
Architecture   : x86_64
Build Date     : Sat Nov 20 04:00:45 2010
Install Date   : Thu May 5 19:05:55 2011
Install Reason : Explicitly installed
Install Script : Yes
Description    : Gnu version of awk

akurei@joel: ~ $ yaourt -Qi sed
Name           : sed
Version        : 4.2.1-3
URL            : http://www.gnu.org/software/sed
Licenses       : GPL3
Groups         : base
Provides       : None
Depends On     : acl  sh
Optional Deps  : None
Required By    : ca-certificates  fakeroot  grub  mkinitcpio  packer  thinkwatt
Conflicts With : None
Replaces       : None
Installed Size : 804.00 K
Packager       : St
Architecture   : x86_64
Build Date     : Fri Nov 19 22:35:32 2010
Install Date   : Thu May 5 19:05:55 2011
Install Reason : Explicitly installed
Install Script : Yes
Description    : GNU stream editor

akurei@joel: ~ $ lsmod|grep tp_smapi
tp_smapi               20043  0 
thinkpad_ec             4085  2 hdaps,tp_smapi

Last edited by akurei (2011-05-16 15:36:40)

Offline

#14 2011-05-16 16:27:29

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

Yeah, i'm sorry. That's what i get for playing with argument variables and not checking the script later.

It's fixed now, both on the AUR and git.

// There have been several updates to thinkwatt today.

* thinkwatt now works with all kinds of laptops not just thinkpads with tp_smapi enabled
* the name of the gnuplot png output file will now be equal to the name of the data input file (i.e. thinkwatt -p blafoo.dat will produce blafoo.png in the current directory, however thinkwatt -r 50 without a specified output file will still name the png file as $$.png=processid.png)
* i've implemented several checks to avoid errors, among them checks for smapi, AC, a correct data file and others

I encourage everyone to get the latest version from the AUR. I'll also have to ask you to avoid using spaces in path- and filenames as it will currently break some variables. I haven't quite figured out yet how to best handle spaces in filenames with bash. Suggestions are welcome smile

Regards,
demian

Last edited by demian (2011-05-16 20:21:38)


no place like /home
github

Offline

#15 2011-05-16 22:17:38

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

Another obstacle:

akurei@joel: ~ $ LANG=C yaourt -S thinkwatt

==> Downloading thinkwatt PKGBUILD from AUR...
x PKGBUILD


First Submitted: Mon, 16 May 2011 12:00:13 +0000
thinkwatt 0.1-4 
( Unsupported package: Potentially dangerous ! )
==> Edit PKGBUILD ? [Y/n] ("A" to abort)
==> ------------------------------------
==> n

==> thinkwatt dependencies:
 - gawk (already installed)
 - sed (already installed)


==> Continue building thinkwatt ? [Y/n]
==> -----------------------------------
==> 
==> Building and installing package
==> Making package: thinkwatt 0.1-4 (Tue May 17 00:13:16 CEST 2011)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving Sources...
  -> Found twat
==> Validating source files with md5sums...
    twat ... FAILED
==> ERROR: One or more files did not pass the validity check!
==> ERROR: Makepkg was unable to build thinkwatt.
==> Restart building thinkwatt ? [y/N]
==> ----------------------------------
==> 
==> WARNING: Following packages have not been installed:
    thinkwatt

With skipinteg instalation works:

akurei@joel: /tmp $ LANG=C yaourt -G thinkwatt
==> Download thinkwatt sources
x PKGBUILD
akurei@joel: /tmp $ LANG=C cd thinkwatt
PKGBUILD
akurei@joel: /tmp/thinkwatt $ LANG=C makepkg -sfi --skipinteg
==> Making package: thinkwatt 0.1-4 (Tue May 17 00:15:12 CEST 2011)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving Sources...
  -> Found twat
==> WARNING: Skipping integrity checks.
==> Extracting Sources...
==> Entering fakeroot environment...
==> Starting build()...
==> Tidying install...
  -> Purging other files...
  -> Compressing man and info pages...
==> Creating package...
  -> Generating .PKGINFO file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: thinkwatt 0.1-4 (Tue May 17 00:15:12 CEST 2011)
==> Installing package thinkwatt with pacman -U...
Password: 
resolving dependencies...
looking for inter-conflicts...

Targets (1): thinkwatt-0.1-4

Total Download Size:    0.00 MB
Total Installed Size:   0.02 MB

Proceed with installation? [Y/n] 
(1/1) checking package integrity                                                                      [############################################################] 100%
(1/1) checking for file conflicts                                                                     [############################################################] 100%
(1/1) upgrading thinkwatt
akurei@joel: ~ $ LANG=C thinkwatt -r 60 test
recording power consumption for the next 60 seconds
recorded data succesfully written to test
average consumption during the last 60 seconds was 33.0877 W
do you want to create a graphic now, too? y/n y
done. you can find the plot file in /tmp/thinkwatt
graph saved in current working directory as 19946.png

Offline

#16 2011-05-17 13:03:33

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

That happened because you resumed a previously started build of thinkwatt.

First Submitted: Mon, 16 May 2011 12:00:13 +0000
thinkwatt 0.1-4
[...]
==> Continue building thinkwatt ? [Y/n]
[...]
==> Making package: thinkwatt 0.1-4 (Tue May 17 00:13:16 CEST 2011)

By the time you resumed the build I had already uploaded a new version of the thinkwatt script so the checksums didn't match.


-----
I was sick today and used the time to mprove thinkwatt a lot.
* There is now a nifty countdown so you see how many seconds of recording are left
* I've added more customization options for the plotting process
* By default gnuplot now also draws a grid
* I've added quite a few checks that will avoid possible errors

The version is now 0.2.

Regards,
demian


no place like /home
github

Offline

#17 2011-05-17 14:39:44

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: thinkwatt: record power consumption and visualize it with gnuplot

Works great so far big_smile
Thanks a lot!

Offline

#18 2011-05-19 17:02:52

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

0.2-2:
support for spaces in file names
lots of small fixes/improvements to the code

it should run very smoothly now.

Last edited by demian (2011-05-19 19:32:32)


no place like /home
github

Offline

#19 2011-05-23 06:21:38

Hermano Arco
Member
Registered: 2009-08-19
Posts: 10

Re: thinkwatt: record power consumption and visualize it with gnuplot

Works great, thanks!

A small wish: -q for silent running.

Offline

#20 2011-05-28 20:56:20

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: thinkwatt: record power consumption and visualize it with gnuplot

0.2-4:
* added a --quiet / -q option.
* general overhaul of the --record argument:
  if you don't specify a time in seconds it will now record indefinately or until cancelled with Ctrl+C. If cancelled you will be asked if you want to plot from the already recorded data.
  added an --output / -o option to be used if you want -r to record to a specific (directory/)file.
* other, minor improvements to the "code"

Last edited by demian (2011-05-28 21:24:56)


no place like /home
github

Offline

#21 2011-06-15 07:37:31

OdinEidolon
Member
From: Belluno - Italy
Registered: 2011-01-31
Posts: 498

Re: thinkwatt: record power consumption and visualize it with gnuplot

cat: /sys/class/power_supply/AC/online: File o directory non esistente  (file or directory non existent)                                                                                                    
error: please unplug the ac adapater first

On my sistem (see sig) the AC on/off file should be
/sys/class/power_supply/ADP0/online


Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee

Offline

Board footer

Powered by FluxBB