This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: file io script example
- From: James Dickens <jamesd dot wi at gmail dot com>
- To: Kevin Stafford <kevinrs at us dot ibm dot com>
- Cc: systemtap at sources dot redhat dot com
- Date: Wed, 7 Sep 2005 17:19:08 -0500
- Subject: Re: file io script example
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YnvZfHgeSzyVvtURpEO4pfo5IFgj2p69aqeNHznPO6xjw4ybYR4vaqXs5VhIQLKB35+FGkKwMTM99owEY53a4vjo/0G9FFpQ+Jn28I/o2rhcb9o+TenZbksIf/t+wiXJBICSJwtgLcaNUgyBymD6dAOwbgPaJXld7AqECscjFuQ=
- References: <431F663A.1060308@us.ibm.com>
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
>
>
>
>