oprofile 使用之三(run 使用时间采样)

来源:互联网 发布:网络歌曲犯错 编辑:程序博客网 时间:2024/06/05 10:26

经历了上述的失败,只能走第2条路,时间采样。

    1.修改opcontrol脚本加载驱动的参数,搜索modprobe oprofile 修改为 modprobe oprofile timer=1

    2.pcontrol --init   插入oprofile.ko驱动 挂载oprofilefs 

   3. opcontrol --no-vmlinux --setup --session-dir=/opt/gtk/testop/ 如果不设置--session-dir那么后续分析会出现opannotate error: Invalid sample file, bad magic number,暂时不知道为什么。

   4.使用如下代码保存成multiply.c  编译 arm-linux-gcc -g multiply.c -o multiply.arm

int fast_multiply(x,  y) /multiply.c
{
    return x * y;
}
int slow_multiply(x, y) 
{
    int i, j, z;
    for (i = 0, z = 0; i < x; i++) 
        z = z + y;
    return z;
}
int main()
{
    int i,j;
    int x,y;
    for (i = 0; i < 2000; i ++) {
        for (j = 0; j < 30 ; j++) {
            x = fast_multiply(i, j);
            y = slow_multiply(i, j);
        }
    }
    return 0;
}

       5.执行如下命令

        opcontrol --start && ./multiply.arm && opcontrol --dump && opcontrol --stop

         启动采样                   执行程序                转储采样信息               停止采样

       6.执行如下命令

       opannotate --source ./multiply.arm 进行采样信息分析

       出现如下错误

opannotate error: No sample file found: try running opcontrol --dump
or specify a session containing sample files

       执行 opannotate --source ./multiply.arm --session-dir=/opt/gtk/testop/

       出现如下错误

       warning: /opt/gtk/multiply.arm could not be found.

      opannotate (warning): no debug information available for binary Segmentation fault

     执行opannotate --source ./multiply.arm --session-dir=/opt/gtk/testop --root=/

      成功打印出分析的信息

      

       至此我们的oprofile运行分析成功。

原创粉丝点击