DTraceBasicsDemo

DTrace Basics Demo (10 Minutes)

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.

OpenSolaris Versions Supported

OpenSolaris 2008.05 or higher.

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

Demo Prep

I advise to copy the code listed below into separate files and then just explain the code and run the scripts during presentation. You can also download all the used scripts from here.

Gotchas

None known.

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:
    syscall:::entry
    {
          printf("%s(%d) called %s\n", execname, pid, probefunc);
    }
    
  • 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:
    syscall:::entry
    /execname == "java"/
    {
              printf("Java(%d) called syscall %s\n", pid, probefunc);
    }
    
  • 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
    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);
    }
    
  • 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
    hotspot$target:::gc-begin
    {
            printf("GC started at %Y\n",walltimestamp);
    }
    
  • 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
    syscall::open:entry
    /execname == "firefox-bin"/
    {
            @[copyinstr(arg0)] = count();
    }
    
  • 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
    pfexec dtrace -F -n 'fbt:conskbd:conskbdlrput:entry { self->in = 1; }' -n 'fbt:::/self->in/{}' -n 'fbt:conskbd:conskbdlrput:return/self->in/{ exit(0); }'
    
  • 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

Demo Cleanup

None.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact