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
/* | |
Compile probes.c as a shared library | |
In Mac OS X (http://www.finkproject.org/doc/porting/shared.php#build-lib): | |
cc -fno-common -c probes.c | |
cc -dynamiclib -install_name /usr/local/lib/libprobes.dylib -o libprobes.dylib probes.o | |
cp libprobes.dylib /usr/local/lib/ | |
*/ | |
#include "probes.h" | |
void Ping() { | |
GOLANG_PING(); | |
} | |
int Ping_enabled() { | |
return GOLANG_PING_ENABLED(); | |
} | |
void Pong() { | |
GOLANG_PONG(); | |
} | |
int 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(); | |
}; |
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
/* Header file generated by dtrace */ | |
/* ... */ | |
void Ping(); | |
int Ping_enabled(); | |
void Pong(); | |
int Pong_enabled(); |
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.