chrisa-ruby-dtrace 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/History.txt +34 -0
  2. data/Manifest.txt +58 -0
  3. data/README.txt +88 -0
  4. data/Rakefile +73 -0
  5. data/examples/scsi.rb +442 -0
  6. data/ext/dof/constants.c +49 -0
  7. data/ext/dof/dof.h +55 -0
  8. data/ext/dof/dof_api.c +57 -0
  9. data/ext/dof/dof_helper.c +82 -0
  10. data/ext/dof/extconf.rb +4 -0
  11. data/ext/dof/file.c +56 -0
  12. data/ext/dof/generator.c +9 -0
  13. data/ext/dof/header.c +80 -0
  14. data/ext/dof/parser.c +415 -0
  15. data/ext/dof/parser.h +10 -0
  16. data/ext/dof/section.c +302 -0
  17. data/ext/dtrace_aggdata.c +142 -0
  18. data/ext/dtrace_api.c +119 -0
  19. data/ext/dtrace_api.h +150 -0
  20. data/ext/dtrace_bufdata.c +139 -0
  21. data/ext/dtrace_dropdata.c +131 -0
  22. data/ext/dtrace_errdata.c +110 -0
  23. data/ext/dtrace_hdl.c +577 -0
  24. data/ext/dtrace_probedata.c +267 -0
  25. data/ext/dtrace_probedesc.c +78 -0
  26. data/ext/dtrace_process.c +37 -0
  27. data/ext/dtrace_program.c +62 -0
  28. data/ext/dtrace_programinfo.c +60 -0
  29. data/ext/dtrace_recdesc.c +46 -0
  30. data/ext/dtrace_util.c +92 -0
  31. data/ext/extconf.rb +28 -0
  32. data/ext/stubs.txt +78 -0
  33. data/lib/dtrace/aggregate.rb +40 -0
  34. data/lib/dtrace/aggregateset.rb +19 -0
  35. data/lib/dtrace/consumer.rb +174 -0
  36. data/lib/dtrace/data.rb +82 -0
  37. data/lib/dtrace/dof/file.rb +63 -0
  38. data/lib/dtrace/dof/section/strtab.rb +21 -0
  39. data/lib/dtrace/dof/section.rb +69 -0
  40. data/lib/dtrace/dof.rb +8 -0
  41. data/lib/dtrace/printfrecord.rb +10 -0
  42. data/lib/dtrace/probe.rb +46 -0
  43. data/lib/dtrace/probedata.rb +23 -0
  44. data/lib/dtrace/probedesc.rb +15 -0
  45. data/lib/dtrace/provider/probedef.rb +24 -0
  46. data/lib/dtrace/provider.rb +231 -0
  47. data/lib/dtrace/record.rb +11 -0
  48. data/lib/dtrace/stackrecord.rb +31 -0
  49. data/lib/dtrace/tracer.rb +35 -0
  50. data/lib/dtrace.rb +74 -0
  51. data/lib/dtraceconsumer.rb +9 -0
  52. data/plugin/dtrace/README +81 -0
  53. data/plugin/dtrace/Rakefile +22 -0
  54. data/plugin/dtrace/bin/dtracer.rb +29 -0
  55. data/plugin/dtrace/init.rb +7 -0
  56. data/plugin/dtrace/lib/dtrace_helper.rb +2 -0
  57. data/plugin/dtrace/lib/dtrace_report.rb +67 -0
  58. data/plugin/dtrace/lib/dtracer.rb +52 -0
  59. data/plugin/dtrace/lib/dtracer_client.rb +26 -0
  60. data/plugin/dtrace/public/stylesheets/dtrace.css +48 -0
  61. data/plugin/dtrace/scripts/default.d +11 -0
  62. data/plugin/dtrace/scripts/rails_mysql.d +29 -0
  63. data/plugin/dtrace/tasks/dtrace.rake +52 -0
  64. data/plugin/dtrace/test/dtrace_test.rb +8 -0
  65. data/plugin/dtrace/views/dtrace/_report.rhtml +26 -0
  66. data/test/apple-dof +0 -0
  67. data/test/disabled_probe_effect.txt +19 -0
  68. data/test/dof +0 -0
  69. data/test/dof2 +0 -0
  70. data/test/test_disabled_probe_effect.rb +60 -0
  71. data/test/test_dof_generator.rb +142 -0
  72. data/test/test_dof_helper.rb +106 -0
  73. data/test/test_dof_parser.rb +25 -0
  74. data/test/test_dof_providers.rb +282 -0
  75. data/test/test_dof_strtabs.rb +92 -0
  76. data/test/test_dtrace.rb +111 -0
  77. data/test/test_dtrace_aggregates.rb +56 -0
  78. data/test/test_dtrace_drops_errors.rb +183 -0
  79. data/test/test_dtrace_probe.rb +383 -0
  80. data/test/test_dtrace_probes.rb +400 -0
  81. data/test/test_dtrace_processes.rb +83 -0
  82. data/test/test_dtrace_profile.rb +232 -0
  83. data/test/test_dtrace_provider.rb +153 -0
  84. data/test/test_dtrace_repeat.rb +51 -0
  85. data/test/test_dtrace_rubyprobe.rb +52 -0
  86. data/test/test_dtrace_typefilter.rb +108 -0
  87. data/test/test_legacy_consumer.rb +56 -0
  88. metadata +165 -0
