In this blog post, we’ll look at some of the available PMP profiling tools.
While debugging or analyzing issues with Percona Server for MySQL, we often need a quick understanding of what’s happening on the server. Percona experts frequently use the pt-pmp tool from Percona Toolkit (inspired by http://poormansprofiler.org).
The pt-pmp tool collects application stack traces GDB and then post-processes them. From this you get a condensed, ordered list of the stack traces. The list helps you understand where the application spent most of the time: either running something or waiting for something.
Getting a profile with pt-pmp is handy, but it has a cost: it’s quite intrusive. In order to get stack traces, GDB has to attach to each thread of your application, which results in interruptions. Under high loads, these stops can be quite significant (up to 15-30-60 secs). This means that the pt-pmp approach is not really usable in production.
Below I’ll describe how to reduce GDB overhead, and also what other tools can be used instead of GDB to get stack traces.
|
1 |
# to check if index already exists:<br> readelf -S | grep gdb_index<br># to generate index: <br> gdb -batch mysqld -ex "save gdb-index /tmp" -ex "quit"<br># to embed index:<br> objcopy --add-section .gdb_index=tmp/mysqld.gdb-index --set-section-flags .gdb_index=readonly mysqld mysqld<br> |
Now let’s compare all the above profilers. We will measure the amount of time it needs to take all the stack traces from Percona Server for MySQL under a high load (sysbench OLTP_RW with 512 threads).
The results show that eu-stack (without resolving) got all stack traces in less than a second, and that Quickstack and GDB (with the readnever patch) got very close results. For other profilers, the time was around two to five times higher. This is quite unacceptable for profiling (especially in production).
There is one more note regarding the pt-pmp tool. The current version only supports GDB as the profiler. However, there is a development version of this tool that supports GDB, Quickstack, eu-stack and eu-stack with offline symbol resolving. It also allows you to look at stack traces for specific threads (tids). So for instance, in the case of Percona Server for MySQL, we can analyze just the purge, cleaner or IO threads.
Below are the command lines used in testing:
|
1 |
# gdb & gdb+gdb_index<br> time gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p `pidof mysqld` > /dev/null <br># gdb+readnever<br> time gdb --readnever -ex "set pagination 0" -ex "thread apply all bt" -batch -p `pidof mysqld` > /dev/null <br># eu-stack <br> time eu-stack -s -m -p `pidof mysqld` > /dev/null <br># eu-stack without resolving<br> time eu-stack -q -p `pidof mysqld` > /dev/null <br># quickstack - 1 sample<br> time quickstack -c 1 -p `pidof mysqld` > /dev/null <br># quickstack - 1000 samples<br> time quickstack -c 1000 -p `pidof mysqld` > /dev/null <br> |
Resources
RELATED POSTS