Hi Michael,

    Thanks very much! According to your tips, I google related materials:


    https://blogs.oracle.com/chrisg/entry/follow_fork_for_dtrace_pid;‍
    http://marc.info/?t=115514030100002&r=1&w=2.‍


    Hope these stuff can also help other people.


Best Regards
Nan Xiao
------------------ 原始邮件 ------------------
发件人: "Michael Schuster";<michaelspriv...@gmail.com>;
发送时间: 2014年10月24日(星期五) 下午3:26
收件人: "Nan Xiao"<xiaonan19830...@qq.com>; 
抄送: "dtrace-discuss"<dtrace-discuss@lists.dtrace.org>; 
主题: Re: [dtrace-discuss] How to trace libc module of both parent andchild 
processes?



Hi,


The last time I tried something like that, you had to start a seperate Dtrace 
script for every process you wanted to trace - I don't think the pid provider 
allows for tracing of more than one process at a time (from within a single 
script).

I don't have an example handy, but if you search for "pid provider" "fork" and 
"system" or similar, you should get along.


HTH
Michael


On Fri, Oct 24, 2014 at 9:13 AM, Nan Xiao via dtrace-discuss 
<dtrace-discuss@lists.dtrace.org> wrote:
Hi all,


Firstly, I am very sorry for interrupting mailing list so frequently these 
days. As a newbie of DTrace, I think this mailing list is the best place for 
discussing DTrace issues. And I am very grateful for everybody who has helped 
me, thanks!


I am using DTrace to trace some libc module functions. E.g., the C program is 
like this:


        #include <stdio.h>
        #include <sys/types.h>
        #include <unistd.h>


        int main(void) {
                        pid_t pid = 0;
                        
                        pid = fork();
                        if (pid > 0) {
                                        printf("Parent:%d\n", time(NULL));
                        } else if (pid == 0) {
                                        printf("Child:%d\n", time(NULL));
                        }
                        
                        return 0;
        }
        
If I want to trace time function of parent process, the DTrace script is easy:


        pid$target:libc:time:return
        {
                        trace(arg1);
                        ustack();
        }
        
Now, if I want to trace both parent and child processes, it seems a little 
difficult.


Firstly, I should get the child process ID:


        pid_t child_pid;
        
        pid$target::fork:return
        {
                        child_pid = (pid_t)arg1;
                        ustack();
        }


Secondly, I want to trace both parent and child processes. I tried the 
following methods:


1)
        libc:time:return
        /pid && (pid == $target || pid == child_pid)/
        {
                trace(arg1);
                ustack();
        }
The DTrace complains ":libc:time:return does not match any probes" error.


2)
        pid*:libc:time:return
        /pid && (pid == $target || pid == child_pid)/
        {
                trace(arg1);
                ustack();
        }


The DTrace complains "probe description pid*:libc:time:return does not match 
any probes" error.


So is there any good methods of tracing libc module of both parent and child 
processes?‍ Thanks very much in advance!


Best Regards
Nan Xiao‍
       dtrace-discuss | Archives   | Modify  Your Subscription 






-- 
Michael Schuster
http://recursiveramblings.wordpress.com/


-------------------------------------------
dtrace-discuss
Archives: https://www.listbox.com/member/archive/184261/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184261/25769126-e243886f
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769126&id_secret=25769126-8d47a7b2
Powered by Listbox: http://www.listbox.com

Reply via email to