关于Android平台的性能分析, 一般有2中方法, 也就是常说的侵入式和非侵入式
1. 非侵入式
也就是常用的 profile , 可以用AS 自带的 monitor 进行 CPU的 trace, 也可以用 perf 工具, 对APP运行时进行动态的函数采样统计, 得出调用堆栈图, 进而分析耗时性能点
python app_profiler.py --skip_collect_binaries -p io.agora.premium -r "-e task-clock:u -g --duration 10"
python report_html.py
2. 侵入式
Define function pointers for the ATrace functions #include <android/trace.h> #include <dlfcn.h> void *(*ATrace_beginSection) (const char* sectionName); void *(*ATrace_endSection) (void); typedef void *(*fp_ATrace_beginSection) (const char* sectionName); typedef void *(*fp_ATrace_endSection) (void);
Load the ATrace symbols at runtime
// Retrieve a handle to libandroid. void *lib = dlopen("libandroid.so", RTLD_NOW || RTLD_LOCAL); // Access the native tracing functions. if (lib != NULL) { // Use dlsym() to prevent crashes on devices running Android 5.1 // (API level 22) or lower. ATrace_beginSection = reinterpret_cast<fp_ATrace_beginSection>( dlsym(lib, "ATrace_beginSection")); ATrace_endSection = reinterpret_cast<fp_ATrace_endSection>( dlsym(lib, "ATrace_endSection")); }
python2 systrace.py -t 5 -a com.agora.jnimm load
相关操作说明
https://developer.android.com/topic/performance/tracing/navigate-report