GithubHelp home page GithubHelp logo

eagles125 / ktap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ktap/ktap

0.0 2.0 0.0 2.63 MB

A lightweight script-based dynamic tracing tool for Linux

Home Page: ktap.org

License: Other

ktap's Introduction

ktap

A New Scripting Dynamic Tracing Tool For Linux
www.ktap.org

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.

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 samples/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. ftrace(kernel newer than 3.3, and must compiled with CONFIG_FUNCTION_TRACER)

     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

     var 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:malloc {
             print("entry:", execname(), argevent)
     }
    
     trace probe:/lib/libc.so.6:malloc%return {
             print("exit:", execname(), argevent)
     }
    
  8. stapsdt tracing (userspace static marker)

     trace sdt:/lib64/libc.so.6:lll_futex_wake {
             print("lll_futex_wake", execname(), argevent)
     }
    
     or:
    
     #trace all static mark in libc
     trace sdt:/lib64/libc.so.6:* {
             print(execname(), argevent)
     }
    
  9. timer

     tick-1ms {
             printf("time fired on one cpu\n");
     }
    
     profile-2s {
             printf("time fired on every cpu\n");
     }
    
  10. FFI (Call kernel function from ktap script, need compile with FFI=1)

    cdef[[
            int printk(char *fmt, ...);
    ]]
    
    C.printk("This message is called from ktap ffi\n")
    

More examples can be found at samples directory.

Mailing list

[email protected]
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 [email protected]. 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

ktap's People

Contributors

ktap avatar yichengq avatar azat avatar houqp avatar stadaki avatar bnoordhuis avatar gregkh avatar darander avatar gm281 avatar libin2015 avatar xs3c avatar askondro avatar philips avatar fomichev avatar yegorich avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.