背景

在性能调优中,intel vtune是使用频率仅次于perf的工具。intel vtune相比perf有以下优势:

  • 带GUI,方便指标结合source/asm code进行快速分析。如下图

alt text

  • 可进行top-down performance analysis。如下图

alt text

由于我们的linux server都不带图形界面,所以一般的做法是这样的:在开发机上安装带gui的vtune,在linux server上安装带命令行的vtune,然后再linux server上使用vtune对正在运行的process进行采样,接着将采样结果下载到开发机中,导入vtune gui, 进行后续分析。

这种做法的缺点是:

  • 每次采样完都需要将结果从linux server中同步到开发机中。
  • binary和source directory太大,无法同步,也就无法在vtune gui中查看source/asm code

因此考虑在linux server中安装桌面环境,再在开发机上通过xrdp远程连接linux server。

配置步骤

xrdp远程连接参考:https://learn.microsoft.com/zh-cn/azure/virtual-machines/linux/use-remote-desktop?tabs=azure-cli

安装带gui的vtune: https://www.intel.com/content/www/us/en/docs/vtune-profiler/installation-guide/2023-1/regular-install.html#STANDALONE

常见问题:

  • 由于linux server iptables限制,开发机无法通过xrdp默认端口远程连接linux server。参考:https://blog.csdn.net/zzh_my/article/details/106075759 修改端口后重启linux server上的xrdp, sudo service xrdp restart
  • 通过vtune-gui启动vtune后,窗口会黑屏。~/.xsession-erros报错如下。参考:https://github.com/deltachat/deltachat-desktop/issues/3592 在ubuntu docker启动时加上-ipc=host选项:
sudo docker run  --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --privileged=true --ipc=host --name dev_ly --net=host  --init   -v /var/run/docker.sock:/var/run/docker.sock  -v /data1:/data1 -d  dev_ly/20240223  /bin/bash -c "tail -f /dev/null"

[25226:0223/103815.520120:ERROR:broker_posix.cc(46)] Received unexpected number of handles
Error sending from webFrameMain: Error: Render frame was disposed before WebFrameMain could be accessed
at EventEmitter.n.send (node:electron/js2c/browser_init:165:417)
at EventEmitter.b.send (node:electron/js2c/browser_init:161:2494)
at /opt/intel/oneapi/vtune/2022.4.0/bin64/resources/app/scripts/ipc-handler.js:46:34
at processTicksAndRejections (node:internal/process/task_queues:96:5)

注意:每次重启系统之后记得开启 xrdp和lightdm: sudo service xrdp restart && sudo service lightdm restart

常用命令

采样:vtune -collect uarch-exploration -target-pid=pidof clickhouse-server 导入采样结果:vtune-gui <采样结果目录>

效果:

memory-consumption

alt text

uarch-exploration

alt text

performance-snapshot

alt text

hpc-performance

alt text

memory-access

alt text