Systemtap: learning notes

Before using stap, the kernel-debuginfo-$(uname -r), kernel-debuginfo-common-$(uname -m)-$(uname -r) and kernel-devel-$(uname -r) should be installed. (CentOS)

stap-prep is a shortcut, but in the end, the above 3 packages should present.

verbose manpage over stap: man stapprobes

Another doc of stap will be included as file  of this blog.

Normal usage of stap file: (its format is loose)

#!/bin/stap
global cntread, cntwrite, cntother

probe kernel.function("vfs_read"), kernel.function("vfs_write"), kernel.function(@1)
{
        if (probefunc() == "vfs_read")
                cntread++;
        else if (probefunc() == "vfs_write")
                cntwrite++;
        else
                cntother++;
}

probe timer.s(5){
        exit();
}

probe end {
        printf("Read: %d\nWrite: %d\nOther: %d\n", cntread, cntwrite, cntother);
}

Run by: stap stap.stp -v/-vvv -- vfs_open (Note: vfs_open as first argument passed to stp script which replaces @1)

猜你喜欢

转载自www.cnblogs.com/sansna/p/9314492.html