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.
Files changed (81) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +86 -19
  3. data/README.txt +48 -6
  4. data/Rakefile +61 -20
  5. data/examples/scsi.rb +1 -1
  6. data/ext/dof/Makefile +154 -0
  7. data/ext/dof/constants.c +57 -0
  8. data/ext/dof/dof.h +56 -0
  9. data/ext/dof/dof_api.c +58 -0
  10. data/ext/dof/dof_helper.c +82 -0
  11. data/ext/dof/extconf.rb +4 -0
  12. data/ext/dof/file.c +90 -0
  13. data/ext/dof/generator.c +9 -0
  14. data/ext/dof/header.c +79 -0
  15. data/ext/dof/mkmf.log +10 -0
  16. data/ext/dof/parser.c +415 -0
  17. data/ext/dof/parser.h +10 -0
  18. data/ext/dof/section.c +312 -0
  19. data/ext/dtrace_aggdata.c +2 -2
  20. data/ext/dtrace_api.c +46 -34
  21. data/ext/dtrace_api.h +31 -7
  22. data/ext/dtrace_bufdata.c +3 -3
  23. data/ext/dtrace_hdl.c +66 -3
  24. data/ext/dtrace_probedata.c +4 -4
  25. data/ext/{dtrace_probe.c → dtrace_probedesc.c} +7 -7
  26. data/ext/extconf.rb +25 -0
  27. data/ext/i386-darwin/dtrace_probe.c +278 -0
  28. data/ext/i386-solaris/dtrace_probe.c +225 -0
  29. data/ext/stubs.txt +78 -0
  30. data/lib/dtrace.rb +34 -13
  31. data/lib/dtrace/aggregate.rb +40 -0
  32. data/lib/dtrace/aggregateset.rb +19 -0
  33. data/lib/dtrace/consumer.rb +174 -0
  34. data/lib/dtrace/data.rb +82 -0
  35. data/lib/dtrace/dof.rb +8 -0
  36. data/lib/dtrace/dof/file.rb +64 -0
  37. data/lib/dtrace/dof/section.rb +75 -0
  38. data/lib/dtrace/dof/section/strtab.rb +28 -0
  39. data/lib/{dtraceprintfrecord.rb → dtrace/printfrecord.rb} +4 -2
  40. data/lib/dtrace/probe.rb +3 -6
  41. data/lib/dtrace/probedata.rb +23 -0
  42. data/lib/dtrace/probedesc.rb +15 -0
  43. data/lib/dtrace/provider.rb +190 -169
  44. data/lib/dtrace/provider/klass.rb +33 -0
  45. data/lib/dtrace/provider/probedef.rb +24 -0
  46. data/lib/{dtracerecord.rb → dtrace/record.rb} +4 -2
  47. data/lib/{dtracestackrecord.rb → dtrace/stackrecord.rb} +10 -8
  48. data/lib/dtrace/version.rb +9 -0
  49. data/lib/dtraceconsumer.rb +3 -167
  50. data/plugin/dtrace/lib/dtracer.rb +4 -4
  51. data/test/apple-dof +0 -0
  52. data/test/disabled_probe_effect.txt +19 -0
  53. data/test/dof +0 -0
  54. data/test/dof2 +0 -0
  55. data/test/test_disabled_probe_effect.rb +56 -0
  56. data/test/test_dof_generator.rb +142 -0
  57. data/test/test_dof_helper.rb +106 -0
  58. data/test/test_dof_parser.rb +27 -0
  59. data/test/test_dof_providers.rb +278 -0
  60. data/test/test_dof_strtabs.rb +98 -0
  61. data/test/test_dtrace.rb +67 -1
  62. data/test/test_dtrace_aggregates.rb +5 -5
  63. data/test/test_dtrace_drops_errors.rb +5 -5
  64. data/test/test_dtrace_probe.rb +385 -0
  65. data/test/test_dtrace_probes.rb +414 -0
  66. data/test/test_dtrace_processes.rb +2 -2
  67. data/test/test_dtrace_profile.rb +12 -12
  68. data/test/test_dtrace_provider.rb +138 -0
  69. data/test/test_dtrace_repeat.rb +1 -1
  70. data/test/test_dtrace_rubyprobe.rb +3 -1
  71. data/test/test_dtrace_typefilter.rb +9 -9
  72. data/test/test_legacy_consumer.rb +56 -0
  73. metadata +112 -71
  74. data/lib/dtrace/provider/osx.rb +0 -25
  75. data/lib/dtrace/provider/solaris.rb +0 -29
  76. data/lib/dtraceaggregate.rb +0 -37
  77. data/lib/dtraceaggregateset.rb +0 -17
  78. data/lib/dtracedata.rb +0 -80
  79. data/lib/dtraceprobe.rb +0 -13
  80. data/lib/dtraceprobedata.rb +0 -21
  81. data/test/test_dynusdt.rb +0 -135