data/ext/dof/section.c ADDED
@@ -0,0 +1,302 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+ #include <errno.h>
8
+ #include <string.h>
9
+
10
+ RUBY_EXTERN eDtraceDofException;
11
+
12
+ VALUE dof_generate_section_header(VALUE self) {
13
+ VALUE hdr_data;
14
+ dof_sec_t hdr;
15
+ uint32_t type;
16
+ uint64_t offset;
17
+ uint64_t size;
18
+ VALUE data;
19
+ uint32_t entsize;
20
+
21
+ memset(&hdr, 0, sizeof(hdr));
22
+ hdr.dofs_flags = FIX2INT(rb_iv_get(self, "@flags"));
23
+ hdr.dofs_type = FIX2INT(rb_iv_get(self, "@section_type"));
24
+ hdr.dofs_offset = FIX2INT(rb_iv_get(self, "@offset"));
25
+ hdr.dofs_size = FIX2INT(rb_iv_get(self, "@size"));
26
+ hdr.dofs_entsize = FIX2INT(rb_iv_get(self, "@entsize"));
27
+ hdr.dofs_align = FIX2INT(rb_iv_get(self, "@align"));
28
+
29
+ hdr_data = rb_str_new((const char *)&hdr, sizeof(hdr));
30
+ return hdr_data;
31
+ }
32
+
33
+ VALUE dof_generate_comments(VALUE self) {
34
+ VALUE dof;
35
+ VALUE comments = rb_iv_get(self, "@data");
36
+
37
+ if (NIL_P(comments) ) {
38
+ rb_raise(eDtraceDofException, "no comments in dof_generate_comments");
39
+ return Qnil;
40
+ }
41
+
42
+ Check_Type(comments, T_STRING);
43
+
44
+ dof = rb_str_new(RSTRING(comments)->ptr, RSTRING(comments)->len + 1);
45
+ return dof;
46
+ }
47
+
48
+ VALUE dof_generate_probes(VALUE self) {
49
+ VALUE dof;
50
+ VALUE probes = rb_iv_get(self, "@data");
51
+ VALUE probe;
52
+ int i;
53
+
54
+ if (NIL_P(probes) ) {
55
+ rb_raise(eDtraceDofException, "no probes in dof_generate_probes");
56
+ return Qnil;
57
+ }
58
+ Check_Type(probes, T_ARRAY);
59
+
60
+ dof = rb_str_new2("");
61
+
62
+ for (i = 0; i < rb_ary_len(probes); i++) {
63
+ probe = rb_ary_entry(probes, i);
64
+
65
+ Check_Type(probe, T_HASH);
66
+
67
+ dof_probe_t p;
68
+ memset(&p, 0, sizeof(p));
69
+
70
+ p.dofpr_addr = (uint64_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("addr"))));
71
+ p.dofpr_func = (dof_stridx_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("func"))));
72
+ p.dofpr_name = (dof_stridx_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("name"))));
73
+ p.dofpr_nargv = (dof_stridx_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("nargv"))));
74
+ p.dofpr_xargv = (dof_stridx_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("xargv"))));
75
+
76
+ p.dofpr_argidx = (uint32_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("argidx"))));
77
+ p.dofpr_offidx = (uint32_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("offidx"))));
78
+ p.dofpr_nargc = (uint8_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("nargc"))));
79
+ p.dofpr_xargc = (uint8_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("xargc"))));
80
+ p.dofpr_noffs = (uint16_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("noffs"))));
81
+ p.dofpr_enoffidx = (uint32_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("enoffidx"))));
82
+ p.dofpr_nenoffs = (uint16_t)FIX2INT(rb_hash_aref(probe, ID2SYM(rb_intern("nenoffs"))));
83
+
84
+ VALUE p_dof = rb_str_new((const char *)&p, sizeof(p));
85
+ rb_str_concat(dof, p_dof);
86
+ }
87
+
88
+ return dof;
89
+ }
90
+
91
+ VALUE dof_generate_strtab(VALUE self) {
92
+ VALUE dof;
93
+ VALUE strings = rb_iv_get(self, "@data");
94
+ VALUE string;
95
+ int i;
96
+
97
+ if (NIL_P(strings) ) {
98
+ rb_raise(eDtraceDofException, "no strings in dof_generate_strtab");
99
+ return Qnil;
100
+ }
101
+ Check_Type(strings, T_ARRAY);
102
+
103
+ dof = rb_str_new("", 0);
104
+ rb_str_concat(dof, rb_str_new("\0", 1));
105
+
106
+ for (i = 0; i < rb_ary_len(strings); i++) {
107
+ string = rb_ary_entry(strings, i);
108
+
109
+ Check_Type(string, T_STRING);
110
+
111
+ rb_str_concat(dof, rb_str_new(RSTRING(string)->ptr, RSTRING(string)->len + 1));
112
+ }
113
+
114
+ return dof;
115
+ }
116
+
117
+ VALUE dof_generate_utsname(VALUE self) {
118
+ VALUE dof;
119
+ struct utsname u;
120
+
121
+ if (uname(&u) < 0) {
122
+ rb_raise(eDtraceDofException, "uname failed: %s", strerror(errno));
123
+ return Qnil;
124
+ }
125
+
126
+ dof = rb_str_new((const char *)&u, sizeof(struct utsname));
127
+ return dof;
128
+ }
129
+
130
+ VALUE dof_generate_prargs(VALUE self) {
131
+ VALUE dof;
132
+ VALUE args = rb_iv_get(self, "@data");
133
+ VALUE rarg;
134
+ uint8_t arg;
135
+ int i;
136
+
137
+ if (NIL_P(args) ) {
138
+ rb_raise(eDtraceDofException, "no args in dof_generate_prargs");
139
+ return Qnil;
140
+ }
141
+ Check_Type(args, T_ARRAY);
142
+
143
+ dof = rb_str_new("", 0);
144
+
145
+ for (i = 0; i < rb_ary_len(args); i++) {
146
+ rarg = rb_ary_entry(args, i);
147
+ Check_Type(rarg, T_FIXNUM);
148
+ if (FIX2INT(rarg) >= 0 && FIX2INT(rarg) < 256) {
149
+ arg = FIX2INT(rarg);
150
+ rb_str_concat(dof, rb_str_new((char *)&arg, 1));
151
+ }
152
+ }
153
+
154
+ return dof;
155
+ }
156
+
157
+ VALUE dof_generate_proffs(VALUE self) {
158
+ VALUE dof;
159
+ VALUE args = rb_iv_get(self, "@data");
160
+ VALUE rarg;
161
+ uint32_t arg;
162
+ int i;
163
+
164
+ if (NIL_P(args) ) {
165
+ rb_raise(eDtraceDofException, "no args in dof_generate_proffs");
166
+ return Qnil;
167
+ }
168
+ Check_Type(args, T_ARRAY);
169
+
170
+ dof = rb_str_new("", 0);
171
+
172
+ for (i = 0; i < rb_ary_len(args); i++) {
173
+ rarg = rb_ary_entry(args, i);
174
+ Check_Type(rarg, T_FIXNUM);
175
+ arg = FIX2INT(rarg);
176
+ rb_str_concat(dof, rb_str_new((char *)&arg, 4));
177
+ }
178
+
179
+ return dof;
180
+ }
181
+
182
+ VALUE dof_generate_prenoffs(VALUE self) {
183
+ VALUE dof;
184
+ VALUE args = rb_iv_get(self, "@data");
185
+ VALUE rarg;
186
+ uint32_t arg;
187
+ int i;
188
+
189
+ if (NIL_P(args) ) {
190
+ rb_raise(eDtraceDofException, "no args in dof_generate_prenoffs");
191
+ return Qnil;
192
+ }
193
+ Check_Type(args, T_ARRAY);
194
+
195
+ dof = rb_str_new("", 0);
196
+
197
+ for (i = 0; i < rb_ary_len(args); i++) {
198
+ rarg = rb_ary_entry(args, i);
199
+ Check_Type(rarg, T_FIXNUM);
200
+ arg = FIX2INT(rarg);
201
+ rb_str_concat(dof, rb_str_new((char *)&arg, 4));
202
+ }
203
+
204
+ return dof;
205
+ }
206
+
207
+ dof_attr_t _dof_generate_dof_attr_t(VALUE data) {
208
+ dof_attr_t attr = 0;
209
+ uint8_t n = 0;
210
+ uint8_t d = 0;
211
+ uint8_t c = 0;
212
+
213
+ Check_Type(data, T_HASH);
214
+
215
+ n = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("name"))));
216
+ d = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("data"))));
217
+ c = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("class"))));
218
+
219
+ attr = DOF_ATTR(n, d, c);
220
+ return attr;
221
+ }
222
+
223
+ VALUE dof_generate_provider(VALUE self) {
224
+ VALUE dof;
225
+ VALUE provider = rb_iv_get(self, "@data");
226
+ dof_provider_t p;
227
+
228
+ if (NIL_P(provider) ) {
229
+ rb_raise(eDtraceDofException, "no data in dof_generate_provider");
230
+ return Qnil;
231
+ }
232
+ Check_Type(provider, T_HASH);
233
+
234
+ p.dofpv_strtab = (dof_secidx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("strtab"))));
235
+ p.dofpv_probes = (dof_secidx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("probes"))));
236
+ p.dofpv_prargs = (dof_secidx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("prargs"))));
237
+ p.dofpv_proffs = (dof_secidx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("proffs"))));
238
+ p.dofpv_name = (dof_stridx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("name"))));
239
+ p.dofpv_provattr = _dof_generate_dof_attr_t(rb_hash_aref(provider, ID2SYM(rb_intern("provattr"))));
240
+ p.dofpv_modattr = _dof_generate_dof_attr_t(rb_hash_aref(provider, ID2SYM(rb_intern("modattr"))));
241
+ p.dofpv_funcattr = _dof_generate_dof_attr_t(rb_hash_aref(provider, ID2SYM(rb_intern("funcattr"))));
242
+ p.dofpv_nameattr = _dof_generate_dof_attr_t(rb_hash_aref(provider, ID2SYM(rb_intern("nameattr"))));
243
+ p.dofpv_argsattr = _dof_generate_dof_attr_t(rb_hash_aref(provider, ID2SYM(rb_intern("argsattr"))));
244
+ p.dofpv_prenoffs = (dof_secidx_t)FIX2INT(rb_hash_aref(provider, ID2SYM(rb_intern("prenoffs"))));
245
+
246
+ dof = rb_str_new((const char *)&p, sizeof(p));
247
+ return dof;
248
+ }
249
+
250
+ VALUE dof_generate_reltab(VALUE self) {
251
+ VALUE dof;
252
+ VALUE relos = rb_iv_get(self, "@data");
253
+ VALUE relo;
254
+ int i;
255
+
256
+ if (NIL_P(relos) ) {
257
+ rb_raise(eDtraceDofException, "no relos in dof_generate_reltab");
258
+ return Qnil;
259
+ }
260
+ Check_Type(relos, T_ARRAY);
261
+
262
+ dof = rb_str_new2("");
263
+
264
+ for (i = 0; i < rb_ary_len(relos); i++) {
265
+ relo = rb_ary_entry(relos, i);
266
+
267
+ Check_Type(relo, T_HASH);
268
+
269
+ dof_relodesc_t r;
270
+ memset(&r, 0, sizeof(r));
271
+
272
+ r.dofr_name = (dof_stridx_t)FIX2INT(rb_hash_aref(relo, ID2SYM(rb_intern("name"))));
273
+ r.dofr_type = (uint32_t)FIX2INT(rb_hash_aref(relo, ID2SYM(rb_intern("type"))));
274
+ r.dofr_offset = (uint64_t)FIX2INT(rb_hash_aref(relo, ID2SYM(rb_intern("offset"))));
275
+ r.dofr_data = (uint64_t)FIX2INT(rb_hash_aref(relo, ID2SYM(rb_intern("data"))));
276
+
277
+ VALUE r_dof = rb_str_new((const char *)&r, sizeof(r));
278
+ rb_str_concat(dof, r_dof);
279
+ }
280
+
281
+ return dof;
282
+ }
283
+
284
+ VALUE dof_generate_relhdr(VALUE self) {
285
+ VALUE dof;
286
+ VALUE relhdr = rb_iv_get(self, "@data");
287
+ dof_relohdr_t r;
288
+
289
+ if (NIL_P(relhdr) ) {
290
+ rb_raise(eDtraceDofException, "no data in dof_generate_relhdr");
291
+ return Qnil;
292
+ }
293
+ Check_Type(relhdr, T_HASH);
294
+
295
+ r.dofr_strtab = (dof_secidx_t)FIX2INT(rb_hash_aref(relhdr, ID2SYM(rb_intern("strtab"))));
296
+ r.dofr_relsec = (dof_secidx_t)FIX2INT(rb_hash_aref(relhdr, ID2SYM(rb_intern("relsec"))));
297
+ r.dofr_tgtsec = (dof_secidx_t)FIX2INT(rb_hash_aref(relhdr, ID2SYM(rb_intern("tgtsec"))));
298
+
299
+ dof = rb_str_new((const char *)&r, sizeof(r));
300
+ return dof;
301
+ }
302
+
@@ -0,0 +1,142 @@
1
+ /* Ruby-Dtrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ RUBY_EXTERN VALUE eDtraceException;
8
+
9
+ /* :nodoc: */
10
+ VALUE dtraceaggdata_init(VALUE self)
11
+ {
12
+ dtrace_bufdata_t *data;
13
+
14
+ Data_Get_Struct(self, dtrace_bufdata_t, data);
15
+ return self;
16
+ }
17
+
18
+ /* Returns the value of this aggregate, be it the aggregation value,
19
+ or a member of an aggregation key tuple. */
20
+ VALUE dtraceaggdata_value(VALUE self)
21
+ {
22
+ dtrace_bufdata_t *bufdata;
23
+ const dtrace_aggdata_t *aggdata;
24
+ const dtrace_aggdesc_t *aggdesc;
25
+ const dtrace_recdesc_t *rec;
26
+ const char *s;
27
+ dtrace_actkind_t act = DTRACEACT_NONE;
28
+ int64_t aggid;
29
+ uint64_t normal;
30
+ caddr_t addr;
31
+ int64_t value;
32
+ VALUE v = Qnil;
33
+
34
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
35
+ aggdata = bufdata->dtbda_aggdata;
36
+ s = bufdata->dtbda_buffered;
37
+ rec = bufdata->dtbda_recdesc;
38
+
39
+ if (aggdata == NULL) {
40
+ rb_raise(eDtraceException, "null aggdata");
41
+ return Qnil;
42
+ }
43
+
44
+ aggdesc = aggdata->dtada_desc;
45
+
46
+ if (aggdesc == NULL) {
47
+ rb_raise(eDtraceException, "null aggdesc");
48
+ return Qnil;
49
+ }
50
+
51
+ aggid = *((int64_t *)(aggdata->dtada_data +
52
+ aggdesc->dtagd_rec[0].dtrd_offset));
53
+ if (aggid < 0) {
54
+ rb_raise(eDtraceException, "negative aggregation ID");
55
+ return Qnil;
56
+ }
57
+
58
+ act = rec->dtrd_action;
59
+
60
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY) {
61
+
62
+ switch (act) {
63
+ case DTRACEACT_STACK:
64
+ case DTRACEACT_USTACK:
65
+ case DTRACEACT_JSTACK:
66
+ /* todo */
67
+ break;
68
+ case DTRACEACT_USYM:
69
+ case DTRACEACT_UADDR:
70
+ case DTRACEACT_UMOD:
71
+ case DTRACEACT_SYM:
72
+ case DTRACEACT_MOD:
73
+ /* todo */
74
+ break;
75
+ default:
76
+ v = handle_bytedata((aggdata->dtada_data + rec->dtrd_offset), rec->dtrd_size);
77
+ }
78
+
79
+
80
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
81
+
82
+ normal = aggdata->dtada_normal;
83
+ addr = aggdata->dtada_data + rec->dtrd_offset;
84
+
85
+ if (act == DTRACEAGG_AVG) {
86
+ uint64_t *data = (uint64_t *)addr;
87
+ value = (data[0] ? (long long)(data[1] / normal / data[0]) : 0);
88
+ } else {
89
+ value = (*((int64_t *)addr)) / normal;
90
+ }
91
+
92
+ if (act == DTRACEAGG_QUANTIZE || act == DTRACEAGG_LQUANTIZE) {
93
+ v = Qnil; // dtj_new_distribution(data, rec, jc);
94
+ } else {
95
+ switch (act) {
96
+ case DTRACEAGG_COUNT:
97
+ if (value < 0)
98
+ rb_raise(eDtraceException, "count value is negative");
99
+ v = INT2FIX(value);
100
+ break;
101
+ case DTRACEAGG_AVG:
102
+ case DTRACEAGG_MIN:
103
+ case DTRACEAGG_MAX:
104
+ case DTRACEAGG_SUM:
105
+ v = INT2FIX(value);
106
+ break;
107
+ default:
108
+ v = Qnil;
109
+ rb_raise(eDtraceException, "unexpected aggregation action: %d", act);
110
+ }
111
+ }
112
+
113
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
114
+
115
+ v = Qnil;
116
+
117
+ }
118
+
119
+ return v;
120
+ }
121
+
122
+ /* Return the type of this DtraceAggData: tuple, value or last. Used
123
+ to form tuples and values into DtraceAggregate objects. */
124
+ VALUE dtraceaggdata_aggtype(VALUE self)
125
+ {
126
+ dtrace_bufdata_t *bufdata;
127
+ VALUE v;
128
+
129
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
130
+
131
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY)
132
+ v = rb_str_new2("tuple");
133
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL)
134
+ v = rb_str_new2("value");
135
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGLAST)
136
+ v = rb_str_new2("last");
137
+ else
138
+ v = rb_str_new2("unknown");
139
+
140
+ return v;
141
+ }
142
+
data/ext/dtrace_api.c ADDED
@@ -0,0 +1,119 @@
1
+ /* Ruby-Dtrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ VALUE cDtrace;
8
+ VALUE cDtraceProbeDesc;
9
+ VALUE cDtraceProgram;
10
+ VALUE cDtraceProgramInfo;
11
+ VALUE cDtraceAggData;
12
+ VALUE cDtraceRecDesc;
13
+ VALUE cDtraceProbeData;
14
+ VALUE cDtraceBufData;
15
+ VALUE cDtraceProcess;
16
+ VALUE cDtraceDropData;
17
+ VALUE cDtraceErrData;
18
+ VALUE cDtraceProbe;
19
+
20
+ VALUE eDtraceException;
21
+
22
+ void Init_dtrace_api() {
23
+
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", dtrace_each_probe, 0); // in dtrace_hdl.c
27
+ rb_define_method(cDtrace, "compile", dtrace_strcompile, -1); // in dtrace_hdl.c
28
+ rb_define_method(cDtrace, "stop", dtrace_hdl_stop, 0); // in dtrace_hdl.c
29
+ rb_define_method(cDtrace, "status", dtrace_hdl_status, 0); // in dtrace_hdl.c
30
+ rb_define_method(cDtrace, "go", dtrace_hdl_go, 0); // in dtrace_hdl.c
31
+ rb_define_method(cDtrace, "error", dtrace_hdl_error, 0); // in dtrace_hdl.c
32
+ rb_define_method(cDtrace, "setopt", dtrace_hdl_setopt, 2); // in dtrace_hdl.c
33
+ rb_define_method(cDtrace, "sleep", dtrace_hdl_sleep, 0); // in dtrace_hdl.c
34
+ rb_define_method(cDtrace, "work", dtrace_hdl_work, -1); // in dtrace_hdl.c
35
+ rb_define_method(cDtrace, "buf_consumer", dtrace_hdl_buf_consumer, 1); // in dtrace_hdl.c
36
+ rb_define_method(cDtrace, "drop_consumer", dtrace_hdl_drop_consumer, 1); // in dtrace_hdl.c
37
+ rb_define_method(cDtrace, "err_consumer", dtrace_hdl_err_consumer, 1); // in dtrace_hdl.c
38
+ rb_define_method(cDtrace, "createprocess", dtrace_hdl_createprocess, 1); // in dtrace_hdl.c
39
+ rb_define_method(cDtrace, "grabprocess", dtrace_hdl_grabprocess, 1); // in dtrace_hdl.c
40
+ rb_define_alloc_func(cDtrace, dtrace_hdl_alloc);
41
+
42
+ cDtraceProcess = rb_define_class_under(cDtrace, "Process", rb_cObject);
43
+ rb_define_method(cDtraceProcess, "initialize", dtrace_process_init, 0); // in dtrace_process.c
44
+ rb_define_method(cDtraceProcess, "continue", dtrace_process_continue, 0); // in dtrace_process.c
45
+
46
+ cDtraceProbeDesc = rb_define_class_under(cDtrace, "ProbeDesc", rb_cObject);
47
+ rb_define_method(cDtraceProbeDesc, "initialize", dtraceprobedesc_init, 0); // in dtrace_probedesc.c
48
+ rb_define_method(cDtraceProbeDesc, "probe_id", dtraceprobedesc_probe_id, 0); // in dtrace_probedesc.c
49
+ rb_define_method(cDtraceProbeDesc, "provider", dtraceprobedesc_provider, 0); // in dtrace_probedesc.c
50
+ rb_define_method(cDtraceProbeDesc, "mod", dtraceprobedesc_mod, 0); // in dtrace_probedesc.c
51
+ rb_define_method(cDtraceProbeDesc, "func", dtraceprobedesc_func, 0); // in dtrace_probedesc.c
52
+ rb_define_method(cDtraceProbeDesc, "name", dtraceprobedesc_name, 0); // in dtrace_probedesc.c
53
+
54
+ cDtraceProbeData = rb_define_class_under(cDtrace, "ProbeData", rb_cObject);
55
+ rb_define_method(cDtraceProbeData, "initialize", dtraceprobedata_init, 0); // in dtrace_probedata.c
56
+ rb_define_method(cDtraceProbeData, "epid", dtraceprobedata_epid, 0); // in dtrace_probedata.c
57
+ rb_define_method(cDtraceProbeData, "probe", dtraceprobedata_probe, 0); // in dtrace_probedata.c
58
+ rb_define_method(cDtraceProbeData, "cpu", dtraceprobedata_cpu, 0); // in dtrace_probedata.c
59
+ rb_define_method(cDtraceProbeData, "indent", dtraceprobedata_indent, 0); // in dtrace_probedata.c
60
+ rb_define_method(cDtraceProbeData, "prefix", dtraceprobedata_prefix, 0); // in dtrace_probedata.c
61
+ rb_define_method(cDtraceProbeData, "flow", dtraceprobedata_flow, 0); // in dtrace_probedata.c
62
+ rb_define_method(cDtraceProbeData, "each_record", dtraceprobedata_each_record, 0); // in dtrace_probedata.c
63
+
64
+ cDtraceBufData = rb_define_class_under(cDtrace, "BufData", rb_cObject);
65
+ rb_define_method(cDtraceBufData, "initialize", dtracebufdata_init, 0); // in dtrace_bufdata.c
66
+ rb_define_method(cDtraceBufData, "epid", dtracebufdata_epid, 0); // in dtrace_bufdata.c
67
+ rb_define_method(cDtraceBufData, "probe", dtracebufdata_probe, 0); // in dtrace_bufdata.c
68
+ rb_define_method(cDtraceBufData, "record", dtracebufdata_record, 0); // in dtrace_bufdata.c
69
+
70
+ cDtraceProgram = rb_define_class_under(cDtrace, "Program", rb_cObject);
71
+ rb_define_method(cDtraceProgram, "initialize", dtraceprogram_init, 0); // in dtrace_program.c
72
+ rb_define_method(cDtraceProgram, "execute", dtraceprogram_exec, 0); // in dtrace_program.c
73
+ rb_define_method(cDtraceProgram, "info", dtraceprogram_info, 0); // in dtrace_program.c
74
+
75
+ cDtraceProgramInfo = rb_define_class_under(cDtrace, "ProgramInfo", rb_cObject);
76
+ rb_define_method(cDtraceProgramInfo, "initialize", dtraceprograminfo_init, 0); // in dtrace_programinfo.c
77
+ rb_define_method(cDtraceProgramInfo, "aggregates_count", dtraceprograminfo_aggregates_count, 0); // in dtrace_programinfo.c
78
+ rb_define_method(cDtraceProgramInfo, "recgens_count", dtraceprograminfo_recgens_count, 0); // in dtrace_programinfo.c
79
+ rb_define_method(cDtraceProgramInfo, "matches_count", dtraceprograminfo_matches_count, 0); // in dtrace_programinfo.c
80
+ rb_define_method(cDtraceProgramInfo, "speculations_count", dtraceprograminfo_speculations_count, 0); // in dtrace_programinfo.c
81
+
82
+ cDtraceAggData = rb_define_class_under(cDtrace, "AggData", rb_cObject);
83
+ rb_define_method(cDtraceAggData, "initialize", dtraceaggdata_init, 0); // in dtrace_aggdata.c
84
+ rb_define_method(cDtraceAggData, "value", dtraceaggdata_value, 0); // in dtrace_aggdata.c
85
+ rb_define_method(cDtraceAggData, "aggtype", dtraceaggdata_aggtype, 0); // in dtrace_aggdata.c
86
+
87
+ cDtraceRecDesc = rb_define_class_under(cDtrace, "RecDesc", rb_cObject);
88
+ rb_define_method(cDtraceRecDesc, "initialize", dtracerecdesc_init, 0); // in dtrace_recdesc.c
89
+ rb_define_method(cDtraceRecDesc, "action", dtracerecdesc_action, 0); // in dtrace_recdesc.c
90
+
91
+ cDtraceDropData = rb_define_class_under(cDtrace, "DropData", rb_cObject);
92
+ rb_define_method(cDtraceDropData, "initialize", dtracedropdata_init, 0); // in dtrace_dropdata.c
93
+ rb_define_method(cDtraceDropData, "cpu", dtracedropdata_cpu, 0); // in dtrace_dropdata.c
94
+ rb_define_method(cDtraceDropData, "drops", dtracedropdata_drops, 0); // in dtrace_dropdata.c
95
+ rb_define_method(cDtraceDropData, "total", dtracedropdata_total, 0); // in dtrace_dropdata.c
96
+ rb_define_method(cDtraceDropData, "msg", dtracedropdata_msg, 0); // in dtrace_dropdata.c
97
+ rb_define_method(cDtraceDropData, "kind", dtracedropdata_kind, 0); // in dtrace_dropdata.c
98
+
99
+ cDtraceErrData = rb_define_class_under(cDtrace, "ErrData", rb_cObject);
100
+ rb_define_method(cDtraceErrData, "initialize", dtraceerrdata_init, 0); // in dtrace_errdata.c
101
+ rb_define_method(cDtraceErrData, "cpu", dtraceerrdata_cpu, 0); // in dtrace_errdata.c
102
+ rb_define_method(cDtraceErrData, "action", dtraceerrdata_action, 0); // in dtrace_errdata.c
103
+ rb_define_method(cDtraceErrData, "offset", dtraceerrdata_offset, 0); // in dtrace_errdata.c
104
+ rb_define_method(cDtraceErrData, "fault", dtraceerrdata_fault, 0); // in dtrace_errdata.c
105
+ rb_define_method(cDtraceErrData, "addr", dtraceerrdata_addr, 0); // in dtrace_errdata.c
106
+ rb_define_method(cDtraceErrData, "msg", dtraceerrdata_msg, 0); // in dtrace_errdata.c
107
+
108
+ cDtraceProbe = rb_define_class_under(cDtrace, "Probe", rb_cObject);
109
+ rb_define_method(cDtraceProbe, "initialize", dtraceprobe_init, 1); // in dtrace_probe.c
110
+ rb_define_method(cDtraceProbe, "addr", dtraceprobe_addr, 0); // in dtrace_probe.c
111
+ rb_define_method(cDtraceProbe, "fire", dtraceprobe_fire, -1); // in dtrace_probe.c
112
+ rb_define_method(cDtraceProbe, "is_enabled?", dtraceprobe_is_enabled, 0); // in dtrace_probe.c
113
+ rb_define_method(cDtraceProbe, "probe_offset", dtraceprobe_probe_offset, 2); // in dtrace_probe.c
114
+ rb_define_method(cDtraceProbe, "is_enabled_offset", dtraceprobe_is_enabled_offset, 1); // in dtrace_probe.c
115
+ rb_define_alloc_func(cDtraceProbe, dtraceprobe_alloc);
116
+
117
+ eDtraceException = rb_define_class_under(cDtrace, "Exception", rb_eStandardError);
118
+ }
119
+