3

I'm fairly new to Docker, and I'm trying to use perf to check performance on some stuff. Perf doesn't come with the images I'm using, so I went to install it. I used

apt-get update
apt-get install perf

which didn't work because perf is part of another package. I then tried

apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`

which resulted in

E: Unable to locate package linux-tools-common
E: Unable to locate package linux-tools-generic
E: Unable to locate package linux-tools-3.10.0-862.3.3.el7.x86_64
E: Couldn't find any package by glob 'linux-tools-3.10.0-862.3.3.el7.x86_64'
E: Couldn't find any package by regex 'linux-tools-3.10.0-862.3.3.el7.x86_64'

Any recommendations as to what I should try?

Karan
  • 31
  • 3
  • 1
    `linux-tools-generic` should pull in the version for the current kernel, which includes `perf`. If you don't have your `sources.list` set up correctly, it's not going to work. Also, this isn't really a programming question, it's a sysadmin question. Probably belongs on serverfault, not SO. Voting to migrate (not the same thing as vote-to-close as off topic: should have been asked elsewhere, BTW.) Or not, there's only an option to migrate to Superuser, not Serverfault. – Peter Cordes Jun 21 '18 at 17:55
  • What docker image are running? How are you running your docker container? Btw. performance difference is very small, see [here](https://stackoverflow.com/questions/21889053/what-is-the-runtime-performance-cost-of-a-docker-container). – KamilCuk Jun 21 '18 at 18:12
  • @KamilCuk: I assume the OP simply wants to profile the software with their docker config on their server that runs docker images. That's useful whether or not you compare to the same machine *outside* a docker image. – Peter Cordes Jun 21 '18 at 20:35
  • All I want to be able to do is run perf inside a container to see performance metrics to compare with baremetal metrics. @PeterCordes How should I go about setting up sources.list correctly? It's not something I've ever touched. Also, I'll keep in mind posting location next time, thanks for that pointer. – Karan Jun 21 '18 at 21:56

2 Answers2

1

I assume that you have a fairly recent Linux in your container and an old one on the host.

Note that perf has to be the exact same version as your Linux kernel. And that with containerization the kernel of the host system is used.

When you install the generic perf package in the container the package manager retrieves the version of the (host) kernel and tries to install the perf package with the very same version. Due to the newer version of the Linux distribution in the container, the necessary older perf package is not part of its package repository anymore leading to the error message you are seeing.

There are multiple solutions to this: a) update the host Linux kernel to supported by the containers Linux distribution's release, b) downgrade the containers Linux distribution, or c) make the necessary perf package available in the container. This is probably tricky and you might screw up the container's package manager. But it's just a container ;). You can figure out the necessary version with uname -a.

fzgregor
  • 1,807
  • 14
  • 20
  • I'm actually running a much more recent Linux on my host, and the container has an older one. I went hunting through my filesystem and found that linux-tools came with perf_4.9. I tried using it, and it seems to work fine so far. It's not a great solution considering that the container OS is on 3.10, but it's functional for now. – Karan Jun 25 '18 at 22:09
1

What helped me on Debian 10 was:

apt install linux-perf