设为首页 加入收藏

TOP

利用oprofile分析fortran并用gnuplot画图的shell脚本
2014-11-24 08:34:52 来源: 作者: 【 】 浏览:0
Tags:利用 oprofile分析 fortran 并用 gnuplot 画图 shell 脚本

最经利用oprofile分析fortran代码,一个小插曲就是当你的fortran程序运行时间太短的话,oprofile根本就分析不到。先 贴下我的脚本代码;


!/bin/sh


llog=$1


if [ "$#" -ne 1 ]


then


echo "Usage:oprofile.sh interger(300,500,800)"


exit


fi


opcontrol --no-vmlinux


opcontrol --init


opcontrol --reset


opcontrol --setup --event=CPU_CLK_UNHALTED:6000


opcontrol --start


./4_1_1


./4_1_2


./4_1_3


./4_1_4


./4_1_7


./4_1_8


opcontrol --dump


opcontrol --stop


opcontrol --shutdown


opreport -l ./4_1_1 > 1-report-$llog


opreport -l ./4_1_2 > 2-report-$llog


opreport -l ./4_1_3 > 3-report-$llog


opreport -l ./4_1_4 > 4-report-$llog


opreport -l ./4_1_7 > 7-report-$llog


opreport -l ./4_1_8 > 8-report-$llog


opannotate --source ./4_1_1 > 1-annotate-$llog


opannotate --source ./4_1_2 > 2-annotate-$llog


opannotate --source ./4_1_3 > 3-annotate-$llog


opannotate --source ./4_1_4 > 4-annotate-$llog


opannotate --source ./4_1_7 > 7-annotate-$llog


opannotate --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 <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脚本,只有有数据文件,直接带上参数运行这个脚本就可以得到柱状图。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下indent修改C程序格式 下一篇Linux中断的响应过程

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·怎样用 Python 写一 (2025-12-27 02:49:19)
·如何学习python数据 (2025-12-27 02:49:16)
·想要自学数据分析, (2025-12-27 02:49:14)
·Java 集合框架 - 菜 (2025-12-27 02:19:36)
·Java集合框架最全详 (2025-12-27 02:19:33)