Created
August 31, 2012 17:34
-
-
Save ecin/3556241 to your computer and use it in GitHub Desktop.
Dtrace probes in your Golang code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "probes.h" | |
void Ping() { | |
GOLANG_PING(); | |
} | |
bool Ping_enabled() { | |
return GOLANG_PING_ENABLED(); | |
} | |
void Pong() { | |
GOLANG_PONG(); | |
} | |
bool Pong_enabled() { | |
return GOLANG_PONG_ENABLED(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Generate probes.h header file with: | |
dtrace -o probes.h -h -s probes.d | |
*/ | |
provider golang { | |
probe ping(); | |
probe pong(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo of static Dtrace probes in Golang. Run with
go run goarena.go
, spectate withsudo dtrace -s spectator.d
.I failed at making Golang's cgo work nicely with a static library, which is why probes.c needs to be compiled as a shared library. Otherwise, dtrace's probe.h file could have been used directly.
Golang bindings for Chris Andrew's libusdt would probably allow more user-friendly dtrace probes in similar programs.