@@ -0,0 +1,414 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'dtrace/provider'
8
+ require 'test/unit'
9
+
10
+ class TestDtraceProbes < Test::Unit::TestCase
11
+
12
+ def test_is_not_enabled
13
+ Dtrace::Provider.create :foo0 do |p|
14
+ p.probe :bar
15
+ end
16
+
17
+ data = 'not fired'
18
+ Dtrace::Probe::Foo0.bar do |p|
19
+ data = 'fired'
20
+ p.fire
21
+ end
22
+
23
+ assert_equal 'not fired', data
24
+ end
25
+
26
+ def test_probe_no_args
27
+ Dtrace::Provider.create :foo1 do |p|
28
+ p.probe :bar
29
+ end
30
+
31
+ t = Dtrace.new
32
+ t.setopt("bufsize", "4m")
33
+
34
+ progtext = <<EOD
35
+ foo1*:ruby:test_probe_no_args:bar
36
+ {
37
+ trace("fired");
38
+ }
39
+ EOD
40
+
41
+ prog = t.compile progtext
42
+ prog.execute
43
+ t.go
44
+ c = Dtrace::Consumer.new(t)
45
+
46
+ Dtrace::Probe::Foo1.bar do |p|
47
+ p.fire
48
+ end
49
+
50
+ data = []
51
+ c.consume_once do |d|
52
+ data << d
53
+ end
54
+
55
+ assert_equal 1, data.length
56
+ assert_equal 'fired', data[0].data[0].value
57
+
58
+ end
59
+
60
+ def test_probe_one_int_arg
61
+ Dtrace::Provider.create :foo2 do |p|
62
+ p.probe :bar, :integer
63
+ end
64
+
65
+ t = Dtrace.new
66
+ t.setopt("bufsize", "4m")
67
+
68
+ progtext = <<EOD
69
+ foo2*:ruby:test_probe_one_int_arg:bar
70
+ {
71
+ trace(arg0);
72
+ }
73
+ EOD
74
+
75
+ prog = t.compile progtext
76
+ prog.execute
77
+ t.go
78
+ c = Dtrace::Consumer.new(t)
79
+
80
+ Dtrace::Probe::Foo2.bar do |p|
81
+ p.fire(42)
82
+ end
83
+
84
+ data = []
85
+ c.consume_once do |d|
86
+ data << d
87
+ end
88
+
89
+ assert_equal 1, data.length
90
+ assert_equal 42, data[0].data[0].value
91
+
92
+ end
93
+
94
+ def test_multiple_probes_w_args
95
+ Dtrace::Provider.create :foo3 do |p|
96
+ p.probe :bar, :integer
97
+ p.probe :baz, :string
98
+ end
99
+
100
+ t = Dtrace.new
101
+ t.setopt("bufsize", "4m")
102
+
103
+ progtext = <<EOD
104
+ foo3*:ruby:*:bar
105
+ {
106
+ trace(arg0);
107
+ }
108
+
109
+ foo3*:ruby:*:baz
110
+ {
111
+ trace(copyinstr(arg0));
112
+ }
113
+ EOD
114
+
115
+ prog = t.compile progtext
116
+ prog.execute
117
+ t.go
118
+ c = Dtrace::Consumer.new(t)
119
+
120
+ Dtrace::Probe::Foo3.bar do |p|
121
+ p.fire(42)
122
+ end
123
+
124
+ Dtrace::Probe::Foo3.baz do |p|
125
+ p.fire('fired!')
126
+ end
127
+
128
+ data = []
129
+ c.consume_once do |d|
130
+ data << d
131
+ end
132
+
133
+ assert_equal 2, data.length
134
+ assert_equal 42, data[0].data[0].value
135
+ assert_equal 'fired!', data[1].data[0].value
136
+
137
+ end
138
+
139
+ def test_multiple_probes_w_multiple_args
140
+ Dtrace::Provider.create :foo4 do |p|
141
+ p.probe :bar, :integer, :integer
142
+ p.probe :baz, :string, :string
143
+ end
144
+
145
+ t = Dtrace.new
146
+ t.setopt("bufsize", "4m")
147
+
148
+ progtext = <<EOD
149
+ foo4*:ruby:*:bar
150
+ {
151
+ trace(arg0);
152
+ trace(arg1);
153
+ }
154
+
155
+ foo4*:ruby:*:baz
156
+ {
157
+ trace(copyinstr(arg0));
158
+ trace(copyinstr(arg1));
159
+ }
160
+ EOD
161
+
162
+ prog = t.compile progtext
163
+ prog.execute
164
+ t.go
165
+ c = Dtrace::Consumer.new(t)
166
+
167
+ Dtrace::Probe::Foo4.bar do |p|
168
+ p.fire(42, 27)
169
+ end
170
+
171
+ Dtrace::Probe::Foo4.baz do |p|
172
+ p.fire('fired!', 'again')
173
+ end
174
+
175
+ data = []
176
+ c.consume_once do |d|
177
+ data << d
178
+ end
179
+
180
+ assert_equal 2, data.length
181
+ assert_equal 42, data[0].data[0].value
182
+ assert_equal 27, data[0].data[1].value
183
+ assert_equal 'fired!', data[1].data[0].value
184
+ assert_equal 'again', data[1].data[1].value
185
+
186
+ end
187
+
188
+ def test_all_argcs
189
+ Dtrace::Provider.create :foo5 do |p|
190
+ p.probe :bar1, :integer
191
+ p.probe :bar2, :integer, :integer
192
+ p.probe :bar3, :integer, :integer, :integer
193
+ p.probe :bar4, :integer, :integer, :integer, :integer
194
+ p.probe :bar5, :integer, :integer, :integer, :integer,
195
+ :integer
196
+ p.probe :bar6, :integer, :integer, :integer, :integer,
197
+ :integer, :integer
198
+ p.probe :bar7, :integer, :integer, :integer, :integer,
199
+ :integer, :integer, :integer
200
+ p.probe :bar8, :integer, :integer, :integer, :integer,
201
+ :integer, :integer, :integer, :integer
202
+ end
203
+
204
+ t = Dtrace.new
205
+ t.setopt("bufsize", "4m")
206
+
207
+ progtext = <<EOD
208
+ foo5*:ruby:*:bar1
209
+ {
210
+ trace(arg0);
211
+
212
+ }
213
+
214
+ foo5*:ruby:*:bar2
215
+ {
216
+ trace(arg0);
217
+ trace(arg1);
218
+
219
+ }
220
+
221
+ foo5*:ruby:*:bar3
222
+ {
223
+ trace(arg0);
224
+ trace(arg1);
225
+ trace(arg2);
226
+
227
+ }
228
+
229
+ foo5*:ruby:*:bar4
230
+ {
231
+ trace(arg0);
232
+ trace(arg1);
233
+ trace(arg2);
234
+ trace(arg3);
235
+
236
+ }
237
+
238
+ foo5*:ruby:*:bar5
239
+ {
240
+ trace(arg0);
241
+ trace(arg1);
242
+ trace(arg2);
243
+ trace(arg3);
244
+ trace(arg4);
245
+ }
246
+
247
+ foo5*:ruby:*:bar6
248
+ {
249
+ trace(arg0);
250
+ trace(arg1);
251
+ trace(arg2);
252
+ trace(arg3);
253
+ trace(arg4);
254
+ trace(arg5);
255
+ }
256
+
257
+ foo5*:ruby:*:bar7
258
+ {
259
+ trace(arg0);
260
+ trace(arg1);
261
+ trace(arg2);
262
+ trace(arg3);
263
+ trace(arg4);
264
+ trace(arg5);
265
+ trace(arg6);
266
+ }
267
+
268
+ foo5*:ruby:*:bar8
269
+ {
270
+ trace(arg0);
271
+ trace(arg1);
272
+ trace(arg2);
273
+ trace(arg3);
274
+ trace(arg4);
275
+ trace(arg5);
276
+ trace(arg6);
277
+ trace(arg7);
278
+ }
279
+ EOD
280
+
281
+ prog = t.compile progtext
282
+ prog.execute
283
+ t.go
284
+ c = Dtrace::Consumer.new(t)
285
+
286
+ Dtrace::Probe::Foo5.bar1 do |p|
287
+ p.fire(11)
288
+ end
289
+ Dtrace::Probe::Foo5.bar2 do |p|
290
+ p.fire(21, 22)
291
+ end
292
+ Dtrace::Probe::Foo5.bar3 do |p|
293
+ p.fire(31, 32, 33)
294
+ end
295
+ Dtrace::Probe::Foo5.bar4 do |p|
296
+ p.fire(41, 42, 43, 44)
297
+ end
298
+ Dtrace::Probe::Foo5.bar5 do |p|
299
+ p.fire(51, 52, 53, 54, 55)
300
+ end
301
+ Dtrace::Probe::Foo5.bar6 do |p|
302
+ p.fire(61, 62, 63, 64, 65, 66)
303
+ end
304
+ Dtrace::Probe::Foo5.bar7 do |p|
305
+ p.fire(71, 72, 73, 74, 75, 76, 77)
306
+ end
307
+ Dtrace::Probe::Foo5.bar8 do |p|
308
+ p.fire(81, 82, 83, 84, 85, 86, 87, 88)
309
+ end
310
+
311
+ data = []
312
+ c.consume_once do |d|
313
+ data << d
314
+ end
315
+
316
+ assert_equal 8, data.length
317
+
318
+ assert_equal 11, data[0].data[0].value
319
+
320
+ assert_equal 21, data[1].data[0].value
321
+ assert_equal 22, data[1].data[1].value
322
+
323
+ assert_equal 31, data[2].data[0].value
324
+ assert_equal 32, data[2].data[1].value
325
+ assert_equal 33, data[2].data[2].value
326
+
327
+ assert_equal 41, data[3].data[0].value
328
+ assert_equal 42, data[3].data[1].value
329
+ assert_equal 43, data[3].data[2].value
330
+ assert_equal 44, data[3].data[3].value
331
+
332
+ assert_equal 51, data[4].data[0].value
333
+ assert_equal 52, data[4].data[1].value
334
+ assert_equal 53, data[4].data[2].value
335
+ assert_equal 54, data[4].data[3].value
336
+ assert_equal 55, data[4].data[4].value
337
+
338
+ assert_equal 61, data[5].data[0].value
339
+ assert_equal 62, data[5].data[1].value
340
+ assert_equal 63, data[5].data[2].value
341
+ assert_equal 64, data[5].data[3].value
342
+ assert_equal 65, data[5].data[4].value
343
+ assert_equal 66, data[5].data[5].value
344
+
345
+ assert_equal 71, data[6].data[0].value
346
+ assert_equal 72, data[6].data[1].value
347
+ assert_equal 73, data[6].data[2].value
348
+ assert_equal 74, data[6].data[3].value
349
+ assert_equal 75, data[6].data[4].value
350
+ assert_equal 76, data[6].data[5].value
351
+ assert_equal 77, data[6].data[6].value
352
+
353
+ assert_equal 81, data[7].data[0].value
354
+ assert_equal 82, data[7].data[1].value
355
+ assert_equal 83, data[7].data[2].value
356
+ assert_equal 84, data[7].data[3].value
357
+ assert_equal 85, data[7].data[4].value
358
+ assert_equal 86, data[7].data[5].value
359
+ assert_equal 87, data[7].data[6].value
360
+ assert_equal 88, data[7].data[7].value
361
+
362
+ end
363
+
364
+ def test_all_eight_args_chars
365
+ Dtrace::Provider.create :foo6 do |p|
366
+ p.probe :bar, :string, :string, :string, :string,
367
+ :string, :string, :string, :string
368
+ end
369
+
370
+ t = Dtrace.new
371
+ t.setopt("bufsize", "4m")
372
+
373
+ progtext = <<EOD
374
+ foo6*:ruby:*:bar
375
+ {
376
+ trace(copyinstr(arg0));
377
+ trace(copyinstr(arg1));
378
+ trace(copyinstr(arg2));
379
+ trace(copyinstr(arg3));
380
+ trace(copyinstr(arg4));
381
+ trace(copyinstr(arg5));
382
+ trace(copyinstr(arg6));
383
+ trace(copyinstr(arg7));
384
+ }
385
+ EOD
386
+
387
+ prog = t.compile progtext
388
+ prog.execute
389
+ t.go
390
+ c = Dtrace::Consumer.new(t)
391
+
392
+ Dtrace::Probe::Foo6.bar do |p|
393
+ p.fire('one', 'two', 'three', 'four',
394
+ 'five', 'six', 'seven', 'eight')
395
+ end
396
+
397
+ data = []
398
+ c.consume_once do |d|
399
+ data << d
400
+ end
401
+
402
+ assert_equal 1, data.length
403
+ assert_equal 'one', data[0].data[0].value
404
+ assert_equal 'two', data[0].data[1].value
405
+ assert_equal 'three', data[0].data[2].value
406
+ assert_equal 'four', data[0].data[3].value
407
+ assert_equal 'five', data[0].data[4].value
408
+ assert_equal 'six', data[0].data[5].value
409
+ assert_equal 'seven', data[0].data[6].value
410
+ assert_equal 'eight', data[0].data[7].value
411
+
412
+ end
413
+
414
+ end
@@ -33,7 +33,7 @@ EOD
33
33
  p.continue
