This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question on wait4time.stp sample code


On 01/11/2010 03:34 PM, Ivan Novick wrote:
> http://sourceware.org/systemtap/examples/process/wait4time.stp
> 
> Hi,
> 
> I have a few questions regarding the above linked sample code.  Let me
> ask the most basic question.
> 
> In this probe:
> 
> probe syscall.wait4 {
>   t = gettimeofday_us(); p = pid()
>   entry_wait4[p] = t
>   wait4_pid[p]=pid
> }
> 
> 
> There is a reference to pid on the last line which is not a function
> call and not a global variable.  What is pid actually referring to in
> this case?

"syscall.wait4" is a tapset alias for some underlying kernel probes.  In
that alias we also define several local variables corresponding to the
syscall arguments, and "pid" is one of those.

For most of the syscall tapset, we define local variables to match the
userspace argument names, so you can get an idea of their meaning in
"man 2 wait4".  In this case, "pid" specifies the child which is being
waited on.

You can also ask stap to report all variables accessible in a tapset:

$ stap -L syscall.wait4
syscall.wait4 name:string pid:long status_uaddr:long options:long
options_str:string rusage_uaddr:long argstr:string $upid:pid_t
$stat_addr:int* $options:int $ru:struct rusage* $wo:struct wait_opts
$pid:struct pid* $type:enum pid_type $ret:long int


Josh


PS -- If you're really curious, this is how the tapset is actually
defined in /usr/share/systemtap/tapset/syscalls2.stp:

# wait4 ______________________________________________________
#
# long sys_wait4(pid_t pid,
#            int __user *stat_addr,
#            int options,
#            struct rusage __user *ru)
#
probe syscall.wait4 = kernel.function("SyS_wait4") !,
                      kernel.function("sys_wait4")
{
        name = "wait4"
        pid = %( kernel_vr >= "2.6.25" %? $upid %: $pid%)
        status_uaddr = $stat_addr
        options = $options
        options_str = _wait4_opt_str($options)
        rusage_uaddr = $ru
        argstr = sprintf("%d, %p, %s, %p",
                %( kernel_vr >= "2.6.25" %? $upid %: $pid%),
                $stat_addr, _wait4_opt_str($options), $ru)
}
probe syscall.wait4.return = kernel.function("SyS_wait4").return !,
                             kernel.function("sys_wait4").return
{
        name = "wait4"
        retstr = returnstr(1)
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]