... h1. DTrace Basics Demo (10 Minutes)
h4. Description This demo showcases the advantages DTrace on various D scripts. It shows how much you can learn about the scripts with very little D code.
h4. OpenSolaris Versions Supported OpenSolaris 2008.05 or higher.
h4. Points to Hit * DTrace is very cool * One tracing tool for kernel and applications * You can trace various languages as well (e.g. Java, PHP, JavaScript, Python, etc.) * Although D language is not simple to learn you can still download many free scripts * You can really know what is happening in the system and that makes you a better admin/developer * You can hunt bugs and improve performance of your applications |
... None known.
h4. Demo * Run *dtrace -l* to show all probes. The purpose of doing this is to show that there is a lot of probes available. Press Ctrl-C to stop the output and explain the listing (what does the user see in the listing - number, providers, modules, probe names and entry vs. return). For a quick overview see http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Guide. * Which system calls are being executed? This script shows all system calls executed while the script is running. Explain the basics of D language. Create file syscall.d: {noformat} syscall:::entry { printf("%s(%d) called %s\n", execname, pid, probefunc); } {noformat} * Run *dtrace -qs syscall.d*. You will see system calls appearing as you use the OS. * Copy syscall.d to java_syscall.d - this time we will use a predicate to monitor only java processes: {noformat} syscall:::entry /execname == "java"/ { printf("Java(%d) called syscall %s\n", pid, probefunc); } {noformat} * Run *dtrace -qs java_syscall.d*. Run a java application (e.g. NetBeans). You will now see only java-related system calls. * IO usage table - what is the IO distribution? Mention that D language supports different aggregation functions, e.g. sum and quantize. These are great if you want to count number of executions, IO, network traffic, etc. Create file count_io.d {noformat} io:::start { @total = sum(args[0]->b_bcount); @dist = quantize(args[0]->b_bcount); }
END { printa("Total IO completed %@d\n",@total); printf("The IO distribution \n"); printa(@dist); } {noformat} * Run *dtrace -qs count_io.d*. * We've added support for DTrace into different languages distributed with OpenSolaris (Java, PHP, Python, JavaScript, etc.). Show when Java does garbage collection - create file gc.d {noformat} hotspot$target:::gc-begin { printf("GC started at %Y\n",walltimestamp); } {noformat} * Start NetBeans IDE. * Run *ps -ef | grep java* to find out the process id of NetBeans. * Run *dtrace -qs gc.d -p process_id* where process_id is the process ID of NetBeans. Garbage collections should appear as they happen (you can force garbage collection by clicking on the memory bar in NetBeans). * What happens on Firefox startup? Create firefox.d {noformat} syscall::open:entry /execname == "firefox-bin"/ { @[copyinstr(arg0)] = count(); } {noformat} * Run *dtrace -qs firefox.d*. The copyinstr function copies data from kernel space to user space. * Ultimate question - what happens in the system when I press a key? Create key.sh {noformat} pfexec dtrace -F -n 'fbt:conskbd:conskbdlrput:entry { self->in = 1; }' -n 'fbt:::/self->in/{}' -n 'fbt:conskbd:conskbdlrput:return/self->in/{ exit(0); }' {noformat} * Run *./key.sh*. Press a key. Lots of calls will appear (after a while - be patient). You don't have to explain this D script :)
h4. Demo Cleanup None. |