#!/bin/sh
#
# genresult: A system activity measurement script
#
# Usage: genresult [duration] [directory]
#
# Duration is the time that the whole measurement should run.
# Default is 60 seconds.
#
# Copyright (C) 2009 Red Hat, Inc.
# Authors: Phil Knirsch
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to:
#
# Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA  02110-1301, USA.
#

umask 077
TMPDIR=`mktemp -d`
DURATION=60
DIRECTORY=/usr/local/testday-091022/genresult
[ $# -ge 1 ] && DURATION=$1
[ $# -ge 2 ] && DIRECTORY=$2
mkdir -p $DIRECTORY
#netdevstat $DURATION $DURATION > $TMPDIR/netdevstat.result &
#diskdevstat $DURATION $DURATION> $TMPDIR/diskdevstat.result &
echo "Starting measurement"
powertop -d -t $DURATION > $TMPDIR/powertop.result
echo "Finished measurement"
rm -f $DIRECTORY/result.txt
grep "Power usage (ACPI estimate):" $TMPDIR/powertop.result >> $DIRECTORY/result.txt
egrep '^C[0-9]+' $TMPDIR/powertop.result >> $DIRECTORY/result.txt
grep " Ghz" $TMPDIR/powertop.result >> $DIRECTORY/result.txt
grep " Mhz" $TMPDIR/powertop.result >> $DIRECTORY/result.txt
grep "Wakeups-from-idle" $TMPDIR/powertop.result >> $DIRECTORY/result.txt
echo "Results can be found in ${DIRECTORY}/result.txt"
rm -rf $TMPDIR
