diff options
| author | Jovi Zhangwei <jovi.zhangwei@gmail.com> | 2013-10-09 07:47:51 -0700 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-11 10:58:32 -0700 |
| commit | c63a164271f81220ff4966d41218a9101f3d0ec4 (patch) | |
| tree | c6e8ac15275fd0bb602bc25297e8eaa040b51443 /drivers | |
| parent | 67aa4acbc97f6a55b328e4e2305ef19cbe949d85 (diff) | |
| download | linux-c63a164271f81220ff4966d41218a9101f3d0ec4.tar.gz linux-c63a164271f81220ff4966d41218a9101f3d0ec4.tar.bz2 linux-c63a164271f81220ff4966d41218a9101f3d0ec4.zip | |
staging: ktap: add to the kernel tree
This patch introduces ktap to staging tree.
ktap is a new script-based dynamic tracing tool for Linux,
it uses a scripting language and lets users trace the
Linux kernel dynamically. ktap is designed to give
operational insights with interoperability that allow
users to tune, troubleshoot and extend kernel and application.
It's similar with Linux Systemtap and Solaris Dtrace.
ktap have different design principles from Linux mainstream
dynamic tracing language in that it's based on bytecode,
so it doesn't depend upon GCC, doesn't require compiling
kernel module for each script, safe to use in production
environment, fulfilling the embedded ecosystem's tracing needs.
See ktap tutorial for more information:
http://www.ktap.org/doc/tutorial.html
The merit of putting this software in staging tree is
to make it more possible to get feedback from users
and thus polish the code.
Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
79 files changed, 16369 insertions, 0 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 3bfdaa8d80a9..3b1501b7d894 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -150,4 +150,6 @@ source "drivers/staging/dgnc/Kconfig" source "drivers/staging/dgap/Kconfig" +source "drivers/staging/ktap/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index b0d3303b4680..2270ed077bde 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -67,3 +67,4 @@ obj-$(CONFIG_XILLYBUS) += xillybus/ obj-$(CONFIG_DGNC) += dgnc/ obj-$(CONFIG_DGAP) += dgap/ obj-$(CONFIG_MTD_SPINAND_MT29F) += mt29f_spinand/ +obj-$(CONFIG_KTAP) += ktap/ diff --git a/drivers/staging/ktap/Kconfig b/drivers/staging/ktap/Kconfig new file mode 100644 index 000000000000..21f8d2ed03b9 --- /dev/null +++ b/drivers/staging/ktap/Kconfig @@ -0,0 +1,21 @@ +config KTAP + tristate "a programable dynamic tracing tool for Linux" + depends on PERF_EVENTS && EVENT_TRACING + default n + help + ktap is a new script-based dynamic tracing tool for Linux, + it uses a scripting language and lets users trace the + Linux kernel dynamically. ktap is designed to give + operational insights with interoperability that allow + users to tune, troubleshoot and extend kernel and application. + It's similar with Linux Systemtap and Solaris Dtrace. + + ktap have different design principles from Linux mainstream + dynamic tracing language in that it's based on bytecode, + so it doesn't depend upon GCC, doesn't require compiling + kernel module for each script, safe to use in production + environment, fulfilling the embedded ecosystem's tracing needs. + + See ktap tutorial for more information: + http://www.ktap.org/doc/tutorial.html + diff --git a/drivers/staging/ktap/Makefile b/drivers/staging/ktap/Makefile new file mode 100644 index 000000000000..e2e54baf36d9 --- /dev/null +++ b/drivers/staging/ktap/Makefile @@ -0,0 +1,101 @@ + +# Do not instrument the tracer itself: +ifdef CONFIG_FUNCTION_TRACER +ORIG_CFLAGS := $(KBUILD_CFLAGS) +KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) +endif + +all: mod ktap + +INTP = interpreter + +LIBDIR = $(INTP)/library + +LIB_OBJS += $(LIBDIR)/baselib.o $(LIBDIR)/kdebug.o $(LIBDIR)/timer.o \ + $(LIBDIR)/ansilib.o + +INTP_OBJS += $(INTP)/ktap.o $(INTP)/loader.o $(INTP)/object.o \ + $(INTP)/tstring.o $(INTP)/table.o $(INTP)/vm.o \ + $(INTP)/opcode.o $(INTP)/strfmt.o $(INTP)/transport.o \ + $(LIB_OBJS) + +obj-m += ktapvm.o +ktapvm-y := $(INTP_OBJS) + +KVERSION ?= $(shell uname -r) +KERNEL_SRC ?= /lib/modules/$(KVERSION)/build +mod: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules + +modules_install: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install + +KTAPC_CFLAGS = -Wall -O2 + +UDIR = userspace + +$(UDIR)/lex.o: $(UDIR)/lex.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/parser.o: $(UDIR)/parser.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/code.o: $(UDIR)/code.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/dump.o: $(UDIR)/dump.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/main.o: $(UDIR)/main.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/util.o: $(UDIR)/util.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/ktapio.o: $(UDIR)/ktapio.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/eventdef.o: $(UDIR)/eventdef.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/opcode.o: $(INTP)/opcode.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/table.o: $(INTP)/table.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/tstring.o: $(INTP)/tstring.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< +$(UDIR)/object.o: $(INTP)/object.c + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< + +KTAPOBJS = +KTAPOBJS += $(UDIR)/lex.o +KTAPOBJS += $(UDIR)/parser.o +KTAPOBJS += $(UDIR)/code.o +KTAPOBJS += $(UDIR)/dump.o +KTAPOBJS += $(UDIR)/main.o +KTAPOBJS += $(UDIR)/util.o +KTAPOBJS += $(UDIR)/ktapio.o +KTAPOBJS += $(UDIR)/eventdef.o +KTAPOBJS += $(UDIR)/opcode.o +KTAPOBJS += $(UDIR)/table.o +KTAPOBJS += $(UDIR)/tstring.o +KTAPOBJS += $(UDIR)/object.o + +ktap: $(KTAPOBJS) + $(QUIET_LINK)$(CC) $(KTAPC_CFLAGS) -o $@ $(KTAPOBJS) -lpthread + +KMISC := /lib/modules/$(KVERSION)/ktapvm/ + +install: mod ktap + install -d $(KMISC) + install -m 644 -c *.ko /lib/modules/$(KVERSION)/ktapvm/ + /sbin/depmod -a + +load: + insmod ktapvm.ko + +unload: + rmmod ktapvm + +test: FORCE + cd test; sh ./run_test.sh; cd - + +clean: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean + $(RM) ktap + +PHONY += FORCE +FORCE: + diff --git a/drivers/staging/ktap/README.md b/drivers/staging/ktap/README.md new file mode 100644 index 000000000000..c8ddd5fa66c6 --- /dev/null +++ b/drivers/staging/ktap/README.md @@ -0,0 +1,144 @@ +# ktap + +A New Scripting Dynamic Tracing Tool For Linux +[www.ktap.org][homepage] + +ktap is a new scripting dynamic tracing tool for Linux, +it uses a scripting language and lets users trace the Linux kernel dynamically. +ktap is designed to give operational insights with interoperability +that allows users to tune, troubleshoot and extend kernel and application. +It's similar with Linux Systemtap and Solaris Dtrace. + +ktap have different design principles from Linux mainstream dynamic tracing +language in that it's based on bytecode, so it doesn't depend upon GCC, +doesn't require compiling kernel module for each script, safe to use in +production environment, fulfilling the embedded ecosystem's tracing needs. + +More information can be found at [ktap homepage][homepage]. + +[homepage]: http://www.ktap.org + +## Highlights + + * simple but powerful scripting language + * register based interpreter (heavily optimized) in Linux kernel + * small and lightweight (6KLOC of interpreter) + * not depend on gcc for each script running + * easy to use in embedded environment without debugging info + * support for tracepoint, kprobe, uprobe, function trace, timer, and more + * supported in x86, arm, ppc, mips + * safety in sandbox + +## Building & Running + +1. Clone ktap from github + + $ git clone http://github.com/ktap/ktap.git + +2. Compiling ktap + + $ cd ktap + $ make #generate ktapvm kernel module and ktap binary + +3. Load ktapvm kernel module(make sure debugfs mounted) + + $ make load #need to be root or have sudo access + +4. Running ktap + + $ ./ktap scripts/helloworld.kp + + +## Examples + +1. simplest one-liner command to enable all tracepoints + + ktap -e "trace *:* { print(argevent) }" + +2. syscall tracing on target process + + ktap -e "trace syscalls:* { print(argevent) }" -- ls + +3. function tracing + + ktap -e "trace ftrace:function { print(argevent) }" + + ktap -e "trace ftrace:function /ip==mutex*/ { print(argevent) }" + +4. simple syscall tracing + + trace syscalls:* { + print(cpu(), pid(), execname(), argevent) + } + +5. syscall tracing in histogram style + + s = {} + + trace syscalls:sys_enter_* { + s[argname] += 1 + } + + trace_end { + histogram(s) + } + +6. kprobe tracing + + trace probe:do_sys_open dfd=%di fname=%dx flags=%cx mode=+4($stack) { + print("entry:", execname(), argevent) + } + + trace probe:do_sys_open%return fd=$retval { + print("exit:", execname(), argevent) + } + +7. uprobe tracing + + trace probe:/lib/libc.so.6:0x000773c0 { + print("entry:", execname(), argevent) + } + + trace probe:/lib/libc.so.6:0x000773c0%return { + print("exit:", execname(), argevent) + } + +8. timer + + tick-1ms { + printf("time fired on one cpu\n"); + } + + profile-2s { + printf("time fired on every cpu\n"); + } + +More sample scripts can be found at scripts/ directory. + +## Mailing list + +ktap@freelists.org +You can subscribe to ktap mailing list at link (subscribe before posting): +http://www.freelists.org/list/ktap + + +## Copyright and License + +ktap is licensed under GPL v2 + +Copyright (C) 2012-2013, Jovi Zhangwei <jovi.zhangwei@gmail.com>. +All rights reserved. + + +## Contribution + +ktap is still under active development, so contributions are welcome. +You are encouraged to report bugs, provide feedback, send feature request, +or hack on it. + + +## See More + +More info can be found at [documentation][tutorial] +[tutorial]: http://www.ktap.org/doc/tutorial.html + diff --git a/drivers/staging/ktap/doc/tutorial.md b/drivers/staging/ktap/doc/tutorial.md new file mode 100644 index 000000000000..3c32ce77a731 --- /dev/null +++ b/drivers/staging/ktap/doc/tutorial.md @@ -0,0 +1,552 @@ +% The ktap Tutorial + +# Introduction + +ktap is a new scripting dynamic tracing tool for linux + +ktap is a new scripting dynamic tracing tool for Linux, +it uses a scripting language and lets users trace the Linux kernel dynamically. +ktap is designed to give operational insights with interoperability +that allows users to tune, troubleshoot and extend kernel and application. +It's similar with Linux Systemtap and Solaris Dtrace. + +ktap have different design principles from Linux mainstream dynamic tracing +language in that it's based on bytecode, so it doesn't depend upon GCC, +doesn't require compiling kernel module for each script, safe to use in +production environment, fulfilling the embedded ecosystem's tracing needs. + +Highlights features: + +* simple but powerful scripting language +* register based interpreter (heavily optimized) in Linux kernel +* small and lightweight (6KLOC of interpreter) +* not depend on gcc for each script running +* easy to use in embedded environment without debugging info +* support for tracepoint, kprobe, uprobe, function trace, timer, and more +* supported in x86, arm, ppc, mips +* safety in sandbox + + +# Getting started + +Requirements + +* Linux 3.1 or later(Need some kernel patches for kernel earlier than 3.1) +* CONFIG_EVENT_TRACING enabled +* CONFIG_PERF_EVENTS enabled +* CONFIG_DEBUG_FS enabled + (make sure debugfs mounted before insmod ktapvm + mount debugfs: mount -t debugfs none /sys/kernel/debug/) + +Note that those configuration is always enabled in Linux distribution, +like REHL, Fedora, Ubuntu, etc. + +1. Clone ktap from github + + $ git clone http://github.com/ktap/ktap.git + +2. Compiling ktap + + $ cd ktap + $ make #generate ktapvm kernel module and ktap binary + +3. Load ktapvm kernel module(make sure debugfs mounted) + + $ make load #need to be root or have sudo access + +4. Running ktap + + $ ./ktap scripts/helloworld.kp + + +# Language basics + +## Syntax basics + +ktap's syntax is design on the mind of C language syntax friendly, +to make it easy scripting by kernel developer. + +1. Variable declaration +The biggest syntax differences with C is that ktap is a dynamic typed +language, so you won't need add any variable type declaration, just +use the variable. + +2. function +All functions in ktap should use keyword "function" declaration + +3. comments +The comments of ktap is starting from '#', long comments doesn't support now. + +4. others +Don't need place any ';' at the ending of statement in ktap. +ktap use free syntax style, so you can choose to use the ';' or not. + +ktap use nil as NULL, the result of any number operate on nil is nil. + +ktap don't have array structure, also don't have any pointer operation. + +## Control structures + +ktap if/else is same as C language. + +There have two method of for-loop in ktap: + + for (i = init, limit, step) { body } + +this is same as below in C: + + for (i = init; i < limit; i += step) { body } + +The next for-loop method is: + + for (k, v in pairs(t)) { body } # looping all elements |
