Plotting Power Consumption of my Desktop PC

· klm's blog


Original post is here: eklausmeier.goip.de

I own a desktop PC with an AMD octacore FX 8120 and a NVidia GTX 560 graphic card running GPUGrid. What is the power consumption in Watts over time?

[more_WP_Tag] I ran

1( while true; do powerconsum ; sleep 2; done ) &

with below script powerconsum reading data from sensors:

 1#!/usr/bin/perl -W
 2use strict;
 3my (@F,$power1,$temp1,$i);
 4
 5open(IN,"sensors |") || die("Cannot run sensors");
 6open(OUT,">> /some/file") || die("Cannot append to file");
 7
 8$i = 0;
 9while (<IN>) {
10        if (/^power1:/) {
11                @F = split;
12                $power1 = $F[1];
13                ++$i;
14        } elsif (/^temp1:.*thermistor$/) {
15                @F = split;
16                $temp1 = $F[1];
17                $temp1 =~ s/\+//g;
18                $temp1 = substr($temp1,0,length($temp1)-3);
19                ++$i;
20        }
21}
22close(IN) || die("Cannot close pipe");
23if ($i == 2) {
24        print OUT "$power1\t$temp1\n";
25} else {
26        print OUT "sensor output invalid\n";
27}
28close(OUT) || die("Cannot close output file");

Program sensors is in lm-sensors in Ubuntu.

Running above script over the day, produces quite a mass of data (20-45.000 entries per day), unsuitable for direct plotting. So I applied a moving average on it. Unfortunately, I didn't find one in Octave, although present in MATLAB, so I used below Perl script for this:

 1#!/usr/bin/perl -W
 2# Calculate moving average of time series.
 3# Program can take arguments:
 4#     -d             debug flag
 5#     -n <numeric>   number of averages, default is 5
 6
 7use Getopt::Std;
 8my %opts = ('d' => 0, 'n' => 0);
 9getopts('dn:',\%opts);
10
11my ($i,$j,$n,$cols,@sum,@F,@mat) = (0,0,0,0,(),(),());
12$n = (($opts{'n'} > 0) ? $opts{'n'} : 5);
13
14while (<>) {
15        @F = split;
16        $cols = $#F;
17        for ($j=0; $j<=$cols; ++$j) {
18                $sum[$j] += $F[$j];
19                $sum[$j] -= $mat[$i%$n][$j] if ($i >= $n);
20                $mat[$i%$n][$j] = $F[$j];
21        }
22        if ($i >= $n) {
23                for ($j=0; $j<=$cols; ++$j) {
24                        my $mvavg = $sum[$j] / (1.0 * $n);
25                        printf("$mvavg%s", ($j < $cols) ? "\t" : "\n");
26                }
27        }
28        ++$i;
29}

I highlighted the statements for actual moving average computation.

Chart looks like this, spikes usually mean YouTube video watching. Without that my PC usually consumes around 40 Watts, happily crunching numbers for GPUGrid: powerConsumption1

Or see power consumption chart for another day: powerConsumption3

Above charts were produced with

1mvaverag -n300 /some/file | gnuplot -e "set terminal png; set output '/some/png-file'; plot '-' using 1 with lines title 'Power Consumption in Watts'"

I wanted to know whether there are some predominant frequencies in the data, so I moved to frequency domain via discrete Fourier transform using MATLAB/Octave employing fft.

1plot( abs(fft(detrend( dlmread("/some/file")(:,1)) )) )

It looks like there isn't really, see frequency diagram below.

Photo