oprofile的使用

1. 检查内核编译
       编译开关
       CONFIG_KALLSYMS_ALL=y
    CONFIG_PROFILING=y
    CONFIG_OPROFILE=y

2. 用户空间配置
    (1). 拷贝vmlinux到目标机
        adb push out/target/product/Q8145SA/vmlinux /data
    (2). 禁止休眠
             adb shell "mkdir /data/debug"
             adb shell "mount -t debugfs nodev /data/debug"
             adb shell "echo 1 > /data/debug/nohlt"
    (3). 获取内核运行的开始、结束地址
        adb shell "echo 0 > /proc/sys/kernel/kptr_restrict"
        adb shell "opcontrol --setup"
        adb shell cat /proc/kallsyms | grep "_text" | awk '{print $1}'
        列出开始地址是:0xc0008000
        adb shell cat /proc/kallsyms | grep "_etext" | awk '{print $1}'
        列出结束地址是:0xc0896c18
    (4). 配置内核开始、结束地址并指明vmlinux的位置
        a. CPU支持NMI中断模式
                adb shell "opcontrol --kernel-range=0xc0008000,0xc0896c18 --vmlinux=/data/vmlinux --event=CPU_CYCLES:1000::0:1"
            b. timer 模式
                adb shell "opcontrol --kernel-range=0xc0008000,0xc0896c18 --vmlinux=/data/vmlinux --timer"
    (5). 设置调用层数
        adb shell "opcontrol --callgraph=16"
    (6). 启动 oprofile
        adb shell opcontrol --start
        运行一些程序...
    (7). 查看状态
        adb shell opcontrol --status
    (8). 停止采样
        adb shell opcontrol --stop
    
3. 结果分析
    (1). 从目标机获取采样文件到PC
        sudo ./external/oprofile/opimport_pull -r /tmp/profiling
    (2). 报告结果

        opreport --session-dir=/tmp/profiling/
        opreport --session-dir=/tmp/profiling/ -p $PWD/out/target/product/Q8145SA/symbols -l -g libdvm.so

        opreport --session-dir=/tmp/profiling/ -p $PWD/out/target/product/Q8145SA -l -g vmlinux

        opannotate --session-dir=/tmp/profiling/ -p $PWD/out/target/product/Q8145SA -s vmlinux

4. 注意事项
    (1). 运行./external/oprofile/opimport_pull可能会出错,需要修改opimport_pull中的一些配置路径。
    (2). 有时运行 opcontrol --setup 时会提示“Terminated”, 需要把/data目录下的oprofile/删除再重新开机,或者格式化userdata分区重新开机。

    (3). 需要修改内核代码支持timer模式,修改内核里面代码 oprof.c中的 timer=1;

    (4). oprofile的代码主要看文件./external/oprofile/opcontrol/opcontrol.cpp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值