Git Product home page Git Product logo

salp's Introduction

Salp

Salp is a library that enables Go programs to create and fire USDT probes at runtime. Such probes allow API-stable (i.e. not dependent on function names) tracing of executables written in Go - especially important since function tracing of Go code requires some unappealing (though not unimpressive) hacks. Salp uses the libstapsdt library to create and fire these probes.

GoDoc

Build

Dependencies

Salp depends on libstapsdt which in turn depends on libelf and libdl. libstapsdt can be built from source or (for debian based distros) installed via an Ubuntu PPA. Full instructions are available in the docs for libstapsdt

Build and Test

If libstdapsdt is installed globally (e.g. from the PPA above or via make install), you should be able to simply go build or go test. However if you have built libstapsdt from source then you will need to tell the cgo tool how to find the headers and .so files for libstapsdt using the CGO_CFLAGS, CGO_LDFLAGS, and LD_LIBRARY_PATH environment variables.

export CGO_CFLAGS="-I/path/to/libstapsdt/src"
export CGO_LDFLAGS="-L/path/to/libstapsdt/out"
export LD_LIBRARY_PATH="/path/to/libstapsdt/out"

Demo

This repository contains a demo executable that will fire two different probes every second. The demo can be observed using the trace and tplist tools from the bcc project. Use two terminals to run the demo - one to execute the tracable salpdemo go program and one to run the bcc tools and see their output. In the first window run

go run internal/salpdemo.go

This program will print out how to monitor itself but then won't print out anything after that. In the second window run the bcc trace program on the salpdemo process, monitoring probes p1 and p2.

sudo trace -p "$(pgrep -n salpdemo)"                    \
    'u::p1 "i=%d err='%s' date='%s'", arg1, arg2, arg3' \
    'u::p2 "j=%d flag=%d", arg1, arg2'

or alternatively the same thing with bpftrace

sudo bpftrace -p "$(pgrep -n salpdemo)" /dev/stdin <<EOF
  usdt:p1 { printf("i=%d err='%s' date='%s'\n", arg0, str(arg1), str(arg2)); }
  usdt:p2 { printf("j=%d flag=%d\n", arg0, arg1); }
EOF

Either trace invocations will output the values of the three args to probe 1 and the two args to probe 2.

salp's People

Contributors

mmcshane avatar mpm-do avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

salp's Issues

Stub out on OS X

I'm not interested in instrumenting on OS X but compiling would be good.

setting the env. variables CGO_* and LD_* prevent compilation

If I see the environment variables CGO_CFLAGS, CGO_LDFLAGS, and LD_LIBRARY_PATH then my program will NOT compile. I get the following error:

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/home/opc/libstapsdt/out/libstapsdt.a(libstapsdt.o): In function providerLoad': libstapsdt.c:(.text+0x63e): undefined reference to dlopen'
libstapsdt.c:(.text+0x65b): undefined reference to dlerror' libstapsdt.c:(.text+0x6ae): undefined reference to dlsym'
libstapsdt.c:(.text+0x6b7): undefined reference to dlerror' /home/opc/libstapsdt/out/libstapsdt.a(libstapsdt.o): In function providerUnload':
libstapsdt.c:(.text+0x74e): undefined reference to dlclose' libstapsdt.c:(.text+0x757): undefined reference to dlerror'
/home/opc/libstapsdt/out/libstapsdt.a(shared-lib.o): In function createElf': shared-lib.c:(.text+0x11): undefined reference to elf_version'
shared-lib.c:(.text+0x30): undefined reference to elf_begin' /home/opc/libstapsdt/out/libstapsdt.a(shared-lib.o): In function createElfHeader':
shared-lib.c:(.text+0xb8): undefined reference to elf64_newehdr' /home/opc/libstapsdt/out/libstapsdt.a(shared-lib.o): In function createElfProgramHeaders':
shared-lib.c:(.text+0x122): undefined reference to elf64_newphdr' /home/opc/libstapsdt/out/libstapsdt.a(shared-lib.o): In function dynElfSave':
shared-lib.c:(.text+0xad9): undefined reference to elf_ndxscn' shared-lib.c:(.text+0xbbe): undefined reference to elf_ndxscn'
shared-lib.c:(.text+0xf14): undefined reference to elf_ndxscn' shared-lib.c:(.text+0x10ff): undefined reference to elf_ndxscn'
shared-lib.c:(.text+0x1122): undefined reference to elf_update' shared-lib.c:(.text+0x1402): undefined reference to elf_update'
shared-lib.c:(.text+0x16ec): undefined reference to elf_ndxscn' shared-lib.c:(.text+0x1763): undefined reference to elf_ndxscn'
shared-lib.c:(.text+0x17f7): undefined reference to elf_ndxscn' shared-lib.c:(.text+0x186c): undefined reference to elf_ndxscn'
shared-lib.c:(.text+0x18e1): undefined reference to elf_ndxscn' shared-lib.c:(.text+0x198d): undefined reference to elf_flagphdr'
shared-lib.c:(.text+0x19a1): undefined reference to elf_update' /home/opc/libstapsdt/out/libstapsdt.a(shared-lib.o): In function dynElfClose':
shared-lib.c:(.text+0x1bbe): undefined reference to elf_end' /home/opc/libstapsdt/out/libstapsdt.a(section.o): In function sectionInit':
section.c:(.text+0x4d): undefined reference to elf_newscn' section.c:(.text+0x85): undefined reference to elf_newdata'
section.c:(.text+0xbf): undefined reference to elf64_getshdr' /home/opc/libstapsdt/out/libstapsdt.a(hash-table.o): In function hashTableFromSymbolTable':
hash-table.c:(.text+0xae): undefined reference to `elf_hash'
collect2: error: ld returned 1 exit status

When I remove those environment variables then my program will compile. I have to set the environment variables for the program to run. You just can't have them set when compiling the program.

Eliminate libstapsdt dependency

It's a fine library and all but it's an impediment to development and deployment. I'd like to get the dependencies down to just libdl (for dlopen, which is probably unavoidable)

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.