I am running some application inside a Docker container and want to do some profiling to see statistics like what functions in the application consumes most of the CPU and etc. The Linux Perf tool looks like a good fit, but it seems Perf cannot be used in Docker containers since it does not have the permission to access the hardware counters. Any suggestion on how to use Perf in the container, or what other tools can be used? Thanks!
Asked
Active
Viewed 3,494 times
4
-
Is this related to https://stackoverflow.com/questions/46674444/is-it-possible-to-run-linux-perf-tool-inside-docker-container ? – jmoney Dec 10 '18 at 03:08
-
@jmoney I installed Perf in Docker container as suggested by the above question, but as I mentioned, ''it seems Perf cannot be used in Docker containers since it does not have the permission to access the hardware counters". – Qi Zhang Dec 10 '18 at 03:11
-
Have you tried running your Docker container with `--privileged` flag ? It works for me (with a Wordpress container) – Arnabjyoti Kalita Dec 11 '18 at 17:01
-
@ArnabjyotiKalita Yes, I did. I think that will make the Perf in the priviledger container to get the system-wise data, but what I want to have is the data for a specific container only. – Qi Zhang Dec 14 '18 at 19:01
1 Answers
1
if you wanna just profile a specific container, you can try -G/--cgroups option when use perf. if you want to do profiling in docker, you can try:
# profile in docker with --privileged for 20s
perf record -e cpu-clock -G . -a -g -- sleep 20
if you want to do profiling in host, you can try:
# perf will try to read /sys/fs/cgroup/perf_event/docker/{containerID}
perf record -e cpu-clock -G /docker/`docker inspect -f '{{.ID}}'` -a -g -- sleep 20
anyway, when we use '-G/--cgroup', perf will try to filter data by cgroup info. some refs which may be helpful:

AshinZ
- 136
- 2