Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmcshane/salp
USDT probes in Golang on Linux
https://github.com/mmcshane/salp
cgo ebpf go golang usdt
Last synced: 2 months ago
JSON representation
USDT probes in Golang on Linux
- Host: GitHub
- URL: https://github.com/mmcshane/salp
- Owner: mmcshane
- License: mit
- Created: 2017-11-23T08:20:57.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-08-10T20:05:52.000Z (over 1 year ago)
- Last Synced: 2024-06-20T03:28:48.588Z (7 months ago)
- Topics: cgo, ebpf, go, golang, usdt
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 31
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](http://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html).
Salp uses the [libstapsdt](https://github.com/sthima/libstapsdt) library to create
and fire these probes.[![GoDoc](https://godoc.org/github.com/mmcshane/salp?status.svg)](https://godoc.org/github.com/mmcshane/salp)
## 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](http://libstapsdt.readthedocs.io/en/latest/getting-started/getting-started.html)### 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.```bash
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](https://github.com/iovisor/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```bash
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`.```bash
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`
```bash
sudo bpftrace -p "$(pgrep -n salpdemo)" /dev/stdin <