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: file io script example


On 9/7/05, Kevin Stafford <kevinrs@us.ibm.com> wrote:
> Here is a simple script which monitors sys_open and sys_close.
> 
> %{
> #include <linux/file.h>
> %}
> 
> function get_string(str_ptr_addr)
> %{
>         strlcpy(THIS->__retvalue,
>                     (const char __user*) (uintptr_t) THIS->str_ptr_addr,
>                     MAXSTRINGLEN);
> %}
> 
> function get_fname(fd)
> %{
>         struct file *file;
>         file = fget(THIS->fd);
>         strlcpy(THIS->__retvalue,
>                     file->f_dentry->d_name.name,
>                     MAXSTRINGLEN);
> %}
> 
Hi

seems like over the last few days all the samples use  %} if i
understand this construct requires "guru mode" will this always be the
case? or will systemtap be able to support C contructs like struct and
typedef in the future? if this is not the case it sounds terribly
broken.

James Dickens

> 
> # The format variable will not be needed when bz#1306
> # is resolved
> # http://sourceware.org/bugzilla/show_bug.cgi?id=1306
> global format
> 
> probe kernel.statement("*@fs/open.c:958")
> {
>         if(format) {
>                 print("sys_open: fd = " . string($fd) .
>                           ", file = " . get_string($tmp)  .
>                           ", proc = " . pexecname()       .
>                           ", pid = " . string(pid()) . "\n")
>                 format = 0
>         } else
>                 format = 1
> }
> 
> probe kernel.function("sys_close")
> {
>         print("sysclose: fd = " . string($fd) .
>                   ", file = " . get_fname($fd)    .
>                   ", proc = " . pexecname()       .
>                   ", pid = " . string(pid()) . "\n")
> }
> 
> Sample Output:
> 
> sys_open: fd = 3, file = /proc/irq/225/smp_affinity, proc = init, pid = 2478
> sysclose: fd = 3, file = smp_affinity, proc = init, pid = 2478
> sys_open: fd = 6, file = /proc/loadavg, proc = init, pid = 2772
> sysclose: fd = 6, file = loadavg, proc = init, pid = 2772
> 
> Notes:
> *The format variable will not be needed when bz#1306 is resolved.
> * probe kernel.statement("*@fs/open.c:958") is probably not a good idea
> because of
>    the hardcoded line numbers. kernel.function("sys_open") is more
> appropriate but
>    limits access to params (e.g. filename. see bz#1295)
> 
> --
> Kevin Stafford
> DES 2 | MS 2M3
> Beaverton - OR
> Linux Technology Center
> IBM Systems & Technology
> Phone: 1-503-578-3039
> Email: kevinrs@us.ibm.com
> 
> 
> 
>


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