On Mon, Nov 29, 2010 at 3:26 PM, Afantee Lee <dongli...@gmail.com> wrote:
> Thanks for the suggestion.
> it seems Dtrace can profile the enter point and exit point of the program.
> It is a nice tool, but, I probably need more insides into the pthread 
> function it self.
> for example, I need to profile how many times the pthread_lock try to get the 
> access to the critical section. it is part of the pthread detail 
> implementation code.
>
> please let me know if you know any other tool might be helpful.
> Thank you a lot :)

Using the dtrace PID provider you can trace every instruction.
Consider the following:

Use mdb to disassemble a function:

$ echo pthread_rwlock_wrlock::dis | mdb /lib/libc.so.1
pthread_rwlock_wrlock:          pushl  %ebp
pthread_rwlock_wrlock+1:        movl   %esp,%ebp
pthread_rwlock_wrlock+3:        pushl  %ebx
pthread_rwlock_wrlock+4:        subl   $0x4,%esp        <__strdupa_len>
pthread_rwlock_wrlock+7:        call   +0x0     <pthread_rwlock_wrlock+0xc>
pthread_rwlock_wrlock+0xc:      popl   %ebx
pthread_rwlock_wrlock+0xd:      addl   $0x9435c,%ebx    <_vwscanf_c89+0x14>
pthread_rwlock_wrlock+0x13:     subl   $0x8,%esp
pthread_rwlock_wrlock+0x16:     pushl  $0x0
pthread_rwlock_wrlock+0x18:     pushl  0x8(%ebp)
pthread_rwlock_wrlock+0x1b:     call   -0x1d0   <rw_wrlock_impl>
pthread_rwlock_wrlock+0x20:     addl   $0x14,%esp
pthread_rwlock_wrlock+0x23:     popl   %ebx
pthread_rwlock_wrlock+0x24:     leave
pthread_rwlock_wrlock+0x25:     ret

Use dtrace to list the available probes in that function:

# dtrace -l -n 'pid$target:libc.so.1:pthread_rwlock_wrlock:' -c /bin/true
   ID   PROVIDER            MODULE                          FUNCTION NAME
71738    pid6477         libc.so.1             pthread_rwlock_wrlock return
71739    pid6477         libc.so.1             pthread_rwlock_wrlock entry
71740    pid6477         libc.so.1             pthread_rwlock_wrlock 0
71741    pid6477         libc.so.1             pthread_rwlock_wrlock 1
71742    pid6477         libc.so.1             pthread_rwlock_wrlock 3
71743    pid6477         libc.so.1             pthread_rwlock_wrlock 4
71744    pid6477         libc.so.1             pthread_rwlock_wrlock 7
71745    pid6477         libc.so.1             pthread_rwlock_wrlock c
71746    pid6477         libc.so.1             pthread_rwlock_wrlock d
71747    pid6477         libc.so.1             pthread_rwlock_wrlock 13
71748    pid6477         libc.so.1             pthread_rwlock_wrlock 16
71749    pid6477         libc.so.1             pthread_rwlock_wrlock 18
71750    pid6477         libc.so.1             pthread_rwlock_wrlock 1b
71751    pid6477         libc.so.1             pthread_rwlock_wrlock 20
71752    pid6477         libc.so.1             pthread_rwlock_wrlock 23
71753    pid6477         libc.so.1             pthread_rwlock_wrlock 24
71754    pid6477         libc.so.1             pthread_rwlock_wrlock 25

Use dtrace to see how frequently each of those instructions are hit:

# dtrace -qn 'pid$target:libc.so.1:pthread_rwlock_wrlock: {
@freq[probefunc,probename] = count() } tick-1s {printf("%Y\n",
walltimestamp); printa("%...@d %s:%s\n", @freq); trunc(@freq)}' -p 3395
2010 Nov 30 15:36:36
2010 Nov 30 15:36:37
2010 Nov 30 15:36:38
2010 Nov 30 15:36:39
      12 pthread_rwlock_wrlock:0
      12 pthread_rwlock_wrlock:1
      12 pthread_rwlock_wrlock:13
      12 pthread_rwlock_wrlock:16
      12 pthread_rwlock_wrlock:18
      12 pthread_rwlock_wrlock:1b
      12 pthread_rwlock_wrlock:20
      12 pthread_rwlock_wrlock:23
      12 pthread_rwlock_wrlock:24
      12 pthread_rwlock_wrlock:25
      12 pthread_rwlock_wrlock:3
      12 pthread_rwlock_wrlock:4
      12 pthread_rwlock_wrlock:7
      12 pthread_rwlock_wrlock:c
      12 pthread_rwlock_wrlock:d
      12 pthread_rwlock_wrlock:entry
      12 pthread_rwlock_wrlock:return
2010 Nov 30 15:36:40
2010 Nov 30 15:36:41
2010 Nov 30 15:36:42
2010 Nov 30 15:36:43
2010 Nov 30 15:36:44
...

--
Mike Gerdts
http://mgerdts.blogspot.com/
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to