ruby-usdt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +18 -0
- data/README.md +75 -0
- data/ext/libusdt/Makefile +117 -0
- data/ext/libusdt/README +59 -0
- data/ext/libusdt/test.pl +83 -0
- data/ext/libusdt/test_usdt.c +60 -0
- data/ext/libusdt/usdt.c +198 -0
- data/ext/libusdt/usdt.h +50 -0
- data/ext/libusdt/usdt_dof.c +118 -0
- data/ext/libusdt/usdt_dof_file.c +240 -0
- data/ext/libusdt/usdt_dof_sections.c +172 -0
- data/ext/libusdt/usdt_internal.h +100 -0
- data/ext/libusdt/usdt_probe.c +66 -0
- data/ext/libusdt/usdt_tracepoints_i386.s +65 -0
- data/ext/libusdt/usdt_tracepoints_x86_64.s +83 -0
- data/ext/usdt/Makefile +157 -0
- data/ext/usdt/conftest.dSYM/Contents/Info.plist +20 -0
- data/ext/usdt/conftest.dSYM/Contents/Resources/DWARF/conftest +0 -0
- data/ext/usdt/extconf.rb +9 -0
- data/ext/usdt/test.rb +23 -0
- data/ext/usdt/usdt.c +141 -0
- data/ext/usdt/usdt.h +50 -0
- data/lib/usdt/version.rb +3 -0
- data/lib/usdt.rb +2 -0
- metadata +71 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
/*
|
2
|
+
* Stub functions containing DTrace tracepoints for probes and
|
3
|
+
* is-enabled probes. These functions are copied for each probe
|
4
|
+
* dynamically created.
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
.text
|
8
|
+
|
9
|
+
.align 4, 0x90
|
10
|
+
.globl usdt_tracepoint_isenabled
|
11
|
+
.globl _usdt_tracepoint_isenabled
|
12
|
+
.globl usdt_tracepoint_probe
|
13
|
+
.globl _usdt_tracepoint_probe
|
14
|
+
.globl usdt_tracepoint_end
|
15
|
+
.globl _usdt_tracepoint_end
|
16
|
+
.globl usdt_probe_args
|
17
|
+
.globl _usdt_probe_args
|
18
|
+
|
19
|
+
usdt_tracepoint_isenabled:
|
20
|
+
_usdt_tracepoint_isenabled:
|
21
|
+
pushl %ebp
|
22
|
+
movl %esp, %ebp
|
23
|
+
subl $8, %esp
|
24
|
+
xorl %eax, %eax
|
25
|
+
nop
|
26
|
+
nop
|
27
|
+
leave
|
28
|
+
ret
|
29
|
+
usdt_tracepoint_probe:
|
30
|
+
_usdt_tracepoint_probe:
|
31
|
+
nop
|
32
|
+
nop
|
33
|
+
nop
|
34
|
+
nop
|
35
|
+
nop
|
36
|
+
addl $0x20,%esp
|
37
|
+
leave
|
38
|
+
usdt_tracepoint_end:
|
39
|
+
_usdt_tracepoint_end:
|
40
|
+
ret
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Probe argument marshalling, i386 style
|
44
|
+
*
|
45
|
+
*/
|
46
|
+
|
47
|
+
usdt_probe_args:
|
48
|
+
_usdt_probe_args:
|
49
|
+
pushl %ebp
|
50
|
+
movl %esp,%ebp
|
51
|
+
subl $8,%esp
|
52
|
+
subl $8,%esp
|
53
|
+
movl 8(%ebp),%ebx
|
54
|
+
movl 0xc(%ebp),%ecx
|
55
|
+
test %ecx,%ecx
|
56
|
+
je fire
|
57
|
+
args: movl %ecx,%eax
|
58
|
+
sal $2,%eax
|
59
|
+
subl $4,%eax
|
60
|
+
addl 0x10(%ebp),%eax
|
61
|
+
pushl (%eax)
|
62
|
+
dec %ecx
|
63
|
+
jne args
|
64
|
+
fire: jmp *%ebx
|
65
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
/*
|
2
|
+
* Stub functions containing DTrace tracepoints for probes and
|
3
|
+
* is-enabled probes. These functions are copied for each probe
|
4
|
+
* dynamically created.
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
.text
|
8
|
+
|
9
|
+
.align 4, 0x90
|
10
|
+
.globl usdt_tracepoint_isenabled
|
11
|
+
.globl _usdt_tracepoint_isenabled
|
12
|
+
.globl usdt_tracepoint_probe
|
13
|
+
.globl _usdt_tracepoint_probe
|
14
|
+
.globl usdt_tracepoint_end
|
15
|
+
.globl _usdt_tracepoint_end
|
16
|
+
.globl usdt_probe_args
|
17
|
+
.globl _usdt_probe_args
|
18
|
+
|
19
|
+
usdt_tracepoint_isenabled:
|
20
|
+
_usdt_tracepoint_isenabled:
|
21
|
+
pushq %rbp
|
22
|
+
movq %rsp, %rbp
|
23
|
+
xorq %rax, %rax
|
24
|
+
nop
|
25
|
+
nop
|
26
|
+
leave
|
27
|
+
ret
|
28
|
+
usdt_tracepoint_probe:
|
29
|
+
_usdt_tracepoint_probe:
|
30
|
+
nop
|
31
|
+
nop
|
32
|
+
nop
|
33
|
+
nop
|
34
|
+
nop
|
35
|
+
popq %r11
|
36
|
+
popq %rbx
|
37
|
+
popq %r12
|
38
|
+
addq $0x18,%rsp
|
39
|
+
leave
|
40
|
+
usdt_tracepoint_end:
|
41
|
+
_usdt_tracepoint_end:
|
42
|
+
ret
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Probe argument marshalling, x86_64 style
|
46
|
+
*
|
47
|
+
*/
|
48
|
+
|
49
|
+
usdt_probe_args:
|
50
|
+
_usdt_probe_args:
|
51
|
+
pushq %rbp
|
52
|
+
movq %rsp,%rbp
|
53
|
+
subq $0x18,%rsp
|
54
|
+
pushq %r12
|
55
|
+
pushq %rbx
|
56
|
+
pushq %r11
|
57
|
+
movq %rdi,%r12
|
58
|
+
movq %rsi,%rbx
|
59
|
+
movq %rdx,%r11
|
60
|
+
test %rbx,%rbx
|
61
|
+
je fire
|
62
|
+
movq (%r11),%rdi
|
63
|
+
dec %rbx
|
64
|
+
test %rbx,%rbx
|
65
|
+
je fire
|
66
|
+
movq 8(%r11),%rsi
|
67
|
+
dec %rbx
|
68
|
+
test %rbx,%rbx
|
69
|
+
je fire
|
70
|
+
movq 16(%r11),%rdx
|
71
|
+
dec %rbx
|
72
|
+
test %rbx,%rbx
|
73
|
+
je fire
|
74
|
+
movq 24(%r11),%rcx
|
75
|
+
dec %rbx
|
76
|
+
test %rbx,%rbx
|
77
|
+
je fire
|
78
|
+
movq 32(%r11),%r8
|
79
|
+
dec %rbx
|
80
|
+
test %rbx,%rbx
|
81
|
+
je fire
|
82
|
+
movq 40(%r11),%r9
|
83
|
+
fire: jmp *%r12
|
data/ext/usdt/Makefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /Users/kevin/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/i686-darwin11.3.0
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/Users/kevin/.rvm/rubies/ruby-1.8.7-p358
|
11
|
+
exec_prefix = $(prefix)
|
12
|
+
htmldir = $(docdir)
|
13
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
14
|
+
sitedir = $(libdir)/ruby/site_ruby
|
15
|
+
pdfdir = $(docdir)
|
16
|
+
dvidir = $(docdir)
|
17
|
+
sharedstatedir = $(prefix)/com
|
18
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
19
|
+
psdir = $(docdir)
|
20
|
+
libexecdir = $(exec_prefix)/libexec
|
21
|
+
datarootdir = $(prefix)/share
|
22
|
+
bindir = $(exec_prefix)/bin
|
23
|
+
infodir = $(datarootdir)/info
|
24
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
25
|
+
sysconfdir = $(prefix)/etc
|
26
|
+
archdir = $(rubylibdir)/$(arch)
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
includedir = $(prefix)/include
|
29
|
+
mandir = $(datarootdir)/man
|
30
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
31
|
+
localstatedir = $(prefix)/var
|
32
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
33
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
34
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
35
|
+
datadir = $(datarootdir)
|
36
|
+
localedir = $(datarootdir)/locale
|
37
|
+
libdir = $(exec_prefix)/lib
|
38
|
+
oldincludedir = $(DESTDIR)/usr/include
|
39
|
+
|
40
|
+
CC = /usr/bin/gcc-4.2
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fno-common -g -O2 -fno-common -pipe -fno-common $(cflags)
|
48
|
+
INCFLAGS = -I. -I. -I/Users/kevin/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/i686-darwin11.3.0 -I.
|
49
|
+
DEFS =
|
50
|
+
CPPFLAGS = -DHAVE_USDT_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L.
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby
|
61
|
+
RUBY_SO_NAME = ruby
|
62
|
+
arch = i686-darwin11.3.0
|
63
|
+
sitearch = i686-darwin11.3.0
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /Users/kevin/.rvm/rubies/ruby-1.8.7-p358/bin/ruby
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lusdt -ldtrace -ldl -lobjc
|
90
|
+
SRCS = usdt.c
|
91
|
+
OBJS = usdt.o
|
92
|
+
TARGET = usdt
|
93
|
+
DLLIB = $(TARGET).bundle
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS) Makefile
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
6
|
+
<string>English</string>
|
7
|
+
<key>CFBundleIdentifier</key>
|
8
|
+
<string>com.apple.xcode.dsym.conftest</string>
|
9
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
10
|
+
<string>6.0</string>
|
11
|
+
<key>CFBundlePackageType</key>
|
12
|
+
<string>dSYM</string>
|
13
|
+
<key>CFBundleSignature</key>
|
14
|
+
<string>????</string>
|
15
|
+
<key>CFBundleShortVersionString</key>
|
16
|
+
<string>1.0</string>
|
17
|
+
<key>CFBundleVersion</key>
|
18
|
+
<string>1</string>
|
19
|
+
</dict>
|
20
|
+
</plist>
|
Binary file
|
data/ext/usdt/extconf.rb
ADDED
data/ext/usdt/test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/usdt'
|
2
|
+
|
3
|
+
provider = USDT::Provider.create :ruby, :test
|
4
|
+
puts provider
|
5
|
+
p = provider.probe("myfn", "probe",
|
6
|
+
:string, :string, :integer)
|
7
|
+
|
8
|
+
provider.enable
|
9
|
+
|
10
|
+
puts "run:\nsudo dtrace -n 'ruby*:test:myfn:probe { printf(\"%s %s %d\",
|
11
|
+
copyinstr(arg0),
|
12
|
+
copyinstr(arg1),
|
13
|
+
args[2])
|
14
|
+
}'"
|
15
|
+
|
16
|
+
while true
|
17
|
+
if p.enabled?
|
18
|
+
p.fire("one", "two", 3)
|
19
|
+
puts("Fired!")
|
20
|
+
end
|
21
|
+
sleep 0.5
|
22
|
+
end
|
23
|
+
|
data/ext/usdt/usdt.c
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "usdt.h"
|
3
|
+
|
4
|
+
VALUE USDT;
|
5
|
+
VALUE USDT_Provider;
|
6
|
+
VALUE USDT_Probe;
|
7
|
+
VALUE USDT_Error;
|
8
|
+
|
9
|
+
static VALUE provider_create(VALUE self, VALUE name, VALUE mod);
|
10
|
+
static VALUE provider_probe(int argc, VALUE *argv, VALUE self);
|
11
|
+
static VALUE provider_enable(VALUE self);
|
12
|
+
static VALUE probe_enabled(VALUE self);
|
13
|
+
static VALUE probe_fire(int argc, VALUE *argv, VALUE self);
|
14
|
+
|
15
|
+
void Init_usdt() {
|
16
|
+
USDT = rb_define_module("USDT");
|
17
|
+
|
18
|
+
USDT_Error = rb_define_class_under(USDT, "Error", rb_eRuntimeError);
|
19
|
+
|
20
|
+
USDT_Provider = rb_define_class_under(USDT, "Provider", rb_cObject);
|
21
|
+
rb_define_singleton_method(USDT_Provider, "create", provider_create, 2);
|
22
|
+
rb_define_method(USDT_Provider, "probe", provider_probe, -1);
|
23
|
+
rb_define_method(USDT_Provider, "enable", provider_enable, 0);
|
24
|
+
|
25
|
+
USDT_Probe = rb_define_class_under(USDT, "Probe", rb_cObject);
|
26
|
+
rb_define_method(USDT_Probe, "enabled?", probe_enabled, 0);
|
27
|
+
rb_define_method(USDT_Probe, "fire", probe_fire, -1);
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* USDT::Provider.create :name, :modname
|
32
|
+
*/
|
33
|
+
static VALUE provider_create(VALUE self, VALUE name, VALUE mod) {
|
34
|
+
Check_Type(name, T_SYMBOL);
|
35
|
+
Check_Type(mod, T_SYMBOL);
|
36
|
+
|
37
|
+
char *namestr = rb_id2name(rb_to_id(name));
|
38
|
+
char *modstr = rb_id2name(rb_to_id(mod));
|
39
|
+
|
40
|
+
usdt_provider_t* p = usdt_create_provider(namestr, modstr);
|
41
|
+
|
42
|
+
VALUE rbProvider = Data_Wrap_Struct(USDT_Provider, NULL, free, p);
|
43
|
+
|
44
|
+
if (rb_block_given_p()) {
|
45
|
+
rb_yield(rbProvider);
|
46
|
+
}
|
47
|
+
|
48
|
+
return rbProvider;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* USDT::Provider#probe(func, name, pargs*)
|
53
|
+
*/
|
54
|
+
static VALUE provider_probe(int argc, VALUE *argv, VALUE self) {
|
55
|
+
const char *func = RSTRING_PTR(argv[0]);
|
56
|
+
const char *name = RSTRING_PTR(argv[1]);
|
57
|
+
const char *types[6];
|
58
|
+
size_t i, pargc = 0;
|
59
|
+
size_t t_int = rb_intern("integer");
|
60
|
+
size_t t_str = rb_intern("string");
|
61
|
+
|
62
|
+
for (i = 0; i < 6; i++) {
|
63
|
+
if (i < argc - 2) {
|
64
|
+
Check_Type(argv[i+2], T_SYMBOL);
|
65
|
+
if (t_int == rb_to_id(argv[i+2])) {
|
66
|
+
types[i] = "int";
|
67
|
+
pargc++;
|
68
|
+
} else if (t_str == rb_to_id(argv[i+2])) {
|
69
|
+
types[i] = "char *";
|
70
|
+
pargc++;
|
71
|
+
} else {
|
72
|
+
types[i] = NULL;
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
types[i] = NULL;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
usdt_provider_t *provider = DATA_PTR(self);
|
80
|
+
|
81
|
+
usdt_probedef_t **probe;
|
82
|
+
probe = ALLOC(usdt_probedef_t *);
|
83
|
+
*probe = usdt_create_probe(func, name, pargc, types);
|
84
|
+
|
85
|
+
usdt_provider_add_probe(provider, *probe);
|
86
|
+
VALUE rbProbe = Data_Wrap_Struct(USDT_Probe, NULL, free, probe);
|
87
|
+
return rbProbe;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* USDT::Provider#enable
|
92
|
+
*/
|
93
|
+
static VALUE provider_enable(VALUE self) {
|
94
|
+
usdt_provider_t *provider = DATA_PTR(self);
|
95
|
+
int status = usdt_provider_enable(provider);
|
96
|
+
if (status == 0) {
|
97
|
+
return Qtrue;
|
98
|
+
} else {
|
99
|
+
rb_raise(USDT_Error, "%s", usdt_errstr(provider));
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* USDT::Probe#enabled?
|
105
|
+
*/
|
106
|
+
static VALUE probe_enabled(VALUE self) {
|
107
|
+
usdt_probedef_t **p = DATA_PTR(self);
|
108
|
+
usdt_probedef_t *pd = *p;
|
109
|
+
|
110
|
+
if (usdt_is_enabled(pd->probe) == 0) {
|
111
|
+
return Qfalse;
|
112
|
+
} else {
|
113
|
+
return Qtrue;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* USDT::Probe#fire *args
|
119
|
+
*/
|
120
|
+
static VALUE probe_fire(int argc, VALUE *argv, VALUE self) {
|
121
|
+
usdt_probedef_t **p = DATA_PTR(self);
|
122
|
+
usdt_probedef_t *probedef = *p;
|
123
|
+
|
124
|
+
void *pargs[6];
|
125
|
+
int i;
|
126
|
+
|
127
|
+
for (i = 0; i < probedef->argc; i++) {
|
128
|
+
if (probedef->types[i] == USDT_ARGTYPE_STRING) {
|
129
|
+
Check_Type(argv[i], T_STRING);
|
130
|
+
pargs[i] = (void *) RSTRING_PTR(argv[i]);
|
131
|
+
} else if (probedef->types[i] == USDT_ARGTYPE_INTEGER) {
|
132
|
+
Check_Type(argv[i], T_FIXNUM);
|
133
|
+
pargs[i] = (void *) FIX2INT(argv[i]);
|
134
|
+
} else {
|
135
|
+
pargs[i] = NULL;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
usdt_fire_probe(probedef->probe, probedef->argc, pargs);
|
140
|
+
return Qtrue;
|
141
|
+
}
|
data/ext/usdt/usdt.h
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#include <stdint.h>
|
2
|
+
#include <unistd.h>
|
3
|
+
|
4
|
+
typedef uint8_t usdt_argtype_t;
|
5
|
+
#define USDT_ARGTYPE_NONE 0
|
6
|
+
#define USDT_ARGTYPE_STRING 1
|
7
|
+
#define USDT_ARGTYPE_INTEGER 2
|
8
|
+
|
9
|
+
typedef enum usdt_error {
|
10
|
+
USDT_ERROR_MALLOC = 0,
|
11
|
+
USDT_ERROR_VALLOC,
|
12
|
+
USDT_ERROR_NOPROBES,
|
13
|
+
USDT_ERROR_LOADDOF
|
14
|
+
} usdt_error_t;
|
15
|
+
|
16
|
+
typedef struct usdt_probe {
|
17
|
+
int (*isenabled_addr)(void);
|
18
|
+
void *probe_addr;
|
19
|
+
} usdt_probe_t;
|
20
|
+
|
21
|
+
int usdt_is_enabled(usdt_probe_t *probe);
|
22
|
+
void usdt_fire_probe(usdt_probe_t *probe, size_t argc, void **argv);
|
23
|
+
|
24
|
+
typedef struct usdt_probedef {
|
25
|
+
const char *name;
|
26
|
+
const char *function;
|
27
|
+
size_t argc;
|
28
|
+
usdt_argtype_t types[6];
|
29
|
+
struct usdt_probe *probe;
|
30
|
+
struct usdt_probedef *next;
|
31
|
+
} usdt_probedef_t;
|
32
|
+
|
33
|
+
usdt_probedef_t *usdt_create_probe_varargs(const char *func, const char *name, ...);
|
34
|
+
usdt_probedef_t *usdt_create_probe(const char *func, const char *name,
|
35
|
+
size_t argc, const char **types);
|
36
|
+
|
37
|
+
typedef struct usdt_provider {
|
38
|
+
const char *name;
|
39
|
+
const char *module;
|
40
|
+
usdt_probedef_t *probedefs;
|
41
|
+
char *error;
|
42
|
+
} usdt_provider_t;
|
43
|
+
|
44
|
+
usdt_provider_t *usdt_create_provider(const char *name, const char *module);
|
45
|
+
void usdt_provider_add_probe(usdt_provider_t *provider, usdt_probedef_t *probedef);
|
46
|
+
int usdt_provider_enable(usdt_provider_t *provider);
|
47
|
+
|
48
|
+
void usdt_error(usdt_provider_t *provider, usdt_error_t error);
|
49
|
+
char *usdt_errstr(usdt_provider_t *provider);
|
50
|
+
|
data/lib/usdt/version.rb
ADDED
data/lib/usdt.rb
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-usdt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Chan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- kevin@yinkei.com
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/usdt/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/usdt/version.rb
|
23
|
+
- lib/usdt.rb
|
24
|
+
- ext/libusdt/Makefile
|
25
|
+
- ext/libusdt/README
|
26
|
+
- ext/libusdt/test.pl
|
27
|
+
- ext/libusdt/test_usdt.c
|
28
|
+
- ext/libusdt/usdt.c
|
29
|
+
- ext/libusdt/usdt.h
|
30
|
+
- ext/libusdt/usdt_dof.c
|
31
|
+
- ext/libusdt/usdt_dof_file.c
|
32
|
+
- ext/libusdt/usdt_dof_sections.c
|
33
|
+
- ext/libusdt/usdt_internal.h
|
34
|
+
- ext/libusdt/usdt_probe.c
|
35
|
+
- ext/libusdt/usdt_tracepoints_i386.s
|
36
|
+
- ext/libusdt/usdt_tracepoints_x86_64.s
|
37
|
+
- ext/usdt/conftest.dSYM/Contents/Info.plist
|
38
|
+
- ext/usdt/conftest.dSYM/Contents/Resources/DWARF/conftest
|
39
|
+
- ext/usdt/extconf.rb
|
40
|
+
- ext/usdt/Makefile
|
41
|
+
- ext/usdt/test.rb
|
42
|
+
- ext/usdt/usdt.c
|
43
|
+
- ext/usdt/usdt.h
|
44
|
+
- README.md
|
45
|
+
- LICENSE.md
|
46
|
+
homepage: http://github.com/kevinykchan/ruby-usdt
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
- ext
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.21
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: ruby bindings to libusdt
|
71
|
+
test_files: []
|