Android Trace

关于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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值