Alan Hargreaves' Blog

The ramblings of a former Australian SaND TSC* Principal Field Technologist

Some DTrace scripts I found useful last week

Last week I spent some time looking at applications that a customer was using to perform a data migration. It occurs to me that folks might be interested in a couple of the “one liner” type scripts that I found useful after turning them into ‘stat’ type tools. So, here they are.

funcs.d

#!/usr/sbin/dtrace -s
#pragma D option quiet
/*
* Count all user space function calls
*
* $1 - time to run (eg 10s)
* $2 - pid to monitor
*/
pid$2:::entry {
@[probefunc] = count();}
tick-$1 {
printa(@);
clear(@);
printf("--------\n");}

syscalls.d

#!/usr/sbin/dtrace -s
#pragma D option quiet
/*
* Count the syscalls a process is making as a stat tool
*
* $1 time to wait (eg 10s)
* $2 target pid
*/
syscall:::entry /pid == $2/ {
@[probefunc] = count();}
tick-$1 {
printa(@);
printf("--------\n");
clear(@);}

systimes.d

#!/usr/sbin/dtrace -s
#pragma D option quiet
/*
* Count the syscalls a process is making as a stat tool
*
* $1 time to wait (eg 10s)
* $2 target pid
*/
syscall:::entry /pid == $2/ {
self->start = vtimestamp;}
syscall:::return /self->start/ {
@[probefunc] = quantize((vtimestamp - self->start)/1000);}
tick-$1 {
printa(@);
printf("--------\n");
clear(@);}

ustk.d

#!/usr/sbin/dtrace -s
#pragma D option quiet
/*
* Aggregate user stacks calling a function in user space
*
* $1 - time to run (eg 10s)
* $2 - pid to monitor
* $3 - function to look for
*/
pid$2::$3:entry {
@[ustack(30)] = count();}
tick-$1 {
printa(@);
clear(@);
printf("--------\n");}

Technorati Tags:
,

Advertisements

Written by Alan

November 21, 2006 at 9:06 pm

Posted in Solaris

2 Responses

Subscribe to comments with RSS.

  1. There is something “not quite right” in funcs.c
    # /export/home/dclarke/funcs.d
    dtrace: failed to compile script /export/home/dclarke/funcs.d: line 12: invalid probe description “pid$2:::entry”: Undefined macro variable in probe description
    #
    # uname -a
    SunOS titan 5.10 Generic_118855-19 i86pc i386 i86pc

    Dennis Clarke

    January 14, 2007 at 6:37 pm

  2. oops ..
    never mind
    # /export/home/dclarke/funcs.d 5 12834

    Dennis Clarke

    January 14, 2007 at 6:41 pm


Comments are closed.

%d bloggers like this: