Created
January 28, 2014 19:10
-
-
Save justinrainbow/8674133 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/sbin/dtrace -s | |
/* | |
* mysql_db_slow.d Trace queries slower than specified ns. | |
* | |
* USAGE: ./mysql_db_slow.d min_ns | |
*/ | |
#pragma D option quiet | |
#pragma D option defaultargs | |
#pragma D option switchrate=10hz | |
#pragma D option strsize=1024 | |
dtrace:::BEGIN | |
/$1 == 0/ | |
{ | |
printf("USAGE: %s min_ms\n\n", $$0); | |
printf("\teg: %s 100\n", $$0); | |
exit(1); | |
} | |
dtrace:::BEGIN | |
{ | |
dbname = "enter-db-name-here"; | |
min_ns = $1 * 1000000; | |
printf("Tracing... Min query time: %d ns.\n\n", min_ns); | |
} | |
mysql*:::query-start /* using the mysql provider */ | |
{ | |
self->start = timestamp; | |
self->vstart = vtimestamp; | |
self->query = copyinstr(arg0); /* Get the query */ | |
self->db = copyinstr(arg2); /* Get the DB name */ | |
self->who = strjoin(copyinstr(arg3), strjoin("@", copyinstr(arg4))); /* Get the username */ | |
} | |
mysql*:::query-done | |
/self->start && (timestamp - self->start) > min_ns && dbname == self->db/ | |
{ | |
this->time = (timestamp - self->start) / 1000000; | |
this->vtime = (vtimestamp - self->vstart) / 1000000; | |
printf("%-8d %-8d\t %20s\t Database: %s\n", this->time, this->vtime, self->who, self->db); | |
printf("%s\n\n---------\n\n", self->query); | |
} | |
mysql*:::query-done | |
/self->start && (timestamp - self->start) > min_ns/ | |
{ | |
self->query = 0; | |
self->start = 0; | |
self->vstart = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment