Skip to content
USDT probes in Golang on Linux via libstapsdt
Go
Branch: master
Clone or download
Latest commit 08bee40 Aug 29, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
internal Code quality in demo exe Aug 29, 2018
.gitignore Initial commit Nov 23, 2017
LICENSE Initial commit Nov 23, 2017
README.md README.md typo: form -> from Aug 29, 2018
salp.go Remove assignment of nil to pointer receiver Aug 29, 2018
salp_test.go Typo fixes Aug 29, 2018

README.md

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 salpdemo | head -n1)" \
    'u::p1 "arg1=%d arg2=%s", arg1, arg2' \
    'u::p2 "arg1=%d", arg1'

trace will output the values of arg1 and arg2 from probe p1 and the value of arg1 from probe p2.

You can’t perform that action at this time.