gprof 표준입출력 문제
글쓴이: 오호라 / 작성시간: 수, 2006/04/19 - 5:18오전
샘플소스 : test.c
#include<stdio.h> void foo( void ); void bar( void ); int main(void) { printf( "hello world.\n" ); foo(); bar(); return 0; } void foo( void ) { printf( "I'm foo.\n" ); } void bar( void ) { printf( "I'm bar.\n" ); }
소스는 별로 중요하지 않지만 이해를 좀더 돕고자...
준비물
1. gcc
2. binutils
3. glibc-profile ( libc_p.a )
※ 3번 설치 ( rpmfind.com : glibc-profile )
확인
# ls /usr/lib/libc_p.a
GNU gprof 발췌
cc -g -c myprog.c utils.c -pg cc -o myprog myprog.o utils.o -pg The `-pg' option also works with a command that both compiles and links: cc -o myprog myprog.c utils.c -g -pg If you run the linker ld directly instead of through a compiler such as cc, you may have to specify a profiling startup file `gcrt0.o' as the first input file instead of the usual startup file `crt0.o'. In addition, you would probably want to specify the profiling C library, `libc_p.a', by writing `-lc_p' instead of the usual `-lc'. This is not absolutely necessary, but doing this gives you number-of-calls information for standard library functions such as read and open. For example: ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p
저도 이 문서를 보고 많이 고생했습니다.
gcc -pg -g -static test.c -lc_p
우선 libc_p.a 란 파일을 찾아 삼만리. 알고보니 glibc-profile 라이브러리에 포함되어 있더군요. glibc만 괜히 다시 컴파일했습니다. --profile=enable 옵션주고...
또, 하나는 -static 이 빠진 겁니다. *.a 정적라이브러리죠.
저도 GNU 메뉴얼만 철석같이 믿고 생각도 못했죠. 삽질과 셔핑만 주구장창...
# ./a.out - gmon.out 이란 메타파일이 생겨죠. # gprof a.out gmon.out > profile-result.txt
※ 이 문제에 대해서 아무리 찾아도 안나오더군요. 많은 도움이 되시길...
Forums:
> 저도 GNU 메뉴얼만
> 저도 GNU 메뉴얼만 철석같이 믿고 생각도 못했죠.
glibc 매뉴얼이 잘못된 것은 없습니다. 다만 대부분 바이너리 패키징 배포판이 덩치가 큰 패키지는 여러 개로 나누어 배포하기 때문에 문제가 됩니다. xxx-x.y.z.rpm xxx-devel-x.y.z.rpm 등.. 따라서 이 부분은 배포판에서 충분히 설명할 문제라고 생각합니다.
--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://cinsk.github.io/cfaqs/
그렇지 않아도 gprof
그렇지 않아도 gprof 관련해서 버그 리포팅할게 있었습니다.
[PyProfGen 0.2] 잘 쓰고 있습니다. ^^
Line 447 : float()....
에러가 났습니다.
결론부터 말씀드리면 gmon.out 을 읽을 때.
436 라인에서 헤더를 5줄이 아닌 7줄을 읽어야 하더군요.
gprof 버젼차이인지, gcc 버젼차이인지 모르겠네요.
버그가 아닐수도 있습니다. ^^;
아무튼 파이썬 문법도 모르는데. 몇일 고생했네요.
하필 이사까지 가셔서...시간나면 파이썬이나 봐야겠네요.
Hello World.
댓글 달기