【发布时间】:2014-01-23 12:15:03
【问题描述】:
我正在使用 gprof 分析一个矩阵乘法 C 程序。该 C 程序具有这样的一般结构;
int main()
{
int n;
printf("enter size of square matrices");
scanf("%d", &n);
data(matM); //fill matrices with n x n random data
data(matN);
// this is unoptimized algo
matUnopt(int *matM, int *matN, int *MatOut, int size);
// this is optimized algo
matOpt(int *matM, int *matN, int *MatOut, int size);
return(0);
}
现在我的分析方式是:
我运行我的可执行文件,将大小设置为100,然后$ gprof mat gmon.out > analysis1.txt
这会生成 analysis1.txt 我手动记下 matOpt(); 和 matUnopt(); 的时间
然后我再次运行可执行mat,并给出n=150,然后
$ gprof mat gmon.out > analysis2.txt
这会生成 analysis2.txt 我手动记下 matOpt(); 和 matUnopt(); 的时间
等等。
这是非常耗时且无聊的方式。我想自动化这个过程。有些是这样的:
int main()
{
int n;
for (n=50; n<50000; n++)
{
data(matM); //fill matrices with n x n random data
data(matN);
// this is unoptimized algo
matUnopt(int *matM, int *matN, int *MatOut, int size);
//gprof records the time of completion of matUnopt for the particular value of n, and
puts in a file
// this is optimized algo
matOpt(int *matM, int *matN, int *MatOut, int size);
//gprof records the time of completion of matOpt for the particular value of n, and
puts in a file
}
return(0);
}
一旦应用程序退出,我期待一个具有如下表格的文件:
run# (x 50) profiling result (as usual we get from gprof)
1 matUnopt time .....
matOpt time .....
2 matUnopt time .....
matOpt time .....
3 matUnopt time .....
matOpt time .....
4 matUnopt time .....
matOpt time .....
and so on.
请注意,上面的“分析结果”是我们通常从 gprof 获得的。 重要的是我有一种自动化的方法来获取可执行文件的多次运行的功能时间,这也具有不同的输入大小。
这个解释只是一个粗略的想法。我很乐意得到与此近似的任何东西。例如,应用程序可能会退出,然后重新启动它自己以获得新的分析结果。这就是我实际在做的事情。但我想自动执行此操作。
我如何实现这个目标?
【问题讨论】: