> ----------------------------------------
> On Wed, Apr 30, 2008 at 05:51:15PM +0200, [EMAIL PROTECTED] wrote:
> > I am dealing with same problem as Bayard trying to trace child processes. 
> > [...]
> > However I really do not know if it is technically possible to create 
> > "dynamic
> pid provider" :-) 
> 
> The way I've done this in the past is to use syscall or proc probes to
> stop() the child process, followed by a system() action to start a new
> instance of DTrace to trace the new process.
> 
> I don't see how to create a "dynamic pid provider" without stopping the
> new child process to give the pid provider a chance to get a proc handle
> to it and do all that it has to do to setup pid provider probes.  Which
> means that a "dynamic pid provider" would have to be destructive.
> 
> But, yeah, it'd be nice to not have to system() a new DTrace instance.
> In Java I think you could certainly do it by using the Java interfaces
> to DTrace.  But if you're using dtrace(1M) then yes, you have to start a
> new instance.
> 
> Nico


I just tried stop() as you suggested and I thing something bad is happening
when you are using this action. Please see following. Having this two very 
simple dtrace scripts:

#!/usr/sbin/dtrace -wqs
/*this is master.d dscript file*/

proc:::exec-success
/(execname == "myprog") || its_ours[ppid]/
{
    stop(); /*try to comment this line*/
    its_ours[pid] = 1;
    printf("proccess is %s, %d, %d\n",execname,pid,ppid);
    system("dtrace -s helper.d %d > _%s_%d &",pid,execname,pid);
}

------------------EOF
and:

/*this is helper.d dscript file*/
#pragma D option destructive
#pragma D option quiet

dtrace:::BEGIN
{
    system("prun %d", $1); /*try to comment this line*/
}

pid$1:::entry
{
  self->indent++;
  printf("%*s--> %s(%d)\n",2*self->indent," ",probefunc,tid);
}

pid$1:::return
{
  printf("%*s<-- %s(%d)\n",2*self->indent," ",probefunc,tid);
  self->indent = (self->indent-1 < 0 ? 0 : self->indent-1);
}

----------------------EOF

Here is my testing C program "myprog": 

void
fce() {
  sleep(1);
  write(1,"W",1);
}

int main() {
  while(1) fce();

---------------------EOF

Having this I first run master.d script and then I run myprog. 
Now it seems that if you are using stop() and prune then probes from
shared libraries are not fired so you will not see execution flow inside any 
shared library. If you are not using stop() then everything works ok. You can 
see output similar to this if you will leave stop() and prune line in my 
scripts 
commented:

  --> fce(1)
    --> sleep(1)
      --> _save_nv_regs(1)
      <-- _save_nv_regs(1)
      --> ___nanosleep(1)
      <-- ___nanosleep(1)
    <-- sleep(1)
    --> write(1)
      --> _save_nv_regs(1)
      <-- _save_nv_regs(1)
      --> _write(1)
      <-- _write(1)
    <-- write(1)
  <-- fce(1)

But if you will uncomment that lines, you will see something like this (at the 
end of
output file after lot of initialization lines):

            <-- fce(1)
            --> fce(1)
            <-- fce(1)
            --> fce(1)
            <-- fce(1)
            --> fce(1)
            <-- fce(1)
            --> fce(1)

Is this some sort of bug or am I doing something wrong? Could someone try above
procedure on your computer, maybe something is broken on mine ?

Thanks J.
_______________________________________________
dtrace-discuss mailing list
[email protected]

Reply via email to