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.

3 comments:

  1. but i refer to the mysql manual, no compile option named "ENABLE_GPROF"
    here are all options
    http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

    ReplyDelete
    Replies
    1. Hi Ch,

      Thanks for ur comment.

      This option is added in 5.6.6 so is not available in 5.5.

      Please refer to 5.6 documentation. Here is the link :
      http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

      Delete