Shinyprofiler for JNI part in Android application tutorial
Generate the Shinyprofiler native Android ARM binaries in a static library
on Ubuntu Linux, which can be used in Android application through Java
Native Interface (JNI) calls. To make it work, you would typically have to
compile your source code on your host computer for the target
architecture, which would require you to have the entire tool chain on
your development machine. Android NDK provides the complete set of tools
to build native C/C++ source files.
Step 1. Extract the standalone cross-compiler toolchain. Get and install
Android NDK properly from developer.android.com. Use "customized"
toolchain installation to create standalone compiler defined your Android
platform and device architecture (more information in
<NDK_PATH>/docs/STANDALONE-TOOLCHAIN.html)
Step 2. Create Makefile for building the source code and create a static
library.
ANDROID_NDK_BIN:=/home//<USER>/android/standalone-8/bin
CC := $(ANDROID_NDK_BIN)/arm-linux-androideabi-gcc
CPP := $(ANDROID_NDK_BIN)/arm-linux-androideabi-g++
AR := $(ANDROID_NDK_BIN)/arm-linux-androideabi-ar
CFLAGS := -I../include
.cpp.o:
$(CPP) $(CFLAGS) -c $<
.c.o:
$(CC) $(CFLAGS) -c $<
STATIC_LIB_SRC = ShinyManager.c ShinyNode.c ShinyNodePool.c
ShinyNodeState.c ShinyOutput.c ShinyTools.c ShinyZone.c \
STATIC_LIB_OBJ = ShinyManager.o ShinyNode.o ShinyNodePool.o
ShinyNodeState.o ShinyOutput.o ShinyTools.o ShinyZone.o \
OUT = libShiny.a
$(OUT): $(STATIC_LIB_OBJ)
$(AR) -crs $(OUT) $(STATIC_LIB_OBJ)
clean:
rm -f *.o libShiny.a
Step 3. Put libShiny.a file to /thirdparty/shinyprofiler/lib and header
files to /thirdparty/shinyprofiler/include.
Step 4. Make changes to your JNI part Android.mk makefile, which has to
describe Shinyprofiler static library. Define the path along with other
libraries.
SHINY_PATH := ${THIRDPARTY}/shinyprofiler
Import Shinyprofiler library.
include $(CLEAR_VARS)
LOCAL_MODULE := Shiny
LOCAL_SRC_FILES := $(SHINY_PATH)/lib/libShiny.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SHINY_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
Add Shiny library name and an include path to your build module part:
LOCAL_STATIC_LIBRARIES := [other libraries] Shiny
LOCAL_C_INCLUDES := [other include path] $(LOCAL_PATH)/$(SHINY_PATH)/include
Step 5. Insert #include <Shiny.h> to your project source file, which is to
be profiled.
Step 6. Use PROFILE_BEGIN(<block_name>); and PROFILE_END(); macros to
profile needed block of a C source file (e. g. function) or only
PROFILE_FUNC(); at the beginning of a function in a C++ source file.
Step 7. Use PROFILE_UPADATE(); macro to prepare all profiled data for
output and PROFILE_OUTPUT(<path>/<output_file_name>); to write the data.
To deactivate profiling just put #define SHINY_IS_COMPILED FALSE before
#include <Shiny.h>.
Step 8. Use adb pull <remote> [<local>] to get the profiler output file,
having set needed permissions.
Problem set: If you get 'multiply definition of function', while project
building. Transfer noted function definition from header file to source,
having left function prototypes. Cut SHINY_INLINE macro definition for
these functions. We use gcc compiler, which always emits standalone object
code for functions defined with inline, despite it substitutes function
calls with code or not, so we may encounter multiply definition of
function problem, having oblique header file inclusion in Shinyprofiler
source files. Guards can't help us avoid the problem, for they work within
one translation unit only.
Reference:
Shinyprofiler page
Compile C/C++ ARM binary (Static Library) for Android using Standalone
toolchain
Have anybody got any experience with this profiler or can advise any other
for implementation?
No comments:
Post a Comment