ruby-usdt 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -3
- data/ext/usdt/usdt.c +41 -7
- data/lib/usdt/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -5,13 +5,18 @@ Native DTrace probes for ruby apps
|
|
5
5
|
Ruby bindings for [libusdt](https://github.com/chrisa/libusdt).
|
6
6
|
|
7
7
|
Applications, Libraries, and Frameworks can consume ruby-usdt to define USDT
|
8
|
-
providers at runtime for instrumentation and analysis by the
|
8
|
+
providers at runtime for instrumentation and analysis by the
|
9
9
|
[DTrace](http://en.wikipedia.org/wiki/DTrace) framework.
|
10
10
|
|
11
11
|
### Install
|
12
12
|
|
13
13
|
gem install ruby-usdt
|
14
14
|
|
15
|
+
When using Bundler to integrate ruby-usdt into a Ruby or Rails project,
|
16
|
+
you will need to specify that there are git submodule dependencies:
|
17
|
+
|
18
|
+
gem "ruby-usdt", :submodules => true
|
19
|
+
|
15
20
|
### Usage
|
16
21
|
|
17
22
|
# Provider.create <provider>, <module>
|
@@ -33,7 +38,7 @@ providers at runtime for instrumentation and analysis by the DTrace
|
|
33
38
|
provider.enable
|
34
39
|
|
35
40
|
while true
|
36
|
-
if p.enabled
|
41
|
+
if p.enabled?
|
37
42
|
p.fire("omg", "probe!!", 12345)
|
38
43
|
end
|
39
44
|
sleep 0.5
|
@@ -46,7 +51,7 @@ providers at runtime for instrumentation and analysis by the DTrace
|
|
46
51
|
copyinstr(arg1),
|
47
52
|
args[2])
|
48
53
|
}'
|
49
|
-
|
54
|
+
|
50
55
|
## Additional Resources
|
51
56
|
|
52
57
|
- [User-Level-Statically Defined Tracing](http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_USDT#USDT)
|
data/ext/usdt/usdt.c
CHANGED
@@ -8,7 +8,9 @@ VALUE USDT_Error;
|
|
8
8
|
|
9
9
|
static VALUE provider_create(VALUE self, VALUE name, VALUE mod);
|
10
10
|
static VALUE provider_probe(int argc, VALUE *argv, VALUE self);
|
11
|
+
static VALUE provider_remove_probe(VALUE self, VALUE probe);
|
11
12
|
static VALUE provider_enable(VALUE self);
|
13
|
+
static VALUE provider_disable(VALUE self);
|
12
14
|
static VALUE probe_enabled(VALUE self);
|
13
15
|
static VALUE probe_fire(int argc, VALUE *argv, VALUE self);
|
14
16
|
|
@@ -20,7 +22,9 @@ void Init_usdt() {
|
|
20
22
|
USDT_Provider = rb_define_class_under(USDT, "Provider", rb_cObject);
|
21
23
|
rb_define_singleton_method(USDT_Provider, "create", provider_create, 2);
|
22
24
|
rb_define_method(USDT_Provider, "probe", provider_probe, -1);
|
25
|
+
rb_define_method(USDT_Provider, "remove_probe", provider_remove_probe, 1);
|
23
26
|
rb_define_method(USDT_Provider, "enable", provider_enable, 0);
|
27
|
+
rb_define_method(USDT_Provider, "disable", provider_disable, 0);
|
24
28
|
|
25
29
|
USDT_Probe = rb_define_class_under(USDT, "Probe", rb_cObject);
|
26
30
|
rb_define_method(USDT_Probe, "enabled?", probe_enabled, 0);
|
@@ -54,12 +58,12 @@ static VALUE provider_create(VALUE self, VALUE name, VALUE mod) {
|
|
54
58
|
static VALUE provider_probe(int argc, VALUE *argv, VALUE self) {
|
55
59
|
const char *func = rb_id2name(rb_to_id(argv[0]));
|
56
60
|
const char *name = rb_id2name(rb_to_id(argv[1]));
|
57
|
-
const char *types[
|
61
|
+
const char *types[USDT_ARG_MAX];
|
58
62
|
size_t i, pargc = 0;
|
59
63
|
size_t t_int = rb_intern("integer");
|
60
64
|
size_t t_str = rb_intern("string");
|
61
65
|
|
62
|
-
for (i = 0; i <
|
66
|
+
for (i = 0; i < USDT_ARG_MAX; i++) {
|
63
67
|
if (i < argc - 2) {
|
64
68
|
Check_Type(argv[i+2], T_SYMBOL);
|
65
69
|
if (t_int == rb_to_id(argv[i+2])) {
|
@@ -82,9 +86,26 @@ static VALUE provider_probe(int argc, VALUE *argv, VALUE self) {
|
|
82
86
|
probe = ALLOC(usdt_probedef_t *);
|
83
87
|
*probe = usdt_create_probe(func, name, pargc, types);
|
84
88
|
|
85
|
-
usdt_provider_add_probe(provider, *probe)
|
86
|
-
|
87
|
-
|
89
|
+
if ((usdt_provider_add_probe(provider, *probe) == 0)) {
|
90
|
+
VALUE rbProbe = Data_Wrap_Struct(USDT_Probe, NULL, free, probe);
|
91
|
+
return rbProbe;
|
92
|
+
}
|
93
|
+
else {
|
94
|
+
rb_raise(USDT_Error, "%s", usdt_errstr(provider));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* USDT::Provider#remove_probe(probe)
|
100
|
+
*/
|
101
|
+
static VALUE provider_remove_probe(VALUE self, VALUE probe) {
|
102
|
+
usdt_provider_t *provider = DATA_PTR(self);
|
103
|
+
usdt_probedef_t **p = DATA_PTR(probe);
|
104
|
+
usdt_probedef_t *probedef = *p;
|
105
|
+
|
106
|
+
usdt_provider_remove_probe(provider, probedef);
|
107
|
+
|
108
|
+
return Qtrue;
|
88
109
|
}
|
89
110
|
|
90
111
|
/**
|
@@ -100,6 +121,19 @@ static VALUE provider_enable(VALUE self) {
|
|
100
121
|
}
|
101
122
|
}
|
102
123
|
|
124
|
+
/**
|
125
|
+
* USDT::Provider#disable
|
126
|
+
*/
|
127
|
+
static VALUE provider_disable(VALUE self) {
|
128
|
+
usdt_provider_t *provider = DATA_PTR(self);
|
129
|
+
int status = usdt_provider_disable(provider);
|
130
|
+
if (status == 0) {
|
131
|
+
return Qtrue;
|
132
|
+
} else {
|
133
|
+
rb_raise(USDT_Error, "%s", usdt_errstr(provider));
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
103
137
|
/**
|
104
138
|
* USDT::Probe#enabled?
|
105
139
|
*/
|
@@ -125,8 +159,8 @@ static VALUE probe_fire(int argc, VALUE *argv, VALUE self) {
|
|
125
159
|
usdt_probedef_t **p = DATA_PTR(self);
|
126
160
|
usdt_probedef_t *probedef = *p;
|
127
161
|
|
128
|
-
void *pargs[
|
129
|
-
|
162
|
+
void *pargs[USDT_ARG_MAX];
|
163
|
+
size_t i;
|
130
164
|
|
131
165
|
for (i = 0; i < probedef->argc; i++) {
|
132
166
|
if (probedef->types[i] == USDT_ARGTYPE_STRING) {
|
data/lib/usdt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-usdt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|