Qihua Wu
2009-Jan-17 05:43 UTC
[dtrace-discuss] Can I pass a parameter to Dtrace script as a part of function name?
I want to trace function whose name has certain value, such as "read" or "write". But seems dtrace can''t replace the variable with the value I passed in. bash-3.00$ cat d.d #!/usr/sbin/dtrace -s #pragma D option flowindent syscall::**$1**:entry { self->interest = 1; } fbt::: /self->interest/ {} syscall::**$1**:return { self->interest = 0; } bash-3.00$ ./d.d *read* dtrace: failed to compile script ./d.d: line 5: invalid probe description "* syscall::*$1*:entry*": Undefined macro variable in probe description -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20090117/08bfbb8a/attachment.html>
Steve Scargall
2009-Jan-17 07:46 UTC
[dtrace-discuss] Can I pass a parameter to Dtrace script as a part of function name?
$1 is not a D variable it''s a shell var. Have a look at the "inline" function/operand. http://wikis.sun.com/display/DTrace/Type+and+Constant+Definitions There''s loads of examples in the DTrace Toolkit that you can look at and use as examples. Google "dtrace inline" for more examples. -- This message posted from opensolaris.org
Chad Mynhier
2009-Jan-17 21:27 UTC
[dtrace-discuss] Can I pass a parameter to Dtrace script as a part of function name?
On Sat, Jan 17, 2009 at 12:43 AM, Qihua Wu <dtrace.wu at gmail.com> wrote:> I want to trace function whose name has certain value, such as "read" or > "write". But seems dtrace can''t replace the variable with the value I passed > in. > > bash-3.00$ cat d.d > #!/usr/sbin/dtrace -s > > #pragma D option flowindent > > syscall::*$1*:entry { self->interest = 1; } > fbt::: /self->interest/ {} > syscall::*$1*:return { self->interest = 0; } > > > > bash-3.00$ ./d.d read > dtrace: failed to compile script ./d.d: line 5: invalid probe description > "syscall::*$1*:entry": Undefined macro variable in probe descriptionIf you want to enable exactly one syscall for which you know the name, you could simply match every syscall specify that in the predicate: syscall:::entry / probefunc == $1 / { self->interest = 1; } etc. To use globbing to match syscalls (e.g., read, pread, readv, etc.), try this: #!/bin/sh /usr/sbin/dtrace -n '' #pragma D option flowindent syscall::*''$1''*:entry { self->interest = 1; } fbt::: /self->interest/ {} syscall::*''$1''*:return { self->interest = 0; } '' Note the placement of the single-quotes so that $1 gets replaced by the shell. Chad
Chad Mynhier
2009-Jan-17 22:28 UTC
[dtrace-discuss] Can I pass a parameter to Dtrace script as a part of function name?
On Sat, Jan 17, 2009 at 2:46 AM, Steve Scargall <steve.scargall at sun.com> wrote:> $1 is not a D variable it''s a shell var. Have a look at the "inline" function/operand. http://wikis.sun.com/display/DTrace/Type+and+Constant+Definitions > > There''s loads of examples in the DTrace Toolkit that you can look at and use as examples. Google "dtrace inline" for more examples.Actually, $1 is a macro variable, and it''s designed to be used for things like this. For example, the following works (at least on build 105, I don''t have a stock Solaris 10 system handy at the moment): #!/usr/sbin/dtrace -s syscall::$1:entry { @c[execname,probefunc] = count(); } # ./count-syscall.d read dtrace: script ''./count-syscall.d'' matched 1 probe ^C sshd read 2 # This also works: #!/usr/sbin/dtrace -s syscall::*$1:entry { @c[execname,probefunc] = count(); } # ./count-syscall.d read dtrace: script ''./count-syscall.d'' matched 2 probes ^C sshd read 2 # But placing the ''*'' on the other side doesn''t work: #!/usr/sbin/dtrace -s syscall::$1*:entry { @c[execname,probefunc] = count(); } # ./count-syscall.d read dtrace: failed to compile script ./count-syscall.d: line 3: invalid probe description "syscall::$1*:entry": Undefined macro variable in probe description # I haven''t looked into the code to figure out why this fails, nor have I searched the bug database. I''ll look into it, though. Chad
Chad Mynhier
2009-Jan-25 19:11 UTC
[dtrace-discuss] Can I pass a parameter to Dtrace script as a part of function name?
On Sat, Jan 17, 2009 at 5:28 PM, Chad Mynhier <cmynhier at gmail.com> wrote:> For example, the following works (at least on build > 105, I don''t have a stock Solaris 10 system handy at the moment): > > #!/usr/sbin/dtrace -s > > syscall::$1:entry > { > @c[execname,probefunc] = count(); > } > > # ./count-syscall.d read > dtrace: script ''./count-syscall.d'' matched 1 probe > ^C > > sshd read > 2 > # > > > This also works: > > #!/usr/sbin/dtrace -s > > syscall::*$1:entry > { > @c[execname,probefunc] = count(); > } > > > > # ./count-syscall.d read > dtrace: script ''./count-syscall.d'' matched 2 probes > ^C > > sshd read > 2 > # > > But placing the ''*'' on the other side doesn''t work: > > #!/usr/sbin/dtrace -s > > syscall::$1*:entry > { > @c[execname,probefunc] = count(); > } > > > # ./count-syscall.d read > dtrace: failed to compile script ./count-syscall.d: line 3: invalid > probe description "syscall::$1*:entry": Undefined macro variable in > probe description > # > > I haven''t looked into the code to figure out why this fails, nor have > I searched the bug database. I''ll look into it, though.For the curious, I opened bug 6795386 ("macro arguments and globbing in DTrace probe descriptions don''t mix") for this. I''ve played some with the code, but just enough to make the above work, I didn''t do it in a general enough fashion to cover all cases. I''ll look into a proper fix when I get some time. Chad