본문 바로가기

6. With IT/6.2 NDK

android-ndk-profile




NDK에서 코딩된 소스의 속도 측정을 위하여, profile하는 방법이 되겠다. 

다른 삽질하는 사람들을 위하여......ㅋㅋㅋ(나를포함 ㅡ.ㅡ)


1. http://code.google.com/p/android-ndk-profiler/

이 곳에서 android-ndk-profile.zip 을 받는다.(현재 버전 : android-ndk-propfiler-3.1.zip) 


2. 해당 작업중인 프로젝트에 압출을푼다.(.../jni)

cd $HOME/path/to/my-project
unzip android
-ndk-profiler.zip


3. 디렉토리안에 자신에 해당하는 타킷 디바이스용 static library(.a)를 복사하여 ndk-build될 디렉토리안에 넣는다.

("그 파일만" 복사해서 가져옴!!!)

ex) .../jni/library/libandprof.a


4. Android.mk 파일을 수정한다.

# include the profiler snippet
-include android-ndk-profiler.mk

# this is your shared library
include $
(CLEAR_VARS)
# compile with profiling
LOCAL_CFLAGS
:= -pg
LOCAL_STATIC_LIBRARIES
:= andprof
# android logging library is required for the profiler
LOCAL_LDLIBS
+= -llog
# ... your build ...
include $
(BUILD_SHARED_LIBRARY)


4-1 기존에 있던 android-ndk-profiler.mk의 내용을 그대로 자신이 빌드할 Android.mk파일에 복사


# This is android-ndk-profiler.mk source...

TARGET_thumb_release_CFLAGS := $(filter-out -ffunction-sections,$(TARGET_thumb_release_CFLAGS))

TARGET_thumb_release_CFLAGS := $(filter-out -fomit-frame-pointer,$(TARGET_thumb_release_CFLAGS))

TARGET_arm_release_CFLAGS := $(filter-out -ffunction-sections,$(TARGET_arm_release_CFLAGS))

TARGET_arm_release_CFLAGS := $(filter-out -fomit-frame-pointer,$(TARGET_arm_release_CFLAGS))


TARGET_CFLAGS := $(filter-out -ffunction-sections,$(TARGET_CFLAGS))


# include libandprof.a in the build

include $(CLEAR_VARS)

LOCAL_MODULE := andprof

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libandprof.a

==>LOCAL_SRC_FILES := libandprof.a (modify)

include $(PREBUILT_STATIC_LIBRARY)


@ 원래 작성되어져있는 LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libandprof.a  내용중 

$(TARGET_ARCH_ABI)/ 부분을 삭제!!(절대경로나 상대경로를 사용할 수 없음!!)


4-2. Android.mk 파일 수정(추가)


LOCAL_STATIC_LIBRARIES := other librarys... andprof

LOCAL_CFLAGS := other options -pg 

LOCAL_LDLIBS := other options -llog

==> 여기서 andprof 모듈이 static library로 구성되어 있으므로, 컴파일시 static library 형식으로 추가 !!

5. 실제 테스트할 소스코드의 시작과 끝 지점에 android-ndk-profiler-3.1안에 들어있는 prof.h파일을 include한 후 내용 추가!!
/* in the start-up code */
monstartup
("your_lib.so");

/* in the onPause or shutdown code */
moncleanup
();

(나의 경우, nativeInit에 monstartup(실제 자바단에서 사용하는 ndk라이브러리이름))을
nativePause에 moncleanup()을 작성)

==> gmon.out 파일이 /mnt/sdcard안에 생김!!. 이 파일을 해당 프로젝트 디렉토리 안에 복사!!(..\SVM\gmon.out)

6. 실제 performance 측정(NDK스타일. 리눅스 스타일은 다름)

..\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-gprof.exe 파일을 가지고 테스트 한다.(이 파일만 따로 복사하여 따로 두어도 됨)

특정 위치에서 해당 라이브러리.so 를 테스트한다.(..\프로젝트명\obj\local\armeabi\라이브러.so)

ex) arm-linux-androideabi-gprof.exe 파일의 위치가 SVM에 있다고 가정
..\SVM>arm-linux-androideabi-gprof [options] obj\local\armeabi\라이브러.so


options...

 -p : display flat profile
  -P : suppress display of flat profile
  -q : display call graph information
  -Q : suppress display of call graph information
  -l : displays instruction profile at source line level instead of function level (requires debug info)
  -C : display routine names and the execution counts obtained by invocation profiling
  -A : print annotated source code, only annotates with function call count (requires debug info)
  -s : sums all the profile data for the specified input files and writes the results to the file gmon.sum
  -I : search path for source files, used mostly for annotating source (can also use GPROF_PATH environment variable)
  -b : prevents gprof from printing the verbose descriptions of the output
  -d : shows grpof debugging information, can be used to access raw data in gmon files
  -S : A Blue Gene specific option that allows large numbers of gmon.out files to be combined. Sequentially sums
       the gmon.out files in a directory, starting with gmon.out.0 until the next in the sequence is not found.
       The result are placed in gmon.sum.