The Register Likes DTrace

…and so do I; after having a 20 minute introduction to it c/o Darren Moffat midweek, I am positively enthused about DTrace.

The Register article [www.theregister.co.uk] suffers from having to explain DTrace to ordinary people; for Unix geeks it is probably fastest to say:

It’s the bastard offspring of an unholy three-way union between your favourite symbolic debugger, and KADB, and AWK; and it’s totally cool.

There seem to be some good examples at [users.tpg.com.au] linked from [www.sun.com]

I’ve seen stuff like a five-line shellscript which will dump every write() that any process performs – of length greater than 100 bytes with a full stack traceback if desired.

Or neutering processes: intercept each time that a process called “ssh” attempts to perform connect(); trap the system call and poke it so that it returns -1/ECONNREFUSED.

One thing I can’t find yet is a comprehensive published DTrace cookbook – a directory of dinky scripts that simultaneously do useful things and also demonstrate basic functions. When I find one, I’ll let you know.

Skimming the guide, this is a very basic example extract from [docs.sun.com]

Example 3-1 rtime.d: Compute Time Spent in read(2)

 syscall::read:entry {  self->t = timestamp; } syscall::read:return /self->t != 0/ {  printf(“%d/%d spent %d nsecs in read(2)\n”,  pid, tid, timestamp – self->t);  /*  * We’re done with this thread-local variable;  * assign zero to it to allow the DTrace runtime  * to reclaim the underlying storage.  */  self->t = 0; } 

and it continues…

If you find a process that’s of particular interest, add a predicate to learn more about its read(2) behavior:
 syscall::read:entry /execname == “Xsun”/ {  self->t = timestamp; } 

Comments

7 responses to “The Register Likes DTrace”

  1. Gene
    re: The Register Likes DTrace

    Alec, Alec. There’s a OneStop page on dtrace! At least, there was, the last time I was able to look (4/5/4). Sorry I can’t cut and paste the URL; I’m sure you understand.

  2. alecm
    re: The Register Likes DTrace

    ya ya; i suppose i can go prod the owner with the “WIBNI we had a cookbook” idea…

  3. 192.18.1.5
    re: The Register Likes DTrace

    I guess you’ve not bumped into Jon Haslam in a while – he seems to be the DTrace evangelist for as wide a circle around him as will listen, and is also posting nifty bits of D on his external blog – http blogs.sun.com/roller/page/jonh/ .

  4. alecm
    What I Want From DTrace

    Been there, done that, read the blog.

    What I want is a colelcted archive of examples, and an associated book; cf: the Camel book for Perl, and the tarball of associated scripts.

    I am a hacker. I want a DIY buffet of food to select from – not a selection of once-weekly demonstrations by a chef.

  5. Brendan Gregg
    re: The Register Likes DTrace

    Thanks for the link to my DTrace examples Alec!

    I’ve actually checked your site occasionally in the past while researching Unix security history… Although I must confess that the first time I found your web site was after a web search on how to build antennas! 🙂

    Brendan

    [Sydney, Australia]

  6. alecm
    re: The Register Likes DTrace

    you’re welcome!

    oh my god, does this mean i am historic? oh dear… 😎

  7. Brendan Gregg
    re: The Register Likes DTrace

    historic in a good way. 😉

    hmm, historic does indeed have an awkward ring to it. It’s probably better to describe you as a living legend!

Leave a Reply

Your email address will not be published. Required fields are marked *