linux에서 c로 개발한 후, 코드를 검사하는 방법 몇가지.. 

 

 

ValgrindREF-SITE

 - 메모리 오류 체크, 메모리 leak 체크.

   특히 메모리 오류가 가장 짜증나는 부분인데 이런 부분을 제법 잡아주므로 꼭 돌릴 필요가 있다.

 

- 사용법:

$gcc test.c -o app_test

$valgrind --leak-check=yes ./app_test

    

 

CppCheck   http://cppcheck.sourceforge.net/

-  Linux버전도 있고, pc버전도 있으며, 파일 단위나 폴더단위로 소스를 검사.

   메모리 누수/배열 범위/멀티 Thread 등이 check됨.

 

 

 

gcov REF-SITE

- 사용(혹은 TEST) 이 안되고 있는 코드 체크, 코드별 실행 횟수 및 %가 나온다.

 

- 사용법:

  $gcc -fprofile-arcs -ftest-coverage tmp.c
  $./a.out
  $gcov tmp.c

 

 

gprof

- 코드 성능 분석

Posted by yongary
,

c++하나를 불러쓰는 경우

 

wrapping layer를 만들어서,

c언어에서 불러쓰면 된다.

 

예) c++파일 안에서

 

extern "C" {

MyClass* myclass_new()

{

return new MyClass();

}

..몇개 함수 더 매핑.

}

이렇게만 하면,

main. c파일안에서 아래와 같이 호출이 가능하다.

 

struct MyClass *m = myclass_new();

 

 

 

그리고  build시에는 특히 c빌드시(혹은 최종 link시에)

gcc main.c -lstdc++  추가 필요....

 

 

 

참고 blog: http://ospace.tistory.com/215 

Posted by yongary
,

< 함수의 실행시간을 milisecond단위로 측정하는 방법. > 



struct timeval을 이용하여 함수의 실행시간을 측정하는 방법인데,


 struct timeval은 초와 micro초로 이루어져 있으므로,

- 초에는 *1000을 

 - micro초에는 /1000 을 해야 milisecond가 된다.


struct timeval { long tv_sec; // 초 long tv_usec; // micro }



=======사용예제================================================

#include <sys/time.h>


struct timeval before,after;  //선언


//사용 
    gettimeofday(&before,NULL);
    run_my_function( );
    gettimeofday(&after,NULL);

    printf("function running time[ms] : %ld\n",
         1000*(after.tv_sec-before.tv_sec) +   
         (after.tv_usec-before.tv_usec)/1000);





Posted by yongary
,