Thursday, June 21, 2012

gprof data for MySQL client/server



This post aims to provide detailed steps to get gprof data for MySQL client and server.

Compile time options:
During compilation option -DENABLE_GPROF=1 is supposed to be set which would make it possible to collect gprof data for mysql cleint/server.

Thing to be keep in mind that this option doesn't have any effect if it is issued -DWITH_DEBUG=1 during compilation. The reason for this is, gprof aims to be enabled only for optimized non-debug linux builds.

Platform:
This option works only for linux platform.

Collecting gprof data:
Once compilation is done, change directory to place where MySQL is installed (path given in -DCMAKE_INSTALL_PREFIX option or /usr/local/mysql by default).

Following are the steps to collect gprof data. Start mysql server on a shell:

$ pwd
/home/mayank/mysql-bin

$ ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files

$ ./bin/mysqld
On different shell start mysql client:

$ pwd
/home/mayank/mysql-bin

$ ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files

$ ./bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
<snip>
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
...
<run your queries here>
...
mysql> exit
Bye

$ ./bin/mysqladmin shut -uroot

After above steps MySQL client and server has been stopped. And gprof data has been collected.


Generating gprof data:

For client:
gprof data for client is generated in current directory from where client was started.

$ pwd
/home/mayank/mysql-bin

$ ls
bin COPYING data docs gmon.out include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files

$ gprof ./bin/mysql gmon.out > gprof_client.data


For server:
gprof data for server is generated in data directory.

$ pwd
/home/mayank/mysql-bin

$ cd data/

$ ls
auto.cnf gmon.out ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test

$ cd ..

$ gprof ./bin/mysqld ./data/gmon.out > gprof_server.data

Now we have gprof data for both client (gprof_client.data) and server (gprof_server.data) to be analyzed.