This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
file io script example
- From: Kevin Stafford <kevinrs at us dot ibm dot com>
- To: systemtap at sources dot redhat dot com
- Date: Wed, 07 Sep 2005 15:14:18 -0700
- Subject: file io script example
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);
%}
# 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