On Mon, Nov 03, 2008 at 04:31:20AM -0800, [EMAIL PROTECTED] wrote:
> I am very now to DTrace land. 
> 
> 1) I want to write a DTrace script which takes -verbose or --verbose as an 
> option.
> 
> #!/usr/sbin/dtrace -s
> #pragma D option quiet
> 
> pid$1::func1:entry
> {
>     /* should be called only when verbose option is provided in command line 
> */
>    printf("Entered %s ...\n", probefunc);
> }
> pid$1::func2:entry,
> {
>     /* should be called always */
> }
> END 
> {
>     /* should be called always */
>     /* print out summary */
> }
> 
> It should be normally run as 
> $./myscript.d 9149 
> (where 9149 is the pid of the process I want to trace)
> 
> when I want more detailed information, I should be able to run it as 
> $./myscript.d 9149 --verbose
> 
> Is something of this sort possible ?

Not directly;  you can't have optional arguments to your script.

Your options are:

1.  Write a shell script that runs dtrace; you could do:

#!/bin/sh

verbose=0
if [[ $1 = "--verbose" ]]; then
        shift
        verbose=1
fi
pid=$1

/usr/sbin/dtrace -s /dev/stdin <<EOF
#pragma D option quiet

pid$pid::func1:entry
/ $verbose /
{
   printf("Entered %s ...\n", probefunc);
}
...
EOF

> 2) Also I saw that END gets executed when I press Control C. But when I want 
> to send output to another file via tee as shown below :
> $./myscript.d |tee dtrace.log
> and when I press control C, it doesn't get called. Any ideas?

Your control-C is killing tee;  END is getting executed, but the pipe is closed
by the death of tee.  You could do:

% ./myscript.d > dtrace.log

(in another window)
% tail -f dtrace.log

Cheers,
- jonathan

_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

Reply via email to