gprof 표준입출력 문제

오호라의 이미지

샘플소스 : 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

※ 이 문제에 대해서 아무리 찾아도 안나오더군요. 많은 도움이 되시길...

cinsk의 이미지

> 저도 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/

오호라의 이미지

그렇지 않아도 gprof 관련해서 버그 리포팅할게 있었습니다.

[PyProfGen 0.2] 잘 쓰고 있습니다. ^^

Line 447 : float()....

에러가 났습니다.

결론부터 말씀드리면 gmon.out 을 읽을 때.

429    def eatup_header(self):
430         # Eat first 5 lines from the output.
431         while True:
432             line = self.flat.file.readline();
433             self.lineno = self.lineno + 1;
434             if not line:
435                 break;
436             if self.lineno >= 5:
437                 break;
438
439     def parse_fgraph(self):
440         self.eatup_header();
441         while True:
442             line = self.flat.file.readline();
443             self.lineno = self.lineno + 1;
444             if not line:
445                 break;
446             tokens = line.split();
447             self.entries.append(flat_entry(float(tokens[0]), \
448                                            float(tokens[1]), \
449                                            float(tokens[2]), \
450                                            int(tokens[3]), \
451                                            float(tokens[4]), \
452                                            float(tokens[5]), \
453                                            tokens[6]));

436 라인에서 헤더를 5줄이 아닌 7줄을 읽어야 하더군요.

436             if self.lineno >= 7:
437                 break;

gprof 버젼차이인지, gcc 버젼차이인지 모르겠네요.

버그가 아닐수도 있습니다. ^^;

아무튼 파이썬 문법도 모르는데. 몇일 고생했네요.

하필 이사까지 가셔서...시간나면 파이썬이나 봐야겠네요.

Hello World.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.