LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   WSFileMonitor systemtap script (https://www.linuxquestions.org/questions/programming-9/wsfilemonitor-systemtap-script-881984/)

dazdaz 05-21-2011 01:31 PM

WSFileMonitor systemtap script
 
I am trying to get this example systemtap script running, but does'nt compile.
I've made modifications etc but can't figure out what's wrong with the syntax.

I know that systemtap is functioning as I can run a few other scripts, such as

Code:

stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'
My kernel is 2.6.38-8-generic #42-Ubuntu SMP and I have the debuginfo kernel installed.

This is where I found the script :
http://sources.redhat.com/systemtap/wiki/WSFileMonitor

I have made this modification as recommended :
Code:

Eugene: Using kernel 2.6.21-1.3194.fc7, I have to change the code slightly:

  dev_nr = $file->f_path->dentry->d_inode->i_sb->s_dev
  inode_nr = $file->f_path->dentry->d_inode->i_ino

Here are the errors when I run the script.
Code:

# stap wsfile.stp
parse error: command line argument index 1 out of range [1-0]
        at: junk '$1' at wsfile.stp:9:18
    source:  if (dev_nr == ($1 << 20 | $2) # major/minor device
                              ^
parse error: command line argument index 2 out of range [1-0]
        at: junk '$2' at wsfile.stp:9:29
    source:  if (dev_nr == ($1 << 20 | $2) # major/minor device
                                        ^
parse error: command line argument index 3 out of range [1-0]
        at: unknown token '$3' at wsfile.stp:10:22
    source:      && inode_nr == $3)
                                  ^
parse error: expected 'probe', 'global', 'function', or '%{'
        saw: operator ')' at wsfile.stp:10:24
    source:      && inode_nr == $3)
                                    ^
4 parse error(s).
Pass 1: parse failed.  Try again with another '--vp 1' option.

Here is the script :
Code:

#! /usr/bin/env stap

probe kernel.function ("vfs_write"),
      kernel.function ("vfs_read")
{
  dev_nr = $file->f_path->d_inode->i_sb->s_dev
  inode_nr = $file->f_path->d_inode->i_ino

  if (dev_nr == ($1 << 20 | $2) # major/minor device
      && inode_nr == $3)
    printf ("%s(%d) %s 0x%x/%u\n",
      execname(), pid(), probefunc(), dev_nr, inode_nr)
}


Nominal Animal 05-22-2011 05:45 PM

Quote:

Originally Posted by dazdaz (Post 4363056)
Code:

if (dev_nr == ($1 << 20 | $2) # major/minor device
      && inode_nr == $3)


What are $1, $2, and $3 supposed to be? Are you sure you don't mean @1, @2, and @3, respectively?

I recommend you take a look at the sizeof.stp systemtap example.

dazdaz 05-23-2011 02:22 PM

systemtap complains when I change the $ to an @. I know it should be run like this, but for me it does'nt seem to work.

Code:

script.stp arg1 arg2 arg3.


All times are GMT -5. The time now is 04:46 AM.