我知道“perf”工具需要安装对应特定的linux内核版本。而且我知道所有 docker 镜像都使用相同的 linux 内核版本运行,无论 linux 分发版本如何。
我在 docker 中使用 ubuntu 16.04 并且已经安装了 linux-tools-common,启动 perf 告诉我我仍然缺少一些包:'
# perf
/usr/bin/perf: line 32: lsb_release: command not found
WARNING: perf not found for kernel 4.9.12
You may need to install the following packages for this specific kernel:
linux-tools-4.9.12-moby
linux-cloud-tools-4.9.12-moby
You may also want to install one of the following packages to keep up to date:
linux-tools-moby
linux-cloud-tools-moby
然后我尝试安装我错过的东西:
root@xxxxxx:/# apt-get install linux-tools-4.9.12-moby linux-cloud-tools-4.9.12-moby
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-tools-4.9.12-moby
E: Couldn't find any package by glob 'linux-tools-4.9.12-moby'
E: Couldn't find any package by regex 'linux-tools-4.9.12-moby'
E: Unable to locate package linux-cloud-tools-4.9.12-moby
E: Couldn't find any package by glob 'linux-cloud-tools-4.9.12-moby'
E: Couldn't find any package by regex 'linux-cloud-tools-4.9.12-moby'
root@b2543b6e985d:/# apt-get install linux-tools-moby linux-cloud-tools-moby
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-tools-moby
E: Unable to locate package linux-cloud-tools-moby
(1)好奇怪,这个安装问题怎么解决呢?
(2) 另外:我还是很疑惑,如果“perf”和“kernel”之间没有严格的匹配,那么“perf”怎么能在linux的docker中运行良好呢?
最佳答案
I knew that "perf" tool requires installation correspond to specific linux kernel versions. And I knew that all docker images run with the same linux kernel version, no matter linux distribution version.
仍然可以使用来自其他版本内核的 Perf 工具(perf_event
子系统中的系统调用具有良好的设计并且与旧/新工具兼容)。因此,您可以在任何地方找到任何 perf 二进制文件(不是 /usr/bin/perf
脚本),检查其库依赖于 (ldd ..path_to_perf/perf
) 和在 Docker 中复制 perf(并安装库)。
硬件事件、系统范围或内核分析的使用可能在 docker 中受到限制,因此请尝试
perf -e cycles:u ./program
(仅用于用户空间的硬件计数器),perf -e task-clock ./program
(内核和用户空间的软件定时器),perf -e task-clock:u ./program
(仅用于用户空间的软件定时器),
关于Linux "Perf"工具无法在 docker 镜像中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42921793/