zoukankan      html  css  js  c++  java
  • 如何使用perf进行程序分析

    1.安装。

    sudo apt-get install linux-tools

     如果提示没有可安装候选。请输入:

    sudo apt-get install linux-perf-version
    

    其中version为你需要的版本。最好与内核版本相同。

    安装完成后输入

    perf top

    如可以执行,则安装成功。

    注意,如果提示

    “E: linux-perf-x.x is not installed.”

    是因为你的linux内核版本与perf版本不一致,输入

    perf_

    后按tab键,通过自动补全补上对应的版本号就行。

    需要注意的是,如果需要彻底解决内核版本与perf版本不一致的问题(在QT中使用会检测不到perf),或者有洁癖。那么:

    chmod 777 /usr/bin/perf
    vim /usr/bin/perf
    

     找到

    shopt -s execfail
    exec "perf_$version" "$@"

    修改为

    shopt -s execfail
    
    version=5.3
    exec "perf_$version" "$@"

    这里的version=5.3是因为我的linux内核版本为5.3,替换为你的内核版本即可。

    2.分析

    假设你在当前目录下有一个名为test的可执行文件需要分析。那么

    perf stat -e cpu-clock ./test

    会返回一个页面展示经过的CPU时钟数和时间。

    假如你需要记录并分析CPU时钟和page fault

    perf record -e cpu-clock,faults ./test

    通过增加和替换参数即可指定需要记录和分析的选项。

    3.查看报告

    perf report

    通过上下键和回车选择对应的分析选项并进入查看。

    未完待续

    参考文献:

    http://sandsoftwaresound.net/perf/perf-tutorial-hot-spots/

    https://docs.cloud.inspur.com/software/perf.html

  • 相关阅读:
    MAC 上找不到.bash_profile或者ect/profile该怎么办?
    iOS极光推送集成步骤
    排序算法
    iOS之内存管理浅谈
    iOS之多线程浅谈
    iOS之RunTime浅谈
    Hash算法初见
    webApi实现增删改查操作
    Python: sqlite3模块
    python3:iterable, iterator, generator,抽象基类, itertools的使用。
  • 原文地址:https://www.cnblogs.com/BYGAO/p/14550608.html
Copyright © 2011-2022 走看看