Tuesday, May 08, 2007

DTrace and MySQL - 1

With this post, I am starting another series of blog posts that will help you become familiar of DTrace. You can then apply that knowledge to find all the hidden performance goodies of MySQL on Solaris 10. Sounds good?

DTrace is one of those tools that the more you use it, the more you fall in love with it. To be fair, it is much more than a tool, in fact it has its own language, D.

With DTrace you can enable probes by either their name or their number. To see a list of probes available, run
[root@db31:/] dtrace -l | more
ID PROVIDER MODULE FUNCTION NAME
1 dtrace BEGIN
2 dtrace END
3 dtrace ERROR
4 syscall nosys entry
5 syscall nosys return
6 syscall rexit entry
7 syscall rexit return
8 syscall forkall entry
9 syscall forkall return
10 syscall read entry
11 syscall read return
12 syscall write entry
13 syscall write return
14 syscall open entry
15 syscall open return
16 syscall close entry
17 syscall close return
18 syscall wait entry
19 syscall wait return
20 syscall creat entry
21 syscall creat return
...
.

To enable a basic probe named BEGIN with the id of 1, we can either use:

[root@db31:/] dtrace -n BEGIN
dtrace: description 'BEGIN' matched 1 probe
CPU ID FUNCTION:NAME
1 1 :BEGIN
^C
or
[root@db31:/] dtrace -i 1
dtrace: description '1' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN
^C

In addition, to enabling individual probes, we can also enable multiple probes simply be specifying them on the command line. For instance:
[root@db31:/] dtrace -i 1 -i 2 -i 3
dtrace: description '1' matched 1 probe
dtrace: description '2' matched 1 probe
dtrace: description '3' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN
^C
0 2 :END

or
[root@db31:/] dtrace -n BEGIN -n END -n ERROR
dtrace: description 'BEGIN' matched 1 probe
dtrace: description 'END' matched 1 probe
dtrace: description 'ERROR' matched 1 probe
CPU ID FUNCTION:NAME
1 1 :BEGIN
^C
0 2 :END

If you try to enable a probe that is not valid, you will get an error like this:

[root@db31:/] dtrace -n BEGIN -n END -n ERRORS
dtrace: invalid probe specifier ERRORS: probe description :::ERRORS does not match any probes

For a complete and in-depth coverage of DTrace, make sure you check out Solaris Dynamic Tracing Guide. For those looking to dive into examples right away, checkout the /usr/demo/dtrace directory on your Solaris machine.

to be continued...

No comments: