For string arguments use $$1

-Angelo


On Sep 12, 2009, at 3:07 PM, Stathis Kamperis wrote:

Greetings to everyone.
I wrote a script to calculate how much time is spent on the system
calls originating from a specific executable:

#!/usr/sbin/dtrace -s

/*
* Generate table statistics on how much time is spent on every system call,
* for a given program (its name is assigned to $1).
*/

#pragma D option quiet

syscall:::entry
/execname == $1/
{
       self->sstart = timestamp;
}

syscall:::return
/execname == $1/
{
       @timestats[probefunc] = avg(timestamp - self->sstart);
       @cntstats[probefunc] = count();
       self->sstart = 0;
}

tick-1sec
{
printf("%20s | %20s | %5s\n", "Function", "<ns> over 1-sec period",
                               "Count");
       printa("%20s   %...@d  %...@d\n", @timestats, @cntstats);
       printf("\n");
}

Here's the deal:

1. If I leave $1 without double quotes " and the execname I pass has a
dot in it, it (accidentally?) works ok:
$ pfexec ./temp.sh
...

In another terminal:
$ pfexec ./lala.d temp.sh

           Function | <ns> over 1-sec period | Count
             getgid                      873       2
             getuid                      981       2
              umask                     1032       2
          sysconfig                     1077       9
          getrlimit                     1279       1
             llseek                     1290       4
              gtime                     1365       1
             getpid                     1437      25

2. If I leave $1 without double quotes " and the execname doesn't have
a dot in it, it fails with:
$ pfexec ./lala.d temp
dtrace: failed to compile script ./lala.d: line 11: failed to resolve
temp: Unknown variable name

3. If I surround $1 with double quotes, it fails not matter what the
supplied argument is:
$ pfexec ./lala.d temp.sh
dtrace: failed to compile script ./lala.d: line 31: extraneous
argument 'temp.sh' ($1 is not referenced)
$ pfexec ./lala.d temp
dtrace: failed to compile script ./lala.d: line 31: extraneous
argument 'temp' ($1 is not referenced)


I guess that I'm wrong in all 3 cases, but just being lucky in 1).
How could I pass an argument (possibly containing spaces) to dtrace
script and use that as a predicate for execname ?

Best regards,
Stathis
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

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

Reply via email to