xref: /linux/tools/power/cpupower/bench/cpufreq-bench_plot.sh (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1#!/bin/bash
2
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2, or (at your option)
6# any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16# 02110-1301, USA.
17
18# Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
19
20# Helper script to easily create nice plots of your cpufreq-bench results
21
22dir=`mktemp -d`
23output_file="cpufreq-bench.png"
24global_title="cpufreq-bench plot"
25picture_type="jpeg"
26file[0]=""
27
28function usage()
29{
30    echo "cpufreq-bench_plot.sh [OPTIONS] logfile [measure_title] [logfile [measure_title]] ...]"
31    echo
32    echo "Options"
33    echo "   -o output_file"
34    echo "   -t global_title"
35    echo "   -p picture_type [jpeg|gif|png|postscript|...]"
36    exit 1
37}
38
39if [ $# -eq 0 ];then
40	echo "No benchmark results file provided"
41	echo
42	usage
43fi
44
45while getopts o:t:p: name ; do
46    case $name in
47	o)
48	    output_file="$OPTARG".$picture_type
49	    ;;
50	t)
51	    global_title="$OPTARG"
52	    ;;
53	p)
54	    picture_type="$OPTARG"
55	    ;;
56        ?)
57	    usage
58	    ;;
59    esac
60done
61shift $(($OPTIND -1))
62
63plots=0
64while [ "$1" ];do
65    if [ ! -f "$1" ];then
66	echo "File $1 does not exist"
67	usage
68    fi
69    file[$plots]="$1"
70    title[$plots]="$2"
71    # echo "File: ${file[$plots]} - ${title[plots]}"
72    shift;shift
73    plots=$((plots + 1))
74done
75
76echo "set terminal $picture_type"	>> $dir/plot_script.gpl
77echo "set output \"$output_file\""	>> $dir/plot_script.gpl
78echo "set title \"$global_title\""	>> $dir/plot_script.gpl
79echo "set xlabel \"sleep/load time\""	>> $dir/plot_script.gpl
80echo "set ylabel \"Performance (%)\""	>> $dir/plot_script.gpl
81
82for((plot=0;plot<$plots;plot++));do
83
84    # Sanity check
85    ###### I am to dump to get this redirected to stderr/stdout in one awk call... #####
86    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}'
87    ###### I am to dump to get this redirected in one awk call... #####
88
89    # Parse out load time (which must be equal to sleep time for a plot), divide it by 1000
90    # to get ms and parse out the performance in percentage and write it to a temp file for plotting
91    cat ${file[$plot]} |grep -v "^#" |awk '{printf "%lu %.1f\n",$2/1000, $6}' >$dir/data_$plot
92
93    if [ $plot -eq 0 ];then
94	echo -n "plot " >> $dir/plot_script.gpl
95    fi
96    echo -n "\"$dir/data_$plot\" title \"${title[$plot]}\" with lines" >> $dir/plot_script.gpl
97    if [ $(($plot + 1)) -ne $plots ];then
98	echo -n ", " >> $dir/plot_script.gpl
99    fi
100done
101echo >> $dir/plot_script.gpl
102
103gnuplot $dir/plot_script.gpl
104rm -r $dir