Skip to content

Instantly share code, notes, and snippets.

@nidhi-ag
Last active April 17, 2024 21:31
Show Gist options
  • Save nidhi-ag/0eed632509a79ebc75218a8485a1ebe1 to your computer and use it in GitHub Desktop.
Save nidhi-ag/0eed632509a79ebc75218a8485a1ebe1 to your computer and use it in GitHub Desktop.
## Install perf in docker container
### ubuntu 18.4
### kernel 4.14.173-137.229.amzn2.x86_64
docker exec -it {containerid} sh
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.173.tar.xz && tar -xf ./linux-4.14.173.tar.xz && cd linux-4.14.173/tools/perf/ && apt -y install flex bison && make -C . && make install
./perf
./perf list
./perf bench mem all
Note: Run docker in privileged mode
References
https://medium.com/@geekidea_81313/running-perf-in-docker-kubernetes-7eb878afcd42
https://stackoverflow.com/questions/44745987/use-perf-inside-a-docker-container-without-privileged
## cpu profiling of a process
git clone https://github.com/brendangregg/FlameGraph
cd FlameGraph
/linux-4.14.173/tools/perf/perf record -F 99 -p {pid} -g -- sleep 60
/linux-4.14.173/tools/perf/perf script | ./stackcollapse-perf.pl > out.perf-folded
./flamegraph.pl out.perf-folded > perf-kernel.svg
@kangchunhung
Copy link

THANKS!!!

@MaheshKJembi
Copy link

Thanks

@jmillan
Copy link

jmillan commented Dec 1, 2023

Or simply install it as any other package, adding in the DockerFile:

	apt-get install -y linux-perf linux-base

@mloayzagahona
Copy link

thanks @nidhi-ag

hey @jmillan , your approach doesn't work for ubuntu 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment