Spec-Zone .ru
спецификации, руководства, описания, API

5.7.1.3. Query Probes

The query-start and query-done probes are triggered when a specific query is received by the server and when the query has been completed and the information has been successfully sent to the client.

query-start(query, connectionid, database, user, host)query-done(status)

You can get a simple report of the execution time for each query using the following D script:

#!/usr/sbin/dtrace -s#pragma D option quietdtrace:::BEGIN{   printf("%-20s %-20s %-40s %-9s\n", "Who", "Database", "Query", "Time(ms)");}mysql*:::query-start{   self->query = copyinstr(arg0);   self->connid = arg1;   self->db    = copyinstr(arg2);   self->who   = strjoin(copyinstr(arg3),strjoin("@",copyinstr(arg4)));   self->querystart = timestamp;}mysql*:::query-done{   printf("%-20s %-20s %-40s %-9d\n",self->who,self->db,self->query,          (timestamp - self->querystart) / 1000000);}

When executing the above script you should get a basic idea of the execution time of your queries:

shell> ./query.dWho                  Database             Query                                    Time(ms)root@localhost       test                 select * from t1 order by i limit 10     0root@localhost       test                 set global query_cache_size=0            0root@localhost       test                 select * from t1 order by i limit 10     776root@localhost       test                 select * from t1 order by i limit 10     773root@localhost       test                 select * from t1 order by i desc limit 10 795