Profiling

gcc 컴파일 시 아래 옵션을 사용하면 profiling 함수들을 호출할 수 있다.

  • -finstrument-functions

 

사용자(user-compiled) 함수로 들어갔다 나올때마다 다음 함수가 호출된다.

  • __cyg_profile_func_enter()
  • __cyg_profile_func_exit()
__attribute__ ((no_instrument_function)) 
	void __cyg_profile_func_enter(void *this, void *call_site)
{
    (...사용자 코드...)
}

__attribute__ ((no_instrument_function)) 
	void __cyg_profile_func_exit(void *this, void *call_site)
{
    (...사용자 코드...)
}

 

트레이스를 위하여 처음 profiling 함수를 들어가기 전과 마지막 profiling 함수를 사용 후에 각각 한 번씩만 다음 속성으로 선언된 함수가 호출된다.

  • __attribute__ ((constructor))
  • __attribute__ ((destructor))
void __attribute__ ((constructor)) trace_begin (void)
{
        (...사용자 코드...)
}

void __attribute__ ((destructor)) trace_end (void)
{
       (...사용자 코드...)
}

 

profiling 함수 호출 순서

예를 들어 main() 함수에서 foo() 함수를 호출하는 경우의 함수 흐름

profiling

 

notrace

디버거등에 의한 프로 파일링을 막기 위해 사용되는 매크로

#define notrace __attribute__((no_instrument_function))

 

참고

 

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다