ruby-dtrace 0.0.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +21 -0
- data/Manifest.txt +86 -19
- data/README.txt +48 -6
- data/Rakefile +61 -20
- data/examples/scsi.rb +1 -1
- data/ext/dof/Makefile +154 -0
- data/ext/dof/constants.c +57 -0
- data/ext/dof/dof.h +56 -0
- data/ext/dof/dof_api.c +58 -0
- data/ext/dof/dof_helper.c +82 -0
- data/ext/dof/extconf.rb +4 -0
- data/ext/dof/file.c +90 -0
- data/ext/dof/generator.c +9 -0
- data/ext/dof/header.c +79 -0
- data/ext/dof/mkmf.log +10 -0
- data/ext/dof/parser.c +415 -0
- data/ext/dof/parser.h +10 -0
- data/ext/dof/section.c +312 -0
- data/ext/dtrace_aggdata.c +2 -2
- data/ext/dtrace_api.c +46 -34
- data/ext/dtrace_api.h +31 -7
- data/ext/dtrace_bufdata.c +3 -3
- data/ext/dtrace_hdl.c +66 -3
- data/ext/dtrace_probedata.c +4 -4
- data/ext/{dtrace_probe.c → dtrace_probedesc.c} +7 -7
- data/ext/extconf.rb +25 -0
- data/ext/i386-darwin/dtrace_probe.c +278 -0
- data/ext/i386-solaris/dtrace_probe.c +225 -0
- data/ext/stubs.txt +78 -0
- data/lib/dtrace.rb +34 -13
- data/lib/dtrace/aggregate.rb +40 -0
- data/lib/dtrace/aggregateset.rb +19 -0
- data/lib/dtrace/consumer.rb +174 -0
- data/lib/dtrace/data.rb +82 -0
- data/lib/dtrace/dof.rb +8 -0
- data/lib/dtrace/dof/file.rb +64 -0
- data/lib/dtrace/dof/section.rb +75 -0
- data/lib/dtrace/dof/section/strtab.rb +28 -0
- data/lib/{dtraceprintfrecord.rb → dtrace/printfrecord.rb} +4 -2
- data/lib/dtrace/probe.rb +3 -6
- data/lib/dtrace/probedata.rb +23 -0
- data/lib/dtrace/probedesc.rb +15 -0
- data/lib/dtrace/provider.rb +190 -169
- data/lib/dtrace/provider/klass.rb +33 -0
- data/lib/dtrace/provider/probedef.rb +24 -0
- data/lib/{dtracerecord.rb → dtrace/record.rb} +4 -2
- data/lib/{dtracestackrecord.rb → dtrace/stackrecord.rb} +10 -8
- data/lib/dtrace/version.rb +9 -0
- data/lib/dtraceconsumer.rb +3 -167
- data/plugin/dtrace/lib/dtracer.rb +4 -4
- data/test/apple-dof +0 -0
- data/test/disabled_probe_effect.txt +19 -0
- data/test/dof +0 -0
- data/test/dof2 +0 -0
- data/test/test_disabled_probe_effect.rb +56 -0
- data/test/test_dof_generator.rb +142 -0
- data/test/test_dof_helper.rb +106 -0
- data/test/test_dof_parser.rb +27 -0
- data/test/test_dof_providers.rb +278 -0
- data/test/test_dof_strtabs.rb +98 -0
- data/test/test_dtrace.rb +67 -1
- data/test/test_dtrace_aggregates.rb +5 -5
- data/test/test_dtrace_drops_errors.rb +5 -5
- data/test/test_dtrace_probe.rb +385 -0
- data/test/test_dtrace_probes.rb +414 -0
- data/test/test_dtrace_processes.rb +2 -2
- data/test/test_dtrace_profile.rb +12 -12
- data/test/test_dtrace_provider.rb +138 -0
- data/test/test_dtrace_repeat.rb +1 -1
- data/test/test_dtrace_rubyprobe.rb +3 -1
- data/test/test_dtrace_typefilter.rb +9 -9
- data/test/test_legacy_consumer.rb +56 -0
- metadata +112 -71
- data/lib/dtrace/provider/osx.rb +0 -25
- data/lib/dtrace/provider/solaris.rb +0 -29
- data/lib/dtraceaggregate.rb +0 -37
- data/lib/dtraceaggregateset.rb +0 -17
- data/lib/dtracedata.rb +0 -80
- data/lib/dtraceprobe.rb +0 -13
- data/lib/dtraceprobedata.rb +0 -21
- data/test/test_dynusdt.rb +0 -135
data/ext/dtrace_aggdata.c
CHANGED
@@ -96,13 +96,13 @@ VALUE dtraceaggdata_value(VALUE self)
|
|
96
96
|
case DTRACEAGG_COUNT:
|
97
97
|
if (value < 0)
|
98
98
|
rb_raise(eDtraceException, "count value is negative");
|
99
|
-
v =
|
99
|
+
v = LL2NUM(value);
|
100
100
|
break;
|
101
101
|
case DTRACEAGG_AVG:
|
102
102
|
case DTRACEAGG_MIN:
|
103
103
|
case DTRACEAGG_MAX:
|
104
104
|
case DTRACEAGG_SUM:
|
105
|
-
v =
|
105
|
+
v = LL2NUM(value);
|
106
106
|
break;
|
107
107
|
default:
|
108
108
|
v = Qnil;
|
data/ext/dtrace_api.c
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#include "dtrace_api.h"
|
6
6
|
|
7
7
|
VALUE cDtrace;
|
8
|
-
VALUE
|
8
|
+
VALUE cDtraceProbeDesc;
|
9
9
|
VALUE cDtraceProgram;
|
10
10
|
VALUE cDtraceProgramInfo;
|
11
11
|
VALUE cDtraceAggData;
|
@@ -15,42 +15,45 @@ VALUE cDtraceBufData;
|
|
15
15
|
VALUE cDtraceProcess;
|
16
16
|
VALUE cDtraceDropData;
|
17
17
|
VALUE cDtraceErrData;
|
18
|
+
VALUE cDtraceProbe;
|
18
19
|
|
19
20
|
VALUE eDtraceException;
|
20
21
|
|
21
22
|
void Init_dtrace_api() {
|
22
23
|
|
23
|
-
cDtrace = rb_define_class("Dtrace",
|
24
|
-
rb_define_method(cDtrace, "initialize",
|
25
|
-
rb_define_method(cDtrace, "
|
26
|
-
rb_define_method(cDtrace, "
|
27
|
-
rb_define_method(cDtrace, "
|
28
|
-
rb_define_method(cDtrace, "
|
29
|
-
rb_define_method(cDtrace, "
|
30
|
-
rb_define_method(cDtrace, "
|
31
|
-
rb_define_method(cDtrace, "
|
32
|
-
rb_define_method(cDtrace, "
|
33
|
-
rb_define_method(cDtrace, "
|
34
|
-
rb_define_method(cDtrace, "
|
35
|
-
rb_define_method(cDtrace, "
|
36
|
-
rb_define_method(cDtrace, "
|
37
|
-
rb_define_method(cDtrace, "
|
38
|
-
rb_define_method(cDtrace, "
|
24
|
+
cDtrace = rb_define_class("Dtrace", rb_cObject);
|
25
|
+
rb_define_method(cDtrace, "initialize", dtrace_init, 0); // in dtrace_hdl.c
|
26
|
+
rb_define_method(cDtrace, "each_probe_all", dtrace_each_probe_all, 0); // in dtrace_hdl.c
|
27
|
+
rb_define_method(cDtrace, "each_probe_match", dtrace_each_probe_match, 4); // in dtrace_hdl.c
|
28
|
+
rb_define_method(cDtrace, "each_probe_prog", dtrace_each_probe_prog, 1); // in dtrace_hdl.c
|
29
|
+
rb_define_method(cDtrace, "compile", dtrace_strcompile, -1); // in dtrace_hdl.c
|
30
|
+
rb_define_method(cDtrace, "stop", dtrace_hdl_stop, 0); // in dtrace_hdl.c
|
31
|
+
rb_define_method(cDtrace, "status", dtrace_hdl_status, 0); // in dtrace_hdl.c
|
32
|
+
rb_define_method(cDtrace, "go", dtrace_hdl_go, 0); // in dtrace_hdl.c
|
33
|
+
rb_define_method(cDtrace, "error", dtrace_hdl_error, 0); // in dtrace_hdl.c
|
34
|
+
rb_define_method(cDtrace, "setopt", dtrace_hdl_setopt, 2); // in dtrace_hdl.c
|
35
|
+
rb_define_method(cDtrace, "sleep", dtrace_hdl_sleep, 0); // in dtrace_hdl.c
|
36
|
+
rb_define_method(cDtrace, "work", dtrace_hdl_work, -1); // in dtrace_hdl.c
|
37
|
+
rb_define_method(cDtrace, "buf_consumer", dtrace_hdl_buf_consumer, 1); // in dtrace_hdl.c
|
38
|
+
rb_define_method(cDtrace, "drop_consumer", dtrace_hdl_drop_consumer, 1); // in dtrace_hdl.c
|
39
|
+
rb_define_method(cDtrace, "err_consumer", dtrace_hdl_err_consumer, 1); // in dtrace_hdl.c
|
40
|
+
rb_define_method(cDtrace, "createprocess", dtrace_hdl_createprocess, 1); // in dtrace_hdl.c
|
41
|
+
rb_define_method(cDtrace, "grabprocess", dtrace_hdl_grabprocess, 1); // in dtrace_hdl.c
|
39
42
|
rb_define_alloc_func(cDtrace, dtrace_hdl_alloc);
|
40
43
|
|
41
|
-
cDtraceProcess =
|
44
|
+
cDtraceProcess = rb_define_class_under(cDtrace, "Process", rb_cObject);
|
42
45
|
rb_define_method(cDtraceProcess, "initialize", dtrace_process_init, 0); // in dtrace_process.c
|
43
46
|
rb_define_method(cDtraceProcess, "continue", dtrace_process_continue, 0); // in dtrace_process.c
|
44
47
|
|
45
|
-
|
46
|
-
rb_define_method(
|
47
|
-
rb_define_method(
|
48
|
-
rb_define_method(
|
49
|
-
rb_define_method(
|
50
|
-
rb_define_method(
|
51
|
-
rb_define_method(
|
48
|
+
cDtraceProbeDesc = rb_define_class_under(cDtrace, "ProbeDesc", rb_cObject);
|
49
|
+
rb_define_method(cDtraceProbeDesc, "initialize", dtraceprobedesc_init, 0); // in dtrace_probedesc.c
|
50
|
+
rb_define_method(cDtraceProbeDesc, "probe_id", dtraceprobedesc_probe_id, 0); // in dtrace_probedesc.c
|
51
|
+
rb_define_method(cDtraceProbeDesc, "provider", dtraceprobedesc_provider, 0); // in dtrace_probedesc.c
|
52
|
+
rb_define_method(cDtraceProbeDesc, "mod", dtraceprobedesc_mod, 0); // in dtrace_probedesc.c
|
53
|
+
rb_define_method(cDtraceProbeDesc, "func", dtraceprobedesc_func, 0); // in dtrace_probedesc.c
|
54
|
+
rb_define_method(cDtraceProbeDesc, "name", dtraceprobedesc_name, 0); // in dtrace_probedesc.c
|
52
55
|
|
53
|
-
cDtraceProbeData =
|
56
|
+
cDtraceProbeData = rb_define_class_under(cDtrace, "ProbeData", rb_cObject);
|
54
57
|
rb_define_method(cDtraceProbeData, "initialize", dtraceprobedata_init, 0); // in dtrace_probedata.c
|
55
58
|
rb_define_method(cDtraceProbeData, "epid", dtraceprobedata_epid, 0); // in dtrace_probedata.c
|
56
59
|
rb_define_method(cDtraceProbeData, "probe", dtraceprobedata_probe, 0); // in dtrace_probedata.c
|
@@ -60,34 +63,34 @@ void Init_dtrace_api() {
|
|
60
63
|
rb_define_method(cDtraceProbeData, "flow", dtraceprobedata_flow, 0); // in dtrace_probedata.c
|
61
64
|
rb_define_method(cDtraceProbeData, "each_record", dtraceprobedata_each_record, 0); // in dtrace_probedata.c
|
62
65
|
|
63
|
-
cDtraceBufData =
|
66
|
+
cDtraceBufData = rb_define_class_under(cDtrace, "BufData", rb_cObject);
|
64
67
|
rb_define_method(cDtraceBufData, "initialize", dtracebufdata_init, 0); // in dtrace_bufdata.c
|
65
68
|
rb_define_method(cDtraceBufData, "epid", dtracebufdata_epid, 0); // in dtrace_bufdata.c
|
66
69
|
rb_define_method(cDtraceBufData, "probe", dtracebufdata_probe, 0); // in dtrace_bufdata.c
|
67
70
|
rb_define_method(cDtraceBufData, "record", dtracebufdata_record, 0); // in dtrace_bufdata.c
|
68
71
|
|
69
|
-
cDtraceProgram =
|
72
|
+
cDtraceProgram = rb_define_class_under(cDtrace, "Program", rb_cObject);
|
70
73
|
rb_define_method(cDtraceProgram, "initialize", dtraceprogram_init, 0); // in dtrace_program.c
|
71
74
|
rb_define_method(cDtraceProgram, "execute", dtraceprogram_exec, 0); // in dtrace_program.c
|
72
75
|
rb_define_method(cDtraceProgram, "info", dtraceprogram_info, 0); // in dtrace_program.c
|
73
76
|
|
74
|
-
cDtraceProgramInfo =
|
77
|
+
cDtraceProgramInfo = rb_define_class_under(cDtrace, "ProgramInfo", rb_cObject);
|
75
78
|
rb_define_method(cDtraceProgramInfo, "initialize", dtraceprograminfo_init, 0); // in dtrace_programinfo.c
|
76
79
|
rb_define_method(cDtraceProgramInfo, "aggregates_count", dtraceprograminfo_aggregates_count, 0); // in dtrace_programinfo.c
|
77
80
|
rb_define_method(cDtraceProgramInfo, "recgens_count", dtraceprograminfo_recgens_count, 0); // in dtrace_programinfo.c
|
78
81
|
rb_define_method(cDtraceProgramInfo, "matches_count", dtraceprograminfo_matches_count, 0); // in dtrace_programinfo.c
|
79
82
|
rb_define_method(cDtraceProgramInfo, "speculations_count", dtraceprograminfo_speculations_count, 0); // in dtrace_programinfo.c
|
80
83
|
|
81
|
-
cDtraceAggData =
|
84
|
+
cDtraceAggData = rb_define_class_under(cDtrace, "AggData", rb_cObject);
|
82
85
|
rb_define_method(cDtraceAggData, "initialize", dtraceaggdata_init, 0); // in dtrace_aggdata.c
|
83
86
|
rb_define_method(cDtraceAggData, "value", dtraceaggdata_value, 0); // in dtrace_aggdata.c
|
84
87
|
rb_define_method(cDtraceAggData, "aggtype", dtraceaggdata_aggtype, 0); // in dtrace_aggdata.c
|
85
88
|
|
86
|
-
cDtraceRecDesc =
|
89
|
+
cDtraceRecDesc = rb_define_class_under(cDtrace, "RecDesc", rb_cObject);
|
87
90
|
rb_define_method(cDtraceRecDesc, "initialize", dtracerecdesc_init, 0); // in dtrace_recdesc.c
|
88
91
|
rb_define_method(cDtraceRecDesc, "action", dtracerecdesc_action, 0); // in dtrace_recdesc.c
|
89
92
|
|
90
|
-
cDtraceDropData =
|
93
|
+
cDtraceDropData = rb_define_class_under(cDtrace, "DropData", rb_cObject);
|
91
94
|
rb_define_method(cDtraceDropData, "initialize", dtracedropdata_init, 0); // in dtrace_dropdata.c
|
92
95
|
rb_define_method(cDtraceDropData, "cpu", dtracedropdata_cpu, 0); // in dtrace_dropdata.c
|
93
96
|
rb_define_method(cDtraceDropData, "drops", dtracedropdata_drops, 0); // in dtrace_dropdata.c
|
@@ -95,7 +98,7 @@ void Init_dtrace_api() {
|
|
95
98
|
rb_define_method(cDtraceDropData, "msg", dtracedropdata_msg, 0); // in dtrace_dropdata.c
|
96
99
|
rb_define_method(cDtraceDropData, "kind", dtracedropdata_kind, 0); // in dtrace_dropdata.c
|
97
100
|
|
98
|
-
cDtraceErrData =
|
101
|
+
cDtraceErrData = rb_define_class_under(cDtrace, "ErrData", rb_cObject);
|
99
102
|
rb_define_method(cDtraceErrData, "initialize", dtraceerrdata_init, 0); // in dtrace_errdata.c
|
100
103
|
rb_define_method(cDtraceErrData, "cpu", dtraceerrdata_cpu, 0); // in dtrace_errdata.c
|
101
104
|
rb_define_method(cDtraceErrData, "action", dtraceerrdata_action, 0); // in dtrace_errdata.c
|
@@ -104,6 +107,15 @@ void Init_dtrace_api() {
|
|
104
107
|
rb_define_method(cDtraceErrData, "addr", dtraceerrdata_addr, 0); // in dtrace_errdata.c
|
105
108
|
rb_define_method(cDtraceErrData, "msg", dtraceerrdata_msg, 0); // in dtrace_errdata.c
|
106
109
|
|
107
|
-
|
110
|
+
cDtraceProbe = rb_define_class_under(cDtrace, "Probe", rb_cObject);
|
111
|
+
rb_define_method(cDtraceProbe, "initialize", dtraceprobe_init, 1); // in dtrace_probe.c
|
112
|
+
rb_define_method(cDtraceProbe, "addr", dtraceprobe_addr, 0); // in dtrace_probe.c
|
113
|
+
rb_define_method(cDtraceProbe, "fire", dtraceprobe_fire, -1); // in dtrace_probe.c
|
114
|
+
rb_define_method(cDtraceProbe, "is_enabled?", dtraceprobe_is_enabled, 0); // in dtrace_probe.c
|
115
|
+
rb_define_method(cDtraceProbe, "probe_offset", dtraceprobe_probe_offset, 2); // in dtrace_probe.c
|
116
|
+
rb_define_method(cDtraceProbe, "is_enabled_offset", dtraceprobe_is_enabled_offset, 1); // in dtrace_probe.c
|
117
|
+
rb_define_alloc_func(cDtraceProbe, dtraceprobe_alloc);
|
118
|
+
|
119
|
+
eDtraceException = rb_define_class_under(cDtrace, "Exception", rb_eStandardError);
|
108
120
|
}
|
109
121
|
|
data/ext/dtrace_api.h
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
* in the same directory as ruby.h, and we must avoid loading that...
|
7
7
|
*/
|
8
8
|
#include "/usr/include/dtrace.h"
|
9
|
+
|
10
|
+
/* undefine _FILE_OFFSET_BITS: we want the definition from ruby. */
|
11
|
+
#undef _FILE_OFFSET_BITS
|
12
|
+
|
9
13
|
#include "ruby.h"
|
10
14
|
|
11
15
|
/* Used to pass three Ruby VALUEs as the void *arg of dtrace_work() to
|
@@ -38,6 +42,16 @@ typedef struct dtrace_handle {
|
|
38
42
|
VALUE drop;
|
39
43
|
} dtrace_handle_t;
|
40
44
|
|
45
|
+
/* Struct wrapping a probe, a handcrafted function created to be a
|
46
|
+
probe trigger point, and its corresponding is_enabled tracepoint.
|
47
|
+
|
48
|
+
This is actually a pointer to the is_enabled function (the probe
|
49
|
+
function is after) so it's declared to take no args, and return
|
50
|
+
int. */
|
51
|
+
typedef struct dtrace_probe {
|
52
|
+
int (*func)();
|
53
|
+
} dtrace_probe_t;
|
54
|
+
|
41
55
|
/* Handle missing RARRAY_LEN etc */
|
42
56
|
#ifdef RARRAY_LEN
|
43
57
|
static inline long rb_str_len(VALUE s) {return RSTRING_LEN(s);}
|
@@ -63,7 +77,9 @@ VALUE dtraceaggdata_aggtype(VALUE self);
|
|
63
77
|
|
64
78
|
VALUE dtrace_init(VALUE self);
|
65
79
|
VALUE dtrace_hdl_alloc(VALUE klass);
|
66
|
-
VALUE
|
80
|
+
VALUE dtrace_each_probe_all(VALUE self);
|
81
|
+
VALUE dtrace_each_probe_match(VALUE self, VALUE provider, VALUE mod, VALUE func, VALUE name);
|
82
|
+
VALUE dtrace_each_probe_prog(VALUE self, VALUE program);
|
67
83
|
VALUE dtrace_strcompile(int argc, VALUE *argv, VALUE self);
|
68
84
|
VALUE dtrace_hdl_go(VALUE self);
|
69
85
|
VALUE dtrace_hdl_status(VALUE self);
|
@@ -78,12 +94,12 @@ VALUE dtrace_hdl_err_consumer(VALUE self, VALUE err_consumer_proc);
|
|
78
94
|
VALUE dtrace_hdl_createprocess(VALUE self, VALUE argv);
|
79
95
|
VALUE dtrace_hdl_grabprocess(VALUE self, VALUE pid);
|
80
96
|
|
81
|
-
VALUE
|
82
|
-
VALUE
|
83
|
-
VALUE
|
84
|
-
VALUE
|
85
|
-
VALUE
|
86
|
-
VALUE
|
97
|
+
VALUE dtraceprobedesc_init(VALUE self);
|
98
|
+
VALUE dtraceprobedesc_probe_id(VALUE self);
|
99
|
+
VALUE dtraceprobedesc_provider(VALUE self);
|
100
|
+
VALUE dtraceprobedesc_mod(VALUE self);
|
101
|
+
VALUE dtraceprobedesc_func(VALUE self);
|
102
|
+
VALUE dtraceprobedesc_name(VALUE self);
|
87
103
|
|
88
104
|
VALUE dtraceprobedata_init(VALUE self);
|
89
105
|
VALUE dtraceprobedata_epid(VALUE self);
|
@@ -126,3 +142,11 @@ VALUE dtraceerrdata_offset(VALUE self);
|
|
126
142
|
VALUE dtraceerrdata_fault(VALUE self);
|
127
143
|
VALUE dtraceerrdata_addr(VALUE self);
|
128
144
|
VALUE dtraceerrdata_msg(VALUE self);
|
145
|
+
|
146
|
+
VALUE dtraceprobe_alloc(VALUE klass);
|
147
|
+
VALUE dtraceprobe_init(VALUE self, VALUE argc);
|
148
|
+
VALUE dtraceprobe_addr(VALUE self);
|
149
|
+
VALUE dtraceprobe_fire(int argc, VALUE *argv, VALUE self);
|
150
|
+
VALUE dtraceprobe_is_enabled(VALUE self);
|
151
|
+
VALUE dtraceprobe_probe_offset(VALUE self, VALUE rfile, VALUE argc);
|
152
|
+
VALUE dtraceprobe_is_enabled_offset(VALUE self, VALUE rfile);
|
data/ext/dtrace_bufdata.c
CHANGED
@@ -93,7 +93,7 @@ VALUE dtracebufdata_record(VALUE self)
|
|
93
93
|
case DTRACEACT_PRINTF:
|
94
94
|
/* printf action, not available in probedata */
|
95
95
|
v = rb_str_new2(s);
|
96
|
-
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("
|
96
|
+
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::PrintfRecord"));
|
97
97
|
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
|
98
98
|
rb_iv_set(dtracerecord, "@value", v);
|
99
99
|
return (dtracerecord);
|
@@ -103,7 +103,7 @@ VALUE dtracebufdata_record(VALUE self)
|
|
103
103
|
case DTRACEACT_JSTACK:
|
104
104
|
/* stand-alone stack(), ustack(), or jstack() action */
|
105
105
|
v = rb_str_new2(s);
|
106
|
-
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("
|
106
|
+
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::StackRecord"));
|
107
107
|
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
|
108
108
|
rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
|
109
109
|
return (dtracerecord);
|
@@ -127,7 +127,7 @@ VALUE dtracebufdata_record(VALUE self)
|
|
127
127
|
}
|
128
128
|
|
129
129
|
if (!NIL_P(v)) {
|
130
|
-
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("
|
130
|
+
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::Record"));
|
131
131
|
rb_iv_set(dtracerecord, "@value", v);
|
132
132
|
rb_iv_set(dtracerecord, "@action", INT2FIX(act));
|
133
133
|
rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
|
data/ext/dtrace_hdl.c
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
RUBY_EXTERN VALUE eDtraceException;
|
8
8
|
|
9
9
|
RUBY_EXTERN VALUE cDtrace;
|
10
|
-
RUBY_EXTERN VALUE
|
10
|
+
RUBY_EXTERN VALUE cDtraceProbeDesc;
|
11
11
|
RUBY_EXTERN VALUE cDtraceProgram;
|
12
12
|
RUBY_EXTERN VALUE cDtraceRecDesc;
|
13
13
|
RUBY_EXTERN VALUE cDtraceProbeData;
|
@@ -93,11 +93,12 @@ VALUE dtrace_init(VALUE self)
|
|
93
93
|
return Qnil;
|
94
94
|
}
|
95
95
|
|
96
|
+
static
|
96
97
|
int _dtrace_next_probe(dtrace_hdl_t *hdl, const dtrace_probedesc_t *pdp, void *arg)
|
97
98
|
{
|
98
99
|
VALUE probe;
|
99
100
|
|
100
|
-
probe = Data_Wrap_Struct(
|
101
|
+
probe = Data_Wrap_Struct(cDtraceProbeDesc, 0, NULL, (dtrace_probedesc_t *)pdp);
|
101
102
|
|
102
103
|
rb_yield(probe);
|
103
104
|
return 0;
|
@@ -109,7 +110,7 @@ int _dtrace_next_probe(dtrace_hdl_t *hdl, const dtrace_probedesc_t *pdp, void *a
|
|
109
110
|
*
|
110
111
|
* Each probe is represented by a DtraceProbe object
|
111
112
|
*/
|
112
|
-
VALUE
|
113
|
+
VALUE dtrace_each_probe_all(VALUE self)
|
113
114
|
{
|
114
115
|
dtrace_handle_t *handle;
|
115
116
|
|
@@ -119,6 +120,68 @@ VALUE dtrace_each_probe(VALUE self)
|
|
119
120
|
return self;
|
120
121
|
}
|
121
122
|
|
123
|
+
/*
|
124
|
+
* Yields each probe found on the system, matching against a
|
125
|
+
* partial name.
|
126
|
+
* (equivalent to dtrace -l -n 'probe:::spec')
|
127
|
+
*
|
128
|
+
* Each probe is represented by a DtraceProbe object
|
129
|
+
*/
|
130
|
+
VALUE dtrace_each_probe_match(VALUE self, VALUE provider, VALUE mod, VALUE func, VALUE name)
|
131
|
+
{
|
132
|
+
dtrace_handle_t *handle;
|
133
|
+
|
134
|
+
dtrace_probedesc_t desc;
|
135
|
+
desc.dtpd_id = 0;
|
136
|
+
strcpy(desc.dtpd_provider, RSTRING(provider)->ptr);
|
137
|
+
strcpy(desc.dtpd_mod, RSTRING(mod)->ptr);
|
138
|
+
strcpy(desc.dtpd_func, RSTRING(func)->ptr);
|
139
|
+
strcpy(desc.dtpd_name, RSTRING(name)->ptr);
|
140
|
+
|
141
|
+
Data_Get_Struct(self, dtrace_handle_t, handle);
|
142
|
+
(void) dtrace_probe_iter(handle->hdl, &desc, _dtrace_next_probe, NULL);
|
143
|
+
|
144
|
+
return self;
|
145
|
+
}
|
146
|
+
|
147
|
+
static int
|
148
|
+
_dtrace_next_stmt(dtrace_hdl_t *hdl, dtrace_prog_t *program,
|
149
|
+
dtrace_stmtdesc_t *stp, dtrace_ecbdesc_t **last)
|
150
|
+
{
|
151
|
+
dtrace_ecbdesc_t *edp = stp->dtsd_ecbdesc;
|
152
|
+
|
153
|
+
if (edp == *last)
|
154
|
+
return 0;
|
155
|
+
|
156
|
+
if (dtrace_probe_iter(hdl, &edp->dted_probe, _dtrace_next_probe, NULL) != 0) {
|
157
|
+
rb_raise(eDtraceException, "failed to match %s:%s:%s:%s: %s\n",
|
158
|
+
edp->dted_probe.dtpd_provider, edp->dted_probe.dtpd_mod,
|
159
|
+
edp->dted_probe.dtpd_func, edp->dted_probe.dtpd_name,
|
160
|
+
dtrace_errmsg(hdl, dtrace_errno(hdl)));
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
*last = edp;
|
165
|
+
return 0;
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Yields each probe enabled by the given D program.
|
170
|
+
* (equivalent to dtrace -n -s program.d)
|
171
|
+
*/
|
172
|
+
VALUE dtrace_each_probe_prog(VALUE self, VALUE program)
|
173
|
+
{
|
174
|
+
dtrace_handle_t *handle;
|
175
|
+
dtrace_prog_t *prog;
|
176
|
+
dtrace_ecbdesc_t *last = NULL;
|
177
|
+
|
178
|
+
Data_Get_Struct(self, dtrace_handle_t, handle);
|
179
|
+
Data_Get_Struct(program, dtrace_prog_t, prog);
|
180
|
+
|
181
|
+
(void) dtrace_stmt_iter(handle->hdl, prog, (dtrace_stmt_f *)_dtrace_next_stmt, &last);
|
182
|
+
return Qnil;
|
183
|
+
}
|
184
|
+
|
122
185
|
/*
|
123
186
|
* Compile a D program.
|
124
187
|
*
|
data/ext/dtrace_probedata.c
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#include "dtrace_api.h"
|
6
6
|
|
7
7
|
RUBY_EXTERN VALUE eDtraceException;
|
8
|
-
RUBY_EXTERN VALUE
|
8
|
+
RUBY_EXTERN VALUE cDtraceProbeDesc;
|
9
9
|
|
10
10
|
/* :nodoc: */
|
11
11
|
VALUE dtraceprobedata_init(VALUE self)
|
@@ -117,7 +117,7 @@ VALUE dtraceprobedata_probe(VALUE self)
|
|
117
117
|
pd = data->dtpda_pdesc;
|
118
118
|
|
119
119
|
if (pd) {
|
120
|
-
dtraceprobe = Data_Wrap_Struct(
|
120
|
+
dtraceprobe = Data_Wrap_Struct(cDtraceProbeDesc, 0, NULL, (dtrace_probedesc_t *)pd);
|
121
121
|
return dtraceprobe;
|
122
122
|
}
|
123
123
|
|
@@ -246,7 +246,7 @@ VALUE dtraceprobedata_each_record(VALUE self)
|
|
246
246
|
v = INT2FIX(*((int32_t *)addr));
|
247
247
|
break;
|
248
248
|
case 8:
|
249
|
-
v =
|
249
|
+
v = LL2NUM(*((int64_t *)addr));
|
250
250
|
break;
|
251
251
|
default:
|
252
252
|
v = handle_bytedata(addr, rec->dtrd_size);
|
@@ -255,7 +255,7 @@ VALUE dtraceprobedata_each_record(VALUE self)
|
|
255
255
|
}
|
256
256
|
|
257
257
|
if (v) {
|
258
|
-
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("
|
258
|
+
dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::Record"));
|
259
259
|
rb_iv_set(dtracerecord, "@value", v);
|
260
260
|
rb_iv_set(dtracerecord, "@from", rb_str_new2("probedata"));
|
261
261
|
rb_iv_set(dtracerecord, "@index", INT2FIX(i));
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#include "dtrace_api.h"
|
6
6
|
|
7
7
|
/* :nodoc: */
|
8
|
-
VALUE
|
8
|
+
VALUE dtraceprobedesc_init(VALUE self)
|
9
9
|
{
|
10
10
|
dtrace_probedesc_t *pdp;
|
11
11
|
|
@@ -14,10 +14,10 @@ VALUE dtraceprobe_init(VALUE self)
|
|
14
14
|
}
|
15
15
|
|
16
16
|
/*
|
17
|
-
* Returns the id of the
|
17
|
+
* Returns the id of the probedesc. Corresponds to the ID displayed by
|
18
18
|
* dtrace -l
|
19
19
|
*/
|
20
|
-
VALUE
|
20
|
+
VALUE dtraceprobedesc_probe_id(VALUE self)
|
21
21
|
{
|
22
22
|
dtrace_probedesc_t *pdp;
|
23
23
|
|
@@ -28,7 +28,7 @@ VALUE dtraceprobe_probe_id(VALUE self)
|
|
28
28
|
/*
|
29
29
|
* Returns the name of the probe's provider.
|
30
30
|
*/
|
31
|
-
VALUE
|
31
|
+
VALUE dtraceprobedesc_provider(VALUE self)
|
32
32
|
{
|
33
33
|
VALUE string;
|
34
34
|
dtrace_probedesc_t *pdp;
|
@@ -41,7 +41,7 @@ VALUE dtraceprobe_provider(VALUE self)
|
|
41
41
|
/*
|
42
42
|
* Returns the name of the module where the probe is defined.
|
43
43
|
*/
|
44
|
-
VALUE
|
44
|
+
VALUE dtraceprobedesc_mod(VALUE self)
|
45
45
|
{
|
46
46
|
VALUE string;
|
47
47
|
dtrace_probedesc_t *pdp;
|
@@ -54,7 +54,7 @@ VALUE dtraceprobe_mod(VALUE self)
|
|
54
54
|
/*
|
55
55
|
* Returns the name of the function where the probe is defined.
|
56
56
|
*/
|
57
|
-
VALUE
|
57
|
+
VALUE dtraceprobedesc_func(VALUE self)
|
58
58
|
{
|
59
59
|
VALUE string;
|
60
60
|
dtrace_probedesc_t *pdp;
|
@@ -67,7 +67,7 @@ VALUE dtraceprobe_func(VALUE self)
|
|
67
67
|
/*
|
68
68
|
* Returns the name of the probe.
|
69
69
|
*/
|
70
|
-
VALUE
|
70
|
+
VALUE dtraceprobedesc_name(VALUE self)
|
71
71
|
{
|
72
72
|
VALUE string;
|
73
73
|
dtrace_probedesc_t *pdp;
|
data/ext/extconf.rb
CHANGED
@@ -1,4 +1,29 @@
|
|
1
1
|
require 'mkmf'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
def symlink(old, new)
|
5
|
+
begin
|
6
|
+
File.symlink(old, new)
|
7
|
+
rescue Errno::EEXIST
|
8
|
+
File.unlink(new)
|
9
|
+
retry
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
2
13
|
$CFLAGS += " -D_LONGLONG_TYPE -g"
|
3
14
|
have_library("dtrace", "dtrace_open")
|
15
|
+
|
16
|
+
# Update machine-dependent symlinks in the source, based on $Config::CONFIG and `uname -p`
|
17
|
+
os = Config::CONFIG['target_os']
|
18
|
+
os.gsub! /[0-9.]+$/, ''
|
19
|
+
|
20
|
+
# On OSX, this is "powerpc", even on Intel...
|
21
|
+
#cpu = Config::CONFIG['target_cpu']
|
22
|
+
cpu = `uname -p`.chomp
|
23
|
+
|
24
|
+
dir = "#{cpu}-#{os}"
|
25
|
+
symlink "#{dir}/dtrace_probe.c", "dtrace_probe.c"
|
26
|
+
|
27
|
+
# Create makefile in the usual way
|
4
28
|
create_makefile("dtrace_api")
|
29
|
+
|