Isn't this something that would be well suited for DTrace? I am assuming you are running Solaris 10...
Sorry I was in a meeting the first go around Brendan Gregg would do something like this
* 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 execu
* 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
* unstable interface and is likely to stop working for future version
* mysql (this was tested on mysql-5.1.17-beta).
* 01-Jun-2007 Brendan Gregg Created this.
#pragma D option quiet
printf("Tracing... Hit Ctrl-C to end.\n");
self->query = copyinstr(arg1);
self->start = timestamp;
this->elapsed = timestamp - self->start;
@time[self->query] = quantize(this->elapsed);
self->query = 0;
self->start = 0;
printf("MySQL Query execution latency (ns):\n");
There is a lot more detail to be found HERE
Hope this points you in the right direction. Cheers - Jeffery