public
Created

MySQL FS Latency DTrace script

  • Download Gist
mysqld_pid_fslatency.d
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/sbin/dtrace -s
/*
* mysqld_pid_fslatency.d Print file system latency distribution every second.
*
* USAGE: ./mysqld_pid_fslatency.d -p mysqld_PID
*
*/
 
#pragma D option quiet
 
dtrace:::BEGIN
{
printf("Tracing PID %d... Hit Ctrl-C to end.\n", $target);
}
 
pid$target::os_file_read:entry,
pid$target::os_file_write:entry,
pid$target::my_read:entry,
pid$target::my_write:entry
{
self->start = timestamp;
}
 
pid$target::os_file_read:return { this->dir = "read"; }
pid$target::os_file_write:return { this->dir = "write"; }
pid$target::my_read:return { this->dir = "read"; }
pid$target::my_write:return { this->dir = "write"; }
 
pid$target::os_file_read:return,
pid$target::os_file_write:return,
pid$target::my_read:return,
pid$target::my_write:return
/self->start/
{
@time[this->dir] = quantize(timestamp - self->start);
@num = count();
self->start = 0;
}
 
dtrace:::END
{
printa("MySQL filesystem I/O: %@d; latency (ns):\n", @num);
printa(@time);
clear(@time); clear(@num);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.