mvmvmv1234 at yahoo.com
2008-Nov-03 12:31 UTC
[dtrace-discuss] Passing arguments to DTrace script
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 ? 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?
On Mon, Nov 03, 2008 at 04:31:20AM -0800, mvmvmv1234 at yahoo.com 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
mvmvmv1234 at yahoo.com
2008-Nov-05 10:21 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
I have an executable. When I attach a truss, we have to give $truss -o truss.out -fall ./a.out. It shows all system calls made by this program and all the child processes it forks. Where as if I am using a DTrace script I am not able to do it. ./sample.d -c "a.out" pid$1::somefunctionname:entry { printf("%s is called by %d",probefunc, tid); }
mvmvmv1234 at yahoo.com
2008-Nov-05 11:00 UTC
[dtrace-discuss] Passing arguments to DTrace script
Thanx, I will make it work with -x defaultargs that way both $./sample.d and $./sample.d verbose will work.
Angelo Rajadurai
2008-Nov-05 14:52 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
Change $1 to $target! (ie) ./sample.d -c "a.out" pid$target::somefunctionname:entry { printf("%s is called by %d",probefunc, tid); } In case you want to find the funcstions of a running process (say pid 1234) you have two options. ./sample.d --p 1234 pid$target::somefunctionname:entry { printf("%s is called by %d",probefunc, tid); } or ./sample.d 1234 pid$1::somefunctionname:entry { printf("%s is called by %d",probefunc, tid); } HTHs Angelo On Nov 5, 2008, at 5:21 AM, mvmvmv1234 at yahoo.com wrote:> I have an executable. When I attach a truss, we have to give $truss - > o truss.out -fall ./a.out. It shows all system calls made by this > program and all the child processes it forks. > > Where as if I am using a DTrace script I am not able to do it. > > ./sample.d -c "a.out" > pid$1::somefunctionname:entry > { > printf("%s is called by %d",probefunc, tid); > } > > > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org
mvmvmv1234 at yahoo.com
2008-Nov-06 09:02 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
What I mean to ask is will PID provider trace child processes forked by the parent process? --- On Wed, 11/5/08, Angelo Rajadurai <Angelo.Rajadurai at Sun.COM> wrote:> From: Angelo Rajadurai <Angelo.Rajadurai at Sun.COM> > Subject: Re: [dtrace-discuss] truss "-fall" equivalent in DTrace > To: mvmvmv1234 at yahoo.com > Cc: dtrace-discuss at opensolaris.org > Date: Wednesday, November 5, 2008, 2:52 PM > Change $1 to $target! > > (ie) > > ./sample.d -c "a.out" > pid$target::somefunctionname:entry > { > printf("%s is called by %d",probefunc, tid); > } > > In case you want to find the funcstions of a running > process (say pid 1234) > you have two options. > > ./sample.d --p 1234 > pid$target::somefunctionname:entry > { > printf("%s is called by %d",probefunc, tid); > } > > or > ./sample.d 1234 > pid$1::somefunctionname:entry > { > printf("%s is called by %d",probefunc, tid); > } > > > HTHs > > Angelo > > On Nov 5, 2008, at 5:21 AM, mvmvmv1234 at yahoo.com wrote: > > > I have an executable. When I attach a truss, we have > to give $truss -o truss.out -fall ./a.out. It shows all > system calls made by this program and all the child > processes it forks. > > > > Where as if I am using a DTrace script I am not able > to do it. > > > > ./sample.d -c "a.out" > > pid$1::somefunctionname:entry > > { > > printf("%s is called by %d",probefunc, > tid); > > } > > > > > > > > > > _______________________________________________ > > dtrace-discuss mailing list > > dtrace-discuss at opensolaris.org
michael schuster
2008-Nov-06 10:21 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
mvmvmv1234 at yahoo.com wrote:> What I mean to ask is will PID provider trace child processes forked by the parent process?no. You need to trace fork/exec system calls (or similar events) and run a new script (or the same again ...) with appropriate arguments (ie pid). HTH Michael -- Michael Schuster http://blogs.sun.com/recursion Recursion, n.: see ''Recursion''
There is another way. Let cpp handle the arguments: #!/usr/sbin/dtrace -Cs syscall:::entry { #ifdef VERBOSE printf("%s", probefunc); #endif @[probefunc] = count(); } cjg at principia:~/lang/d$ pfexec /usr/sbin/dtrace -Cs /tmp/cpp.d -n ''tick-1s { exit(0) }'' dtrace: script ''/tmp/cpp.d'' matched 234 probes dtrace: description ''tick-1s '' matched 1 probe CPU ID FUNCTION:NAME 0 69410 :tick-1s close 1 llseek 1 lseek 1 mmap 1 open64 1 yield 1 fstat64 2 gtime 2 statvfs 2 sigaction 4 lwp_sigmask 5 setcontext 5 sysconfig 5 brk 6 setitimer 10 portfs 16 clock_gettime 21 getpid 26 p_online 34 writev 50 write 60 read 99 lwp_park 102 pollsys 192 ioctl 256 cjg at principia:~/lang/d$ pfexec /usr/sbin/dtrace -Cs /tmp/cpp.d -D VERBOSE -n ''tick-1s { exit(0) }'' 0 69231 pollsys:entry pollsys 0 68915 write:entry write 0 68913 read:entry read 0 68913 read:entry read 0 69007 ioctl:entry ioctl 0 69231 pollsys:entry pollsys ....... -- This message posted from opensolaris.org
First one note about your comparison with truss. As you said, truss follows child processes when tracing system calls. But system calls != user-land functions. Actually you can write dtrace script which will trace system calls of your program and will follow forked child processes as well as truss -fall is doing it using syscall provider - it''s probes are system-wide so there''s really nothing that would avoid you to write a d script which would trace syscalls, and log down only those records which would match particular PID and all its child PIDs (it is easy within dtrace to track PIDs and dynamically keep PID tree of some process). When doing user-land tracing, child following is much more complicated. See https://www.opensolaris.org/jive/thread.jspa?messageID=226151 Remek On Wed, Nov 5, 2008 at 11:21 AM, mvmvmv1234 at yahoo.com <mvmvmv1234 at yahoo.com> wrote:> I have an executable. When I attach a truss, we have to give $truss -o truss.out -fall ./a.out. It shows all system calls made by this program and all the child processes it forks. > > Where as if I am using a DTrace script I am not able to do it. > > ./sample.d -c "a.out" > pid$1::somefunctionname:entry > { > printf("%s is called by %d",probefunc, tid); > } > > > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
Check out Brendan Gregg''s dtruss shell script (available from his web site or as part of MacOSX Leopard). It emulates truss using dtrace, including truss''s -f option.
mvmvmv1234 at yahoo.com
2008-Nov-14 08:40 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
Thanx a lot. Can I get pstack equivalent script using DTrace? One problem is if we call java from C (using JNI) such stacks are not shown in pstack. One more problem is running instance is hang thread lock can we have a script which shows which all threads are causing deadlock? --- On Fri, 11/7/08, Mark Plotnick <mark.plotnick at gmail.com> wrote:> Check out Brendan Gregg''s dtruss shell script (available > from his web site or as part of MacOSX Leopard). It emulates truss using > dtrace, including truss''s -f option.
On Fri, Nov 14, 2008 at 12:40:55AM -0800, mvmvmv1234 at yahoo.com wrote:> Can I get pstack equivalent script using DTrace?You can use ustack() at any probe. Adam -- Adam Leventhal, Fishworks http://blogs.sun.com/ahl
mvmvmv1234 at yahoo.com
2008-Nov-16 09:50 UTC
[dtrace-discuss] truss "-fall" equivalent in DTrace
I tried this script (attached below) but it printed only 1 thread (shown below). When I tried :::entry and my system was almost hung. I think pstack is good enough for my purpose. :-) BTW any script to find out which two threads are causing lock contention /deadlock? #!/usr/sbin/dtrace -s #pragma D option quiet #pragma D option defaultargs pid$1:::entry / this->thread_is_already_printed != 1 / { this->thread_is_already_printed = 1; printf("thread %d: \n", tid); ustack(50); } $./pstack.d 16028 thread 11: libc.so.1`_lwp_mutex_lock libc.so.1`_lwp_cond_reltimedwait+0x78 libc.so.1`_lwp_cond_timedwait+0x1c libjvm.so`__1cHMonitorEwait6Mil_i_+0x328 libjvm.so`__1cIVMThreadDrun6M_v_+0x1b4 libjvm.so`__1cG_start6Fpv_0_+0x208 libc.so.1`_lwp_start --- On Fri, 11/14/08, Adam Leventhal <ahl at eng.sun.com> wrote:> From: Adam Leventhal <ahl at eng.sun.com> > Subject: Re: [dtrace-discuss] truss "-fall" equivalent in DTrace > To: "mvmvmv1234 at yahoo.com" <mvmvmv1234 at yahoo.com> > Cc: "Mark Plotnick" <mark.plotnick at gmail.com>, dtrace-discuss at opensolaris.org > Date: Friday, November 14, 2008, 7:32 PM > On Fri, Nov 14, 2008 at 12:40:55AM -0800, > mvmvmv1234 at yahoo.com wrote: > > Can I get pstack equivalent script using DTrace? > > You can use ustack() at any probe. > > Adam > > -- > Adam Leventhal, Fishworks > http://blogs.sun.com/ahl
What kind of system is this, and what release of Solaris? Enabling all the probes for all the function entry points in a process (pid$1:::entry) can take some time, and may make your terminal window appear hung, but it should not almost hang your system (unless you did this on a laptop or small, single CPU machine). If you have thread contention, use the plockstat provider. Run "plockstat -V ...." and save the output. The "-V" flag will generate the actual D that plockstat uses (to stderr if I remember right). You can save that and use it as a building block for chasing with threads are hitting your contended locks. Of course, you may find the output of "plockstat -A -p PID" is all you need... Thanks, /jim mvmvmv1234 at yahoo.com wrote:> I tried this script (attached below) but it printed only 1 thread (shown below). When I tried :::entry and my system was almost hung. I think pstack is good enough for my purpose. :-) > > BTW any script to find out which two threads are causing lock contention /deadlock? > > #!/usr/sbin/dtrace -s > #pragma D option quiet > #pragma D option defaultargs > > pid$1:::entry > / this->thread_is_already_printed != 1 / > { > this->thread_is_already_printed = 1; > printf("thread %d: \n", tid); > ustack(50); > } > > $./pstack.d 16028 > thread 11: > > libc.so.1`_lwp_mutex_lock > libc.so.1`_lwp_cond_reltimedwait+0x78 > libc.so.1`_lwp_cond_timedwait+0x1c > libjvm.so`__1cHMonitorEwait6Mil_i_+0x328 > libjvm.so`__1cIVMThreadDrun6M_v_+0x1b4 > libjvm.so`__1cG_start6Fpv_0_+0x208 > libc.so.1`_lwp_start > > > --- On Fri, 11/14/08, Adam Leventhal <ahl at eng.sun.com> wrote: > > >> From: Adam Leventhal <ahl at eng.sun.com> >> Subject: Re: [dtrace-discuss] truss "-fall" equivalent in DTrace >> To: "mvmvmv1234 at yahoo.com" <mvmvmv1234 at yahoo.com> >> Cc: "Mark Plotnick" <mark.plotnick at gmail.com>, dtrace-discuss at opensolaris.org >> Date: Friday, November 14, 2008, 7:32 PM >> On Fri, Nov 14, 2008 at 12:40:55AM -0800, >> mvmvmv1234 at yahoo.com wrote: >> >>> Can I get pstack equivalent script using DTrace? >>> >> You can use ustack() at any probe. >> >> Adam >> >> -- >> Adam Leventhal, Fishworks >> http://blogs.sun.com/ahl >> > > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
On Sun, Nov 16, 2008 at 01:50:52AM -0800, mvmvmv1234 at yahoo.com wrote:> I tried this script (attached below) but it printed only 1 thread (shown below). When I tried :::entry and my system was almost hung. I think pstack is good enough for my purpose. :-) > > BTW any script to find out which two threads are causing lock contention /deadlock? > > #!/usr/sbin/dtrace -s > #pragma D option quiet > #pragma D option defaultargs > > pid$1:::entry > / this->thread_is_already_printed != 1 / > { > this->thread_is_already_printed = 1;You should be using "self->", not "this->". this-> variables are only valid during a single probe firing (i.e. one or more enablings with the same probe name), and must be set before use. They are generally used for temporary results, to avoid recomputing things, and to communicate between multiple enablings of the same probe. self-> variables are thread-local, and will do what you desire here. Cheers, - jonathan> printf("thread %d: \n", tid); > ustack(50); > } > > $./pstack.d 16028 > thread 11: > > libc.so.1`_lwp_mutex_lock > libc.so.1`_lwp_cond_reltimedwait+0x78 > libc.so.1`_lwp_cond_timedwait+0x1c > libjvm.so`__1cHMonitorEwait6Mil_i_+0x328 > libjvm.so`__1cIVMThreadDrun6M_v_+0x1b4 > libjvm.so`__1cG_start6Fpv_0_+0x208 > libc.so.1`_lwp_start > > > --- On Fri, 11/14/08, Adam Leventhal <ahl at eng.sun.com> wrote: > > > From: Adam Leventhal <ahl at eng.sun.com> > > Subject: Re: [dtrace-discuss] truss "-fall" equivalent in DTrace > > To: "mvmvmv1234 at yahoo.com" <mvmvmv1234 at yahoo.com> > > Cc: "Mark Plotnick" <mark.plotnick at gmail.com>, dtrace-discuss at opensolaris.org > > Date: Friday, November 14, 2008, 7:32 PM > > On Fri, Nov 14, 2008 at 12:40:55AM -0800, > > mvmvmv1234 at yahoo.com wrote: > > > Can I get pstack equivalent script using DTrace? > > > > You can use ustack() at any probe. > > > > Adam > > > > -- > > Adam Leventhal, Fishworks > > http://blogs.sun.com/ahl > > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org