34
34
 
35
35
  i = 0
36
- c = DtraceConsumer.new(t)
36
+ c = Dtrace::Consumer.new(t)
37
37
  c.consume do |d|
38
38
  assert d
39
39
  assert_equal "pid#{d.data[0].value}", d.probe.provider
@@ -72,7 +72,7 @@ EOD
72
72
  sleep 3
73
73
 
74
74
  i = 0
75
- c = DtraceConsumer.new(t)
75
+ c = Dtrace::Consumer.new(t)
76
76
  c.consume_once do |d|
77
77
  assert d
78
78
  assert_equal "pid#{pid}", d.probe.provider
@@ -22,7 +22,7 @@ class TestDtraceProfile < Test::Unit::TestCase
22
22
  t.go
23
23
  sleep 2
24
24
 
25
- c = DtraceConsumer.new(t)
25
+ c = Dtrace::Consumer.new(t)
26
26
  assert c
27
27
 
28
28
  i = 0
@@ -65,7 +65,7 @@ EOD
65
65
  t.go
66
66
  sleep 2
67
67
 
68
- c = DtraceConsumer.new(t)
68
+ c = Dtrace::Consumer.new(t)
69
69
 
70
70
  i = 0
71
71
  c.consume do |d|
@@ -74,7 +74,7 @@ EOD
74
74
  assert_equal "profile:::profile-10", d.probe.to_s
