diff options
Diffstat (limited to 'doc/tutorial')
-rw-r--r-- | doc/tutorial/embedded-C.stp | 25 | ||||
-rw-r--r-- | doc/tutorial/functions.stp | 18 | ||||
-rw-r--r-- | doc/tutorial/hello-world.stp | 5 | ||||
-rw-r--r-- | doc/tutorial/inode-watch.stp | 13 | ||||
-rw-r--r-- | doc/tutorial/probe-alias.stp | 17 | ||||
-rw-r--r-- | doc/tutorial/socket-trace.stp | 6 | ||||
-rw-r--r-- | doc/tutorial/strace-open.stp | 8 | ||||
-rw-r--r-- | doc/tutorial/tapset-time-user.stp | 8 | ||||
-rw-r--r-- | doc/tutorial/tapset/time-common.stp | 4 | ||||
-rw-r--r-- | doc/tutorial/tapset/time-default.stp | 2 | ||||
-rw-r--r-- | doc/tutorial/timer-jiffies.stp | 10 |
11 files changed, 116 insertions, 0 deletions
diff --git a/doc/tutorial/embedded-C.stp b/doc/tutorial/embedded-C.stp new file mode 100644 index 00000000..6834d728 --- /dev/null +++ b/doc/tutorial/embedded-C.stp @@ -0,0 +1,25 @@ +%{ +#include <linux/utsname.h> +%} + +function utsname:string (field:long) +%{ + if (down_read_trylock (& uts_sem)) + { + const char *f = + (THIS->field == 0 ? system_utsname.sysname : + THIS->field == 1 ? system_utsname.nodename : + THIS->field == 2 ? system_utsname.release : + THIS->field == 3 ? system_utsname.version : + THIS->field == 4 ? system_utsname.machine : + THIS->field == 5 ? system_utsname.domainname : ""); + strlcpy (THIS->__retvalue, f, MAXSTRINGLEN); + up_read (& uts_sem); + } +%} + +probe begin +{ + printf ("%s %s\n", utsname(0), utsname(2)) + exit () +} diff --git a/doc/tutorial/functions.stp b/doc/tutorial/functions.stp new file mode 100644 index 00000000..6a825722 --- /dev/null +++ b/doc/tutorial/functions.stp @@ -0,0 +1,18 @@ +# Red Hat convention +function system_uid_p (u) { return u < 500 } + +# kernel device number assembly macro +function makedev (major,minor) { return major << 20 | minor } + +function trace_common () +{ + printf("%d %s(%d)", gettimeofday_s(), execname(), pid()) + # no return value +} + +function fibonacci (i) +{ + if (i < 1) return 0 + else if (i < 2) return 1 + else return fibonacci(i-1) + fibonacci(i-2) +} diff --git a/doc/tutorial/hello-world.stp b/doc/tutorial/hello-world.stp new file mode 100644 index 00000000..6a9037a7 --- /dev/null +++ b/doc/tutorial/hello-world.stp @@ -0,0 +1,5 @@ +probe begin +{ + print ("hello world\n") + exit () +} diff --git a/doc/tutorial/inode-watch.stp b/doc/tutorial/inode-watch.stp new file mode 100644 index 00000000..caf04b9a --- /dev/null +++ b/doc/tutorial/inode-watch.stp @@ -0,0 +1,13 @@ +probe kernel.function ("vfs_write"), + kernel.function ("vfs_read") +{ + dev_nr = $file->f_dentry->d_inode->i_sb->s_dev + inode_nr = $file->f_dentry->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) +} + +# dev_name = kernel_string ($file->f_dentry->d_inode->i_sb->s_id) diff --git a/doc/tutorial/probe-alias.stp b/doc/tutorial/probe-alias.stp new file mode 100644 index 00000000..aa5feb1b --- /dev/null +++ b/doc/tutorial/probe-alias.stp @@ -0,0 +1,17 @@ +probe syscallgroup.io = syscall.open, syscall.close, + syscall.read, syscall.write +{ groupname = "io" } + +probe syscallgroup.process = syscall.fork, syscall.execve +{ groupname = "process" } + +probe syscallgroup.* +{ groups [execname() . "/" . groupname] ++ } + +probe end +{ + foreach (eg+ in groups) + printf ("%s: %d\n", eg, groups[eg]) +} + +global groups diff --git a/doc/tutorial/socket-trace.stp b/doc/tutorial/socket-trace.stp new file mode 100644 index 00000000..53b69ecc --- /dev/null +++ b/doc/tutorial/socket-trace.stp @@ -0,0 +1,6 @@ +probe kernel.function("*@net/socket.c") { + printf ("%s -> %s\n", thread_indent(1), probefunc()) +} +probe kernel.function("*@net/socket.c").return { + printf ("%s <- %s\n", thread_indent(-1), probefunc()) +} diff --git a/doc/tutorial/strace-open.stp b/doc/tutorial/strace-open.stp new file mode 100644 index 00000000..fb87cec1 --- /dev/null +++ b/doc/tutorial/strace-open.stp @@ -0,0 +1,8 @@ +probe syscall.open +{ + printf ("%s(%d) open (%s)\n", execname(), pid(), argstr) +} +probe timer.ms(4000) # after 4 seconds +{ + exit () +} diff --git a/doc/tutorial/tapset-time-user.stp b/doc/tutorial/tapset-time-user.stp new file mode 100644 index 00000000..32069b03 --- /dev/null +++ b/doc/tutorial/tapset-time-user.stp @@ -0,0 +1,8 @@ +probe begin +{ + timer_begin ("bench") + for (i=0; i<100; i++) ; + printf ("%d cycles\n", timer_end ("bench")) + exit () +} +function __time_value () { return get_cycles () } # override diff --git a/doc/tutorial/tapset/time-common.stp b/doc/tutorial/tapset/time-common.stp new file mode 100644 index 00000000..cec5a4ea --- /dev/null +++ b/doc/tutorial/tapset/time-common.stp @@ -0,0 +1,4 @@ +global __time_vars +function timer_begin (name) { __time_vars[name] = __time_value () } +function timer_end (name) { return __time_value() - __time_vars[name] } + diff --git a/doc/tutorial/tapset/time-default.stp b/doc/tutorial/tapset/time-default.stp new file mode 100644 index 00000000..614ff506 --- /dev/null +++ b/doc/tutorial/tapset/time-default.stp @@ -0,0 +1,2 @@ +function __time_value () { return gettimeofday_us () } + diff --git a/doc/tutorial/timer-jiffies.stp b/doc/tutorial/timer-jiffies.stp new file mode 100644 index 00000000..d5e92e4a --- /dev/null +++ b/doc/tutorial/timer-jiffies.stp @@ -0,0 +1,10 @@ +global count_jiffies, count_ms +probe timer.jiffies(100) { count_jiffies ++ } +probe timer.ms(100) { count_ms ++ } +probe timer.ms(12345) +{ + hz=(1000*count_jiffies) / count_ms + printf ("jiffies:ms ratio %d:%d => CONFIG_HZ=%d\n", + count_jiffies, count_ms, hz) + exit () +} |