Welcome 微信登录

首页 / 操作系统 / Linux / 利用oprofile分析fortran并用gnuplot画图的shell脚本

最经利用oprofile分析fortran代码,一个小插曲就是当你的fortran程序运行时间太短的话,oprofile根本就分析不到。先 贴下我的脚本代码;!/bin/shllog=$1if [ "$#" -ne 1 ]then    echo "Usage:oprofile.sh interger(300,500,800)"    exitfiopcontrol --no-vmlinuxopcontrol --initopcontrol --resetopcontrol --setup --event=CPU_CLK_UNHALTED:6000opcontrol --start./4_1_1./4_1_2./4_1_3./4_1_4./4_1_7./4_1_8opcontrol --dumpopcontrol --stopopcontrol --shutdownopreport -l ./4_1_1 > 1-report-$llogopreport -l ./4_1_2 > 2-report-$llogopreport -l ./4_1_3 > 3-report-$llogopreport -l ./4_1_4 > 4-report-$llogopreport -l ./4_1_7 > 7-report-$llogopreport -l ./4_1_8 > 8-report-$llogopannotate --source ./4_1_1 > 1-annotate-$llogopannotate --source ./4_1_2 > 2-annotate-$llogopannotate --source ./4_1_3 > 3-annotate-$llogopannotate --source ./4_1_4 > 4-annotate-$llogopannotate --source ./4_1_7 > 7-annotate-$llogopannotate --source ./4_1_8 > 8-annotate-$llog
--------------------------------------------------------------------------------上述脚本中的4_1_1至4_1_8是我编译后的fortran可执行文件。100,300,500,800是我里面的数组规模,我这里面的意思是分别在数组是100,300,500,800的时候,测试优化前后的代码的CPU_CLK_UNHALTED,然后把执行结果分别保存在log里面。log的名称唯一的不同就在于后面跟的llog变量的值,他是数组规模。
截取部分3-annotate-300代码:--------------------------------------------------------------------------------               :      Program test1 /* MAIN__ total:   9016 99.9335 */
               :        implicit none
               :        integer,parameter::scale1=300
               :       ! real:: res(scale1,scale1,scale1)=2.3
               :       ! real:: x(scale1,scale1,scale1)=3.6
其中的9016是占用的CPU周期数。--------------------------------------------------------------------------------当得到上述结果之后,可以画出柱状图来的到直观的比较。画图脚本如下: --------------------------------------------------------------------------------#!/bin/sh
lvqq_data=$1
lvqq_title=$2
lvqq_xlabel=$3
lvqq_ylabel=$4
lvqq_before=$5
lvqq_after=$6
if [ $# -ne 6 ]
then
    echo "Usage:`basename $0 ` data-file title xlabel ylabel first_histogram_name second_histogram_name "
    exit
fi
gnuplot <<CMDS
set title "$lvqq_title"
set key left top Left reverse width 0 box 3
set xlabel "$lvqq_xlabel" 0,0
set ylabel "$lvqq_ylabel" 0,0
set boxwidth 0.9 absolute
set style fill pattern 3 border -1
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing "-"
set style data histograms
set xtics   ("100" 0, "300" 1, "500" 2, "800" 3)
set yrange [0:200] noreverse nowriteback
plot "$lvqq_data" using 2 ti col title "$lvqq_before" , "" u 3 ti col title "$lvqq_after"
set output "test"
set terminal png
replot
quit
CMDS因为我需要画好些图,每次都在命令行里面输入,很麻烦,所以就把他们整合进一个shell脚本,只有有数据文件,直接带上参数运行这个脚本就可以得到柱状图。