75
75
 
76
76
  d.data.each do |r|
77
- assert_equal DtraceAggregateSet, r.class
77
+ assert_equal Dtrace::AggregateSet, r.class
78
78
  r.data.each do |a|
79
79
  assert_not_nil a.value
80
80
  assert_not_nil a.tuple
@@ -107,7 +107,7 @@ EOD
107
107
  t.go
108
108
  sleep 2
109
109
 
110
- c = DtraceConsumer.new(t)
110
+ c = Dtrace::Consumer.new(t)
111
111
 
112
112
  i = 0
113
113
  c.consume do |d|
@@ -146,7 +146,7 @@ EOD
146
146
  sleep 2
147
147
 
148
148
  i = 0
149
- c = DtraceConsumer.new(t)
149
+ c = Dtrace::Consumer.new(t)
150
150
  c.consume_once do |d|
151
151
  i = i + 1
152
152
  assert d
@@ -154,7 +154,7 @@ EOD
154
154
  assert_equal "dtrace:::END", d.probe.to_s
155
155
 
156
156
  d.data.each do |r|
157
- assert_equal DtraceAggregateSet, r.class
157
+ assert_equal Dtrace::AggregateSet, r.class
158
158
  r.data.each do |a|
159
159
  assert_not_nil a.value
160
160
  assert_not_nil a.tuple
@@ -178,7 +178,7 @@ EOD
178
178
  t.go
179
179
  sleep 2
180
180
 
181
- c = DtraceConsumer.new(t)
181
+ c = Dtrace::Consumer.new(t)
182
182
  i = 0
183
183
  c.consume do |d|
184
184
  assert d
@@ -186,8 +186,8 @@ EOD
186
186
  assert_equal "profile:::profile-1", d.probe.to_s
187
187
 
188
188
  assert_equal 2, d.data.length
189
- assert_equal DtraceRecord, d.data[0].class
190
- assert_equal DtraceStackRecord, d.data[1].class
189
+ assert_equal Dtrace::Record, d.data[0].class
190
+ assert_equal Dtrace::StackRecord, d.data[1].class
191
191
 
192
192
  i = i + 1
193
193
  if i > 10
@@ -210,7 +210,7 @@ EOD
210
210
  t.go
211
211
  sleep 2
212
212
 
213
- c = DtraceConsumer.new(t)
213
+ c = Dtrace::Consumer.new(t)
214
214
  i = 0
215
215
  c.consume do |d|
216
216
  assert d
@@ -218,8 +218,8 @@ EOD
218
218
  assert_equal "profile:::profile-1", d.probe.to_s
219
219
 
220
220
  assert_equal 2, d.data.length
221
- assert_equal DtraceRecord, d.data[0].class
222
- assert_equal DtraceStackRecord, d.data[1].class
221
+ assert_equal Dtrace::Record, d.data[0].class
222
+ assert_equal Dtrace::StackRecord, d.data[1].class
223
223
 
224
224
  i = i + 1
225
225
  if i > 10