gprof를 사용하여 행렬 곱셈 C 프로그램을 프로파일 링합니다. 그 C 프로그램은 다음과 같은 일반적인 구조를 가지고 있습니다. 나는 프로파일 얼마나 현재 지금GPROF를 사용하여 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();
그런 다음 다시 실행 가능 매트를 실행하고 n=150
, 다음
$ gprof mat gmon.out > analysis2.txt
이 내가 수동 등등 matOpt();
및 matUnopt();
과의 타이밍을 유의 곳에서 analysis2.txt
를 생성합니다.
이것은 매우 시간이 많이 걸리고 지루한 방법입니다. 이 절차를 자동화하고 싶습니다. 이 같은 일부이 : 응용 프로그램이 종료되면
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의에서 무엇을 얻을 있습니다 . 중요한 것은 실행 파일을 여러 번 실행하기위한 함수의 타이밍을 얻는 자동화 된 방법이 있다는 것입니다. 다른 입력 크기도 마찬가지입니다.
이 설명은 대략적인 설명입니다. 나는 이것에 가까운 것을 얻게되어 기쁠 것이다. 예를 들어, 응용 프로그램이 종료 된 다음 새 프로파일 링 결과를 얻기 위해 자체 응용 프로그램을 재시작 할 수 있습니다. 그것이 내가 실제로하고있는 것입니다. 그러나 저는 이것을 자동으로하고 싶습니다.
어떻게이 목표를 달성 할 수 있습니까?
이것은 매우 유용합니다. 그러나이 방법으로 많은 수의 analysisxx.txt 파일을 가져오고 수동으로 각각을 열고 그 다음에 함수의 타이밍을 살펴보아야합니다. 단일 파일의 모든 파일에서 모든 결과를 얻을 수 있습니까? 그래서 각 크기에 대한 결과를 쉽게 비교할 수 있습니까? – user2799508
grof mat gmon.out $ i >> inasinglefile.txt, 대신에 >> 사용 >> –