#!/bin/bash # 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, 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., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # Author/Copyright(c): 2009, Thomas Renninger , Novell Inc. # Helper script to easily create nice plots of your cpufreq-bench results global dir := $[mktemp -d] global output_file := '"cpufreq-bench.png'" global global_title := '"cpufreq-bench plot'" global picture_type := '"jpeg'" file[0]="" proc usage { echo "cpufreq-bench_plot.sh [OPTIONS] logfile [measure_title] [logfile [measure_title]] ...]" echo echo "Options" echo " -o output_file" echo " -t global_title" echo " -p picture_type [jpeg|gif|png|postscript|...]" exit 1 } if test $Argc -eq 0{ echo "No benchmark results file provided" echo usage } while getopts o:t:p: name { matchstr $name { o { global output_file := ""$OPTARG".$picture_type" } t { global global_title := $OPTARG } p { global picture_type := $OPTARG } ? { usage } } } shift $($OPTIND -1) global plots := '0' while [ "$1" ]{ if test ! -f $1{ echo "File $1 does not exist" usage } file[$plots]="$1" title[$plots]="$2" # echo "File: ${file[$plots]} - ${title[plots]}" shift;shift global plots := $(plots + 1) } echo "set terminal $picture_type" >> $dir/plot_script.gpl echo "set output \"$output_file\"" >> $dir/plot_script.gpl echo "set title \"$global_title\"" >> $dir/plot_script.gpl echo "set xlabel \"sleep/load time\"" >> $dir/plot_script.gpl echo "set ylabel \"Performance (%)\"" >> $dir/plot_script.gpl for((plot=0;plot<$plots;plot++));do # Sanity check ###### I am to dump to get this redirected to stderr/stdout in one awk call... ##### cat ${file[$plot]} |grep -v "^#" |awk '{if ($2 != $3) printf("Error in measure %d:Load time %s does not equal sleep time %s, plot will not be correct\n", $1, $2, $3); ERR=1}' ###### I am to dump to get this redirected in one awk call... ##### # Parse out load time (which must be equal to sleep time for a plot), divide it by 1000 # to get ms and parse out the performance in percentage and write it to a temp file for plotting cat ${file[$plot]} |grep -v "^#" |awk '{printf "%lu %.1f\n",$2/1000, $6}' >$dir/data_$plot if [ $plot -eq 0 ];then echo -n "plot " >> $dir/plot_script.gpl fi echo -n "\"$dir/data_$plot\" title \"${title[$plot]}\" with lines" >> $dir/plot_script.gpl if [ $(($plot + 1)) -ne $plots ];then echo -n ", " >> $dir/plot_script.gpl fi done echo >> $dir/plot_script.gpl gnuplot $dir/plot_script.gpl rm -r $dir (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)} {(-d)})]) left_token: spids: [52 56] ) } spids: [51] ) ] spids: [51] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:output_file) op: Equal rhs: {(DQ (cpufreq-bench.png))} spids: [58] ) ] spids: [58] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:global_title) op: Equal rhs: {(DQ ("cpufreq-bench plot"))} spids: [63] ) ] spids: [63] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:picture_type) op:Equal rhs:{(DQ (jpeg))} spids:[68])] spids: [68] ) (C {(file) (Lit_Other "[") (0) (Lit_Other "]") (Lit_Other "=") (DQ )}) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} { (DQ ( "cpufreq-bench_plot.sh [OPTIONS] logfile [measure_title] [logfile [measure_title]] ...]" ) ) } ) (C {(echo)}) (C {(echo)} {(DQ (Options))}) (C {(echo)} {(DQ (" -o output_file"))}) (C {(echo)} {(DQ (" -t global_title"))}) (C {(echo)} {(DQ (" -p picture_type [jpeg|gif|png|postscript|...]"))}) (C {(exit)} {(1)}) ] spids: [88] ) spids: [82 87] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(C {(echo)} {(DQ ("No benchmark results file provided"))}) (C {(echo)}) (C {(usage)})] spids: [-1 148] ) ] spids: [-1 163] ) (While cond: [ (Sentence child: (C {(getopts)} {(o) (Lit_Other ":") (t) (Lit_Other ":") (p) (Lit_Other ":")} {(name)}) terminator: ) ] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$name")} arms: [ (case_arm pat_list: [{(o)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:output_file) op: Equal rhs: {(DQ ($ VSub_Name "$OPTARG")) (.) ($ VSub_Name "$picture_type")} spids: [195] ) ] spids: [195] ) ] spids: [191 192 203 -1] ) (case_arm pat_list: [{(t)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:global_title) op: Equal rhs: {(DQ ($ VSub_Name "$OPTARG"))} spids: [210] ) ] spids: [210] ) ] spids: [206 207 216 -1] ) (case_arm pat_list: [{(p)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:picture_type) op: Equal rhs: {(DQ ($ VSub_Name "$OPTARG"))} spids: [223] ) ] spids: [223] ) ] spids: [219 220 229 -1] ) (case_arm pat_list: [{(Lit_Other "?")}] action: [(C {(usage)})] spids: [232 233 239 -1] ) ] spids: [184 188 242] ) ] spids: [181 244] ) ) (C {(shift)} { (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Name "$OPTIND")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [248 254] ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:plots) op:Equal rhs:{(0)} spids:[257])] spids: [257] ) (While cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")}) terminator: ) ] body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-f)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("File ") ($ VSub_Number "$1") (" does not exist"))}) (C {(usage)}) ] spids: [-1 287] ) ] spids: [-1 302] ) (C {(file) (Lit_Other "[") ($ VSub_Name "$plots") (Lit_Other "]") (Lit_Other "=") (DQ ($ VSub_Number "$1")) } ) (C {(title) (Lit_Other "[") ($ VSub_Name "$plots") (Lit_Other "]") (Lit_Other "=") (DQ ($ VSub_Number "$2")) } ) (Sentence child:(C {(shift)}) terminator:) (C {(shift)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:plots) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:plots) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [335 342] ) } spids: [334] ) ] spids: [334] ) ] spids: [270 344] ) ) (SimpleCommand words: [{(echo)} {(DQ ("set terminal ") ($ VSub_Name "$picture_type"))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [354] ) ] ) (SimpleCommand words: [ {(echo)} { (DQ ("set output ") (EscapedLiteralPart token:) ($ VSub_Name "$output_file") (EscapedLiteralPart token:) ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [368] ) ] ) (SimpleCommand words: [ {(echo)} { (DQ ("set title ") (EscapedLiteralPart token:) ($ VSub_Name "$global_title") (EscapedLiteralPart token:) ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [382] ) ] ) (SimpleCommand words: [ {(echo)} { (DQ ("set xlabel ") (EscapedLiteralPart token:) ("sleep/load time") (EscapedLiteralPart token:) ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [396] ) ] ) (SimpleCommand words: [ {(echo)} { (DQ ("set ylabel ") (EscapedLiteralPart token:) ("Performance (%)") (EscapedLiteralPart token:) ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [410] ) ] ) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:plot) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:plot) right: (ArithWord w:{($ VSub_Name "$plots")}) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:plot)) body: (DoGroup children: [ (Pipeline children: [ (C {(cat)} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$plot")})) spids: [445 450] ) } ) (C {(grep)} {(-v)} {(DQ ("^#"))}) (C {(awk)} { (SQ < "{if ($2 != $3) printf(\"Error in measure %d:Load time %s does not equal sleep time %s, plot will not be correct\\n\", $1, $2, $3); ERR=1}" > ) } ) ] negated: False ) (Pipeline children: [ (C {(cat)} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$plot")})) spids: [484 489] ) } ) (C {(grep)} {(-v)} {(DQ ("^#"))}) (SimpleCommand words: [{(awk)} {(SQ <"{printf \"%lu %.1f\\n\",$2/1000, $6}">)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$dir") (/data_) ($ VSub_Name "$plot")} spids: [507] ) ] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$plot")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(-n)} {(DQ ("plot "))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [537] ) ] ) ] spids: [-1 526] ) ] spids: [-1 543] ) (SimpleCommand words: [ {(echo)} {(-n)} { (DQ (EscapedLiteralPart token:) ($ VSub_Name "$dir") (/data_) ($ VSub_Name "$plot") (EscapedLiteralPart token:) (" title ") (EscapedLiteralPart token:) (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$plot")})) spids: [558 563] ) (EscapedLiteralPart token:) (" with lines") ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [568] ) ] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$plot")}) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [578 585] ) } {(-ne)} {($ VSub_Name "$plots")} {(Lit_Other "]")} ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(-n)} {(DQ (", "))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [604] ) ] ) ] spids: [-1 593] ) ] spids: [-1 610] ) ] spids: [431 612] ) ) (SimpleCommand words: [{(echo)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Name "$dir") (/plot_script.gpl)} spids: [616] ) ] ) (C {(gnuplot)} {($ VSub_Name "$dir") (/plot_script.gpl)}) (C {(rm)} {(-r)} {($ VSub_Name "$dir")}) ] )