1)perf安装错误

图片.png如图,安装时找不到对应的包,尤其是linux-tools-5.4.0-107-generic

解决方法:

在docker内换源(改为阿里源之后安装成功):

  1. $ sudo vim /etc/apt/sources.list
  2. deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  4. deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  6. deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  7. deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  9. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  11. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

2)不同机器的perf.data读不出数据

perf record后的perf.data数据只能在本机上report并进行函数栈追踪,如果本机下载服务器的perf.data,将无法追踪函数栈,结果会全部都是planning_node,没有分析价值。
图片.png

解决方法:
过程:perf源码中有perf archive命令,用于将相关符号打包,方便在其它机器进行分析;但实际运用中报错perf archive is not a perf-command,可能是文档问题,故查看perf源码将perf-archive脚本从源码中提出,手动进行:

  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # perf archive
  4. # Arnaldo Carvalho de Melo <acme@redhat.com>
  5. PERF_DATA=perf.data
  6. if [ $# -ne 0 ] ; then
  7. PERF_DATA=$1
  8. fi
  9. #
  10. # PERF_BUILDID_DIR environment variable set by perf
  11. # path to buildid directory, default to $HOME/.debug
  12. #
  13. if [ -z $PERF_BUILDID_DIR ]; then
  14. PERF_BUILDID_DIR=~/.debug/
  15. else
  16. # append / to make substitutions work
  17. PERF_BUILDID_DIR=$PERF_BUILDID_DIR/
  18. fi
  19. BUILDIDS=$(mktemp /tmp/perf-archive-buildids.XXXXXX)
  20. NOBUILDID=0000000000000000000000000000000000000000
  21. perf buildid-list -i $PERF_DATA --with-hits | grep -v "^$NOBUILDID " > $BUILDIDS
  22. if [ ! -s $BUILDIDS ] ; then
  23. echo "perf archive: no build-ids found"
  24. rm $BUILDIDS || true
  25. exit 1
  26. fi
  27. MANIFEST=$(mktemp /tmp/perf-archive-manifest.XXXXXX)
  28. PERF_BUILDID_LINKDIR=$(readlink -f $PERF_BUILDID_DIR)/
  29. cut -d ' ' -f 1 $BUILDIDS | \
  30. while read build_id ; do
  31. linkname=$PERF_BUILDID_DIR.build-id/${build_id:0:2}/${build_id:2}
  32. filename=$(readlink -f $linkname)
  33. echo ${linkname#$PERF_BUILDID_DIR} >> $MANIFEST
  34. echo ${filename#$PERF_BUILDID_LINKDIR} >> $MANIFEST
  35. done
  36. tar cjf $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
  37. rm $MANIFEST $BUILDIDS || true
  38. echo -e "Now please run:\n"
  39. echo -e "$ tar xvf $PERF_DATA.tar.bz2 -C ~/.debug\n"
  40. echo "wherever you need to run 'perf report' on."
  41. exit 0

在测试机上运行:
$ ./perf-archive.sh -i perf.data
生成符号表二进制文件:perf.data.tar.bz2

之后在任何机器上,只要复制perf.data和perf.data.tar.bz2就可以分析
运行命令:
$ tar xvf perf.data.tar.bz2 -C ~/.debug
图片.png图片.png