Hi , I have this problem , which might have been discussed here, but I am new to Dtrace and so apologies if this is not new. I have a C++ server which forks off a new process , on a connection. I want to trace certain functions in these new processes. So , I wrote a test script as follows : Proc:::create { self->trace = 1; } ::Mangled_Function_name:entry / self->trace == 1 && execname == "server" / { self->ts[probefunc] = timestamp; } ::Mangled_Function_name:return /self->trace == 1 && execname =="server / { printf(" Time taken %d", timestamp - self->ts[probefunc]); } When ever the server will create a new process it will enter , in the first probe for create. My questions : 1) First of all when I run the program with the command "dtrace -s trial.d" , it gives an error that the probe did not match for the Mangled_Function_Name. So , I used -Z option to make the program run. Is there any other way. 2) The newly created processes do not enter into the Mangled_Function_name probe. However, when I used the same Function and use it in a known pid this works. So , my question is why doesn''t Dtrace find a match in this newly created process. How do I achieve , this functionality . Thanks Mohnish Kodnani This message posted from opensolaris.org
Gangadhar Mylapuram
2007-Apr-25 08:22 UTC
[dtrace-discuss] Tracing a process that is not created yet
mohnish wrote:> Hi , > I have this problem , which might have been discussed here, but I am new > to Dtrace and so apologies if this is not new. > I have a C++ server which forks off a new process , on a connection. > I want to trace certain functions in these new processes. > So , I wrote a test script as follows : > > Proc:::create > { > self->trace = 1; > } > ::Mangled_Function_name:entry > / self->trace == 1 && execname == "server" / > { > self->ts[probefunc] = timestamp; > } > ::Mangled_Function_name:return > /self->trace == 1 && execname =="server / > { > printf(" Time taken %d", timestamp - self->ts[probefunc]); > } > > When ever the server will create a new process it will enter , in the > first probe for create. > > My questions : > 1) First of all when I run the program with the command "dtrace -s > trial.d" , it gives an error that the probe did not match for the > Mangled_Function_Name. So , I used -Z option to make the program run. > Is there any other way. >Couple of nits 1. Proc:::create can be fired by any process on the system, how can you make sure that it happens by the server. 2. you are seeing an error because, there is no probe ::Mangled_Function_name:entry available on the system because of the process you are looking for is not yet in memory. if you are doing exec after fork then you can use proc:::exec-sucess What I can think of is proc:::exec-sucess /execname == "server"/ # I assume that the forked process name is "server" { system("dtrace -Fs abc.d -p ''pgrep server'' "); # at this point process is in memory } abc.d ------ pid$target::Mangled_Function_name:entry { self->ts[probefunc] = timestamp; } pid$target::Mangled_Function_name:entry { printf(" Time taken %d", timestamp - self->ts[probefunc]); exit(0); } I haven''t tested this.> 2) The newly created processes do not enter into the > Mangled_Function_name probe. However, when I used the same Function and > use it in a known pid this works. > So , my question is why doesn''t Dtrace find a match in this newly > created process. > >Because when you ran the dtrace script there was no matching probe available on the system. the probe which you are looking is available only after successful exec. Thanks, Gangadhar