#! /bin/sh # # ntunegraph.sh - Script for plotting temperature graphs out of nTune log # Copyright (C) 2005 Tommi Saviranta # # 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 the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # Version: ntunegraph.sh v0.1.0 09-Oct-2005 wnd@iki.fi BASETIME=x BASEDAY=x usage() { echo "Usage: $0 file" exit 0 } plot() { FILE=$(tempfile) . $0 gen "$1" >"$FILE" gnuplot -persist <) { next if (/CPU/); s/[^0-9\s:\/]//g; s/\s+/ /g; @p = split(/[ :\/]/, \$_); \$t = \$p[3] * 3600 + \$p[4] * 60 + \$p[5]; if (! defined(\$bd)) { \$bd = \$p[2]; \$bt = \$t; } \$t -= \$bt; \$t += 86400 if (\$p[2] != \$bd); \$t /= 60; print "\$t"; for (\$i = 6; \$i <= \$#p; \$i++) { print "\t\$p[\$i]"; } print "\n"; } close(FILE); EOF } # Convenient function for generate_sh # date_to_time() { D=$(echo $1 | cut -d '/' -f 3) H=$(echo $2 | cut -d ':' -f 1) M=$(echo $2 | cut -d ':' -f 2) S=$(echo $2 | cut -d ':' -f 3) TIME=$(( $H * 3600 + $M * 60 + $S )) if [ "x$BASETIME" = "xx" ]; then BASETIME=$TIME BASEDAY=$D fi TIME=$(( $TIME - $BASETIME )) test "$D" != "$BASEDAY" && TIME=$(( $TIME + 86400 )) T0=$(( $TIME / 60 )) T1=$(( $TIME * 100 / 60 )) T1=$(echo "00$T1" | tail -c 3) TIME="$T0.$T1" } # Trim data with standard tools. Slow. # generate_sh() { grep -v Time "$1" | tr -d -c " \t\n0-9:/" | \ sed -e "s/ */\t/g; s/\t\t*/\t/g" | \ while read LINE; do #| sed -e "s/\t/ /g; s/ */ /g;" date_to_time $(echo $LINE | cut -f 1-2) echo "$TIME $(echo "$LINE" | cut -f 3-5)" done } if [ $# -eq 0 ]; then usage elif [ "$1" = "gen" ]; then shift if [ "x$(which perl)" = "x" ]; then generate_sh "$*" else generate_perl "$*" fi else plot "$1" fi