#!/usr/sbin/dtrace -s /* * mysqld_pid_etime.d - measure mysqld query execution latency. * Written for Solaris 10 (needs DTrace). * * 01-Jun-2007, ver 0.50 * * USAGE: ./mysqld_pid_etime.d -p `pgrep -x mysqld` * * This prints distribution plots of the elapsed time during the execution * of MySQL statements, with a plot for each query string traced. This * measure the execution stage only, not the parse or plan stages. * * This is written using the DTrace pid provider, which means it uses an * unstable interface and is likely to stop working for future versions of * mysql (this was tested on mysql-5.1.17-beta). * * 01-Jun-2007 Brendan Gregg Created this. */ #pragma D option quiet dtrace:::BEGIN { printf("Tracing... Hit Ctrl-C to end.\n"); } pid$target::*mysql_parse*:entry { self->query = copyinstr(arg1); } pid$target::*mysql_execute_command*:entry { self->start = timestamp; } pid$target::*mysql_execute_command*:return /self->start/ { this->elapsed = timestamp - self->start; @time[self->query] = quantize(this->elapsed); self->query = 0; self->start = 0; } dtrace:::END { printf("MySQL Query execution latency (ns):\n"); printa(@time); }