The dot in ... --- ...

Chris Gerhard's Weblog

« Why a fixie | Main | Using dtrace to... »

20090627 Saturday June 27, 2009

Follow fork for dtrace pid provider?

There is a ongoing request to have follow fork functionality for the dtrace pid provider but so far no one has stood upto the plate for that RFE. In the mean time my best workaround for this is this:

cjg@brompton:~/lang/d$ cat followfork.d
proc:::start
/ppid == $target/
{
	stop();
	printf("fork %d\n", pid);
	system("dtrace -qs child.d -p %d", pid);
}
cjg@brompton:~/lang/d$ cat child.d
pid$target::malloc:entry
{
	printf("%d %s:%s %d\n", pid, probefunc, probename, ustackdepth)
}
cjg@brompton:~/lang/d$ pfexec /usr/sbin/dtrace -qws followfork.d -s child.d -p 26758
26758 malloc:entry 22
26758 malloc:entry 15
26758 malloc:entry 18
26758 malloc:entry 18
26758 malloc:entry 18
fork 27548
27548 malloc:entry 7
27548 malloc:entry 7
27548 malloc:entry 18
27548 malloc:entry 16
27548 malloc:entry 18

Clearly you can have the child script do what ever you wish.

Better solutions are welcome!


( Jun 27 2009, 01:25:52 PM BST ) Permalink Trackback

   
Comments:

[Trackback] I've been working with a customer to try and find a memory “leak” in their application. Many things have been tried, libumem, and the mdb ::findleaks command all with no success. So I was, as I am sure others before me have, pondering ...

Posted by The dot in ... --- ... on June 30, 2009 at 12:15 PM BST #

this is handy but when the proc:::start probe fires no user-level instructions have executed. this means that it is not possible to trace dynamically loaded libraries in this way.

doing so is straightforward using the technique above. instead of stop()ing on proc:::start I trussed the child application and picked a system call that ran immediately after the relevant library was loaded and launched child.d at that point.

Posted by Lewis on August 05, 2009 at 06:01 PM BST #

Post a Comment:

Comments are closed for this entry.

Valid HTML! Valid CSS!

Except where otherwise noted, this site is
licensed under a Creative Commons License 2.0

This is a personal weblog, I do not speak for my employer.