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,106 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'dtrace/dof'
8
+ require 'test/unit'
9
+
10
+ $dof_dir = File.dirname(__FILE__)
11
+
12
+ class TestDofHelper < Test::Unit::TestCase
13
+ include Dtrace::Dof::Constants
14
+
15
+ def test_sun_dof
16
+ flunk # platform test for Solaris
17
+
18
+ dof = File.read("#{$dof_dir}/dof")
19
+ f = Dtrace::Dof::File.new
20
+ f.allocate(4096)
21
+ f << dof
22
+ Dtrace::Dof.loaddof(f, 'testmodule')
23
+
24
+ t = Dtrace.new
25
+ matches = 0
26
+ t.each_probe("test#{$$}:testmodule:main:test") do |p|
27
+ matches += 1
28
+ end
29
+ assert_equal 1, matches
30
+ end
31
+
32
+ def test_file
33
+ f = Dtrace::Dof::File.new
34
+ f.allocate(4096)
35
+
36
+ s = Dtrace::Dof::Section.new(DOF_SECT_STRTAB, 0)
37
+ s.data = ['test', 'char *', 'char *', 'main', 'test']
38
+ f.sections << s
39
+
40
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
41
+ s.data = [
42
+ {:nargv=>6,
43
+ :noffs=>1,
44
+ :xargv=>13,
45
+ :enoffidx=>0,
46
+ :argidx=>0,
47
+ :name=>1,
48
+ :nenoffs=>0,
49
+ :offidx=>0,
50
+ :addr=>0,
51
+ :nargc=>1,
52
+ :func=>20,
53
+ :xargc=>1}
54
+ ]
55
+ f.sections << s
56
+
57
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
58
+ s.data = [ 0 ]
59
+ f.sections << s
60
+
61
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
62
+ s.data = [ 36 ]
63
+ f.sections << s
64
+
65
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
66
+ s.data = [ 0 ]
67
+ f.sections << s
68
+
69
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
70
+ s.data = {
71
+ :strtab => 0,
72
+ :probes => 1,
73
+ :prargs => 2,
74
+ :proffs => 3,
75
+ :prenoffs => 4,
76
+ :name => 25,
77
+ :provattr => { :name => 5, :data => 5, :class => 5 },
78
+ :modattr => { :name => 1, :data => 1, :class => 5 },
79
+ :funcattr => { :name => 1, :data => 1, :class => 5 },
80
+ :nameattr => { :name => 5, :data => 5, :class => 5 },
81
+ :argsattr => { :name => 5, :data => 5, :class => 5 }
82
+ }
83
+ f.sections << s
84
+
85
+ s = Dtrace::Dof::Section.new(DOF_SECT_COMMENTS, 7)
86
+ s.flags = 0 # no load
87
+ s.data = "Ruby-Dtrace 0.12"
88
+ f.sections << s
89
+
90
+ s = Dtrace::Dof::Section.new(DOF_SECT_UTSNAME, 8)
91
+ s.flags = 0 # no load
92
+ f.sections << s
93
+
94
+ f.generate
95
+ Dtrace::Dof.loaddof(f, 'testmodule')
96
+
97
+ t = Dtrace.new
98
+ matches = 0
99
+ t.each_probe("test#{$$}:testmodule:main:test") do |p|
100
+ matches += 1
101
+ end
102
+ assert_equal 1, matches
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace/dof'
7
+ require 'test/unit'
8
+
9
+ $dof_dir = File.dirname(__FILE__)
10
+
11
+ # Tests for the Dtrace DOF parser
12
+
13
+ class TestDofParser < Test::Unit::TestCase
14
+
15
+ def test_parse
16
+ flunk
17
+ assert File.exists?("#{$dof_dir}/dof")
18
+ dof = Dtrace::Dof::Parser.parse(IO.read("#{$dof_dir}/dof"))
19
+ end
20
+
21
+ def test_parse_apple_dof
22
+ flunk
23
+ assert File.exists?("#{$dof_dir}/apple-dof")
24
+ dof = Dtrace::Dof::Parser.parse(IO.read("#{$dof_dir}/apple-dof"))
25
+ end
26
+
27
+ end
@@ -0,0 +1,278 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'dtrace/dof'
8
+ require 'test/unit'
9
+
10
+ class TestDofProviders < Test::Unit::TestCase
11
+ include Dtrace::Dof::Constants
12
+
13
+ def test_probe_no_args
14
+ f = Dtrace::Dof::File.new
15
+ f.allocate(4096)
16
+
17
+ s = Dtrace::Dof::Section.new(DOF_SECT_STRTAB, 0)
18
+ s.data = ['test', 'main', 'test1dof']
19
+ f.sections << s
20
+
21
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
22
+ s.data = [
23
+ {
24
+ :noffs => 1,
25
+ :enoffidx => 0,
26
+ :argidx => 0,
27
+ :name => 1,
28
+ :nenoffs => 0,
29
+ :offidx => 0,
30
+ :addr => 0,
31
+ :nargc => 0,
32
+ :func => 6,
33
+ :xargc => 0
34
+ },
35
+ ]
36
+ f.sections << s
37
+
38
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
39
+ s.data = [ 0 ]
40
+ f.sections << s
41
+
42
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
43
+ s.data = [ 36 ]
44
+ f.sections << s
45
+
46
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
47
+ s.data = [ 0 ]
48
+ f.sections << s
49
+
50
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
51
+ s.data = {
52
+ :strtab => 0,
53
+ :probes => 1,
54
+ :prargs => 2,
55
+ :proffs => 3,
56
+ :prenoffs => 4,
57
+ :name => 11,
58
+ :provattr => { :name => 5, :data => 5, :class => 5 },
59
+ :modattr => { :name => 1, :data => 1, :class => 5 },
60
+ :funcattr => { :name => 1, :data => 1, :class => 5 },
61
+ :nameattr => { :name => 5, :data => 5, :class => 5 },
62
+ :argsattr => { :name => 5, :data => 5, :class => 5 }
63
+ }
64
+ f.sections << s
65
+
66
+ f.generate
67
+ Dtrace::Dof.loaddof(f, 'testmodule')
68
+
69
+ t = Dtrace.new
70
+ matches = 0
71
+ t.each_probe("test1dof#{$$}:testmodule:main:test") do |p|
72
+ matches += 1
73
+ end
74
+ assert_equal 1, matches
75
+
76
+ end
77
+
78
+ def test_probe_with_char_arg
79
+ f = Dtrace::Dof::File.new
80
+ f.allocate(4096)
81
+
82
+ s = Dtrace::Dof::Section.new(DOF_SECT_STRTAB, 0)
83
+ s.data = ['test', 'char *', 'char *', 'main', 'test2dof']
84
+ f.sections << s
85
+
86
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
87
+ s.data = [
88
+ {
89
+ :nargv => 6,
90
+ :noffs => 1,
91
+ :xargv => 13,
92
+ :enoffidx => 0,
93
+ :argidx => 0,
94
+ :name => 1,
95
+ :nenoffs => 0,
96
+ :offidx => 0,
97
+ :addr => 0,
98
+ :nargc => 1,
99
+ :func => 20,
100
+ :xargc => 1
101
+ },
102
+ ]
103
+ f.sections << s
104
+
105
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
106
+ s.data = [ 0 ]
107
+ f.sections << s
108
+
109
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
110
+ s.data = [ 36 ]
111
+ f.sections << s
112
+
113
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
114
+ s.data = [ 0 ]
115
+ f.sections << s
116
+
117
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
118
+ s.data = {
119
+ :strtab => 0,
120
+ :probes => 1,
121
+ :prargs => 2,
122
+ :proffs => 3,
123
+ :prenoffs => 4,
124
+ :name => 25,
125
+ :provattr => { :name => 5, :data => 5, :class => 5 },
126
+ :modattr => { :name => 1, :data => 1, :class => 5 },
127
+ :funcattr => { :name => 1, :data => 1, :class => 5 },
128
+ :nameattr => { :name => 5, :data => 5, :class => 5 },
129
+ :argsattr => { :name => 5, :data => 5, :class => 5 }
130
+ }
131
+ f.sections << s
132
+
133
+ f.generate
134
+ Dtrace::Dof.loaddof(f, 'testmodule')
135
+
136
+ t = Dtrace.new
137
+ matches = 0
138
+ t.each_probe("test2dof#{$$}:testmodule:main:test") do |p|
139
+ matches += 1
140
+ end
141
+
142
+ assert_equal 1, matches
143
+ end
144
+
145
+ def test_probe_with_int_arg
146
+ f = Dtrace::Dof::File.new
147
+ f.allocate(4096)
148
+
149
+ s = Dtrace::Dof::Section.new(DOF_SECT_STRTAB, 0)
150
+ s.data = ['test', 'int', 'int', 'main', 'test3dof']
151
+ f.sections << s
152
+
153
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
154
+ s.data = [
155
+ {
156
+ :nargv => 6,
157
+ :noffs => 1,
158
+ :xargv => 10,
159
+ :enoffidx => 0,
160
+ :argidx => 0,
161
+ :name => 1,
162
+ :nenoffs => 0,
163
+ :offidx => 0,
164
+ :addr => 0,
165
+ :nargc => 1,
166
+ :func => 14,
167
+ :xargc => 1
168
+ },
169
+ ]
170
+ f.sections << s
171
+
172
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
173
+ s.data = [ 0 ]
174
+ f.sections << s
175
+
176
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
177
+ s.data = [ 36 ]
178
+ f.sections << s
179
+
180
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
181
+ s.data = [ 36 ]
182
+ f.sections << s
183
+
184
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
185
+ s.data = {
186
+ :strtab => 0,
187
+ :probes => 1,
188
+ :prargs => 2,
189
+ :proffs => 3,
190
+ :prenoffs => 4,
191
+ :name => 19,
192
+ :provattr => { :name => 5, :data => 5, :class => 5 },
193
+ :modattr => { :name => 1, :data => 1, :class => 5 },
194
+ :funcattr => { :name => 1, :data => 1, :class => 5 },
195
+ :nameattr => { :name => 5, :data => 5, :class => 5 },
196
+ :argsattr => { :name => 5, :data => 5, :class => 5 }
197
+ }
198
+ f.sections << s
199
+
200
+ f.generate
201
+ Dtrace::Dof.loaddof(f, 'testmodule')
202
+
203
+ t = Dtrace.new
204
+ matches = 0
205
+ t.each_probe("test3dof#{$$}:testmodule:main:test") do |p|
206
+ matches += 1
207
+ end
208
+ assert_equal 1, matches
209
+
210
+ end
211
+
212
+ def test_probe_is_enabled
213
+ f = Dtrace::Dof::File.new
214
+ f.allocate(4096)
215
+
216
+ s = Dtrace::Dof::Section.new(DOF_SECT_STRTAB, 0)
217
+ s.data = ['test', 'main', 'test4dof']
218
+ f.sections << s
219
+
220
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
221
+ s.data = [
222
+ {
223
+ :noffs => 1,
224
+ :enoffidx => 0,
225
+ :argidx => 0,
226
+ :name => 1,
227
+ :nenoffs => 0,
228
+ :offidx => 0,
229
+ :addr => 0,
230
+ :nargc => 0,
231
+ :func => 6,
232
+ :xargc => 0
233
+ },
234
+ ]
235
+ f.sections << s
236
+
237
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
238
+ s.data = [ 0 ]
239
+ f.sections << s
240
+
241
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
242
+ s.data = [ 36 ]
243
+ f.sections << s
244
+
245
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
246
+ s.data = [ 44 ]
247
+ f.sections << s
248
+
249
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
250
+ s.data = {
251
+ :name => 11,
252
+ :strtab => 0,
253
+ :probes => 1,
254
+ :prargs => 2,
255
+ :proffs => 3,
256
+ :prenoffs => 4,
257
+ :provattr => { :name => 5, :data => 5, :class => 5 },
258
+ :modattr => { :name => 1, :data => 1, :class => 5 },
259
+ :funcattr => { :name => 1, :data => 1, :class => 5 },
260
+ :nameattr => { :name => 5, :data => 5, :class => 5 },
261
+ :argsattr => { :name => 5, :data => 5, :class => 5 }
262
+ }
263
+ f.sections << s
264
+
265
+ f.generate
266
+ Dtrace::Dof.loaddof(f, 'testmodule')
267
+
268
+ t = Dtrace.new
269
+ matches = 0
270
+ t.each_probe("test4dof#{$$}:testmodule:main:test") do |p|
271
+ matches += 1
272
+ end
273
+ assert_equal 1, matches
274
+
275
+ end
276
+
277
+ end
278
+
@@ -0,0 +1,98 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'dtrace/dof'
8
+ require 'test/unit'
9
+
10
+ class TestDofStrtabs < Test::Unit::TestCase
11
+ include Dtrace::Dof::Constants
12
+
13
+ def test_strtab_stridxs
14
+ sec = Dtrace::Dof::Section::Strtab.new(1)
15
+ assert sec
16
+
17
+ assert_equal 1, sec.add('foo')
18
+ assert_equal 5, sec.add('bar')
19
+ assert_equal 9, sec.add('baz')
20
+ end
21
+
22
+ def test_strtab_dof
23
+ f = Dtrace::Dof::File.new
24
+ f.allocate(4096)
25
+
26
+ strtab = Dtrace::Dof::Section::Strtab.new(0)
27
+ f.sections << strtab
28
+
29
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROBES, 1)
30
+ s.data = [
31
+ {
32
+ :name => strtab.add('test'),
33
+ :func => strtab.add('main'),
34
+ :noffs => 1,
35
+ :enoffidx => 0,
36
+ :argidx => 0,
37
+ :nenoffs => 0,
38
+ :offidx => 0,
39
+ :addr => 0,
40
+ :nargc => 0,
41
+ :xargc => 0
42
+ },
43
+ ]
44
+ f.sections << s
45
+
46
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRARGS, 2)
47
+ s.data = [ 0 ]
48
+ f.sections << s
49
+
50
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROFFS, 3)
51
+ s.data = [ 36 ]
52
+ f.sections << s
53
+
54
+ s = Dtrace::Dof::Section.new(DOF_SECT_PRENOFFS, 4)
55
+ s.data = [ 36 ]
56
+ f.sections << s
57
+
58
+ s = Dtrace::Dof::Section.new(DOF_SECT_PROVIDER, 5)
59
+ s.data = {
60
+ :strtab => 0,
61
+ :probes => 1,
62
+ :prargs => 2,
63
+ :proffs => 3,
64
+ :prenoffs => 4,
65
+ :name => strtab.add('teststrtabs'),
66
+ :provattr => {
67
+ :name => DTRACE_STABILITY_EVOLVING,
68
+ :data => DTRACE_STABILITY_EVOLVING,
69
+ :class => DTRACE_STABILITY_EVOLVING
70
+ },
71
+ :modattr => {
72
+ :name => DTRACE_STABILITY_PRIVATE,
73
+ :data => DTRACE_STABILITY_PRIVATE,
74
+ :class => DTRACE_STABILITY_EVOLVING
75
+ },
76
+ :funcattr => {
77
+ :name => DTRACE_STABILITY_PRIVATE,
78
+ :data => DTRACE_STABILITY_PRIVATE,
79
+ :class => DTRACE_STABILITY_EVOLVING
80
+ },
81
+ :nameattr => {
82
+ :name => DTRACE_STABILITY_EVOLVING,
83
+ :data => DTRACE_STABILITY_EVOLVING,
84
+ :class => DTRACE_STABILITY_EVOLVING
85
+ },
86
+ :argsattr => {
87
+ :name => DTRACE_STABILITY_EVOLVING,
88
+ :data => DTRACE_STABILITY_EVOLVING,
89
+ :class => DTRACE_STABILITY_EVOLVING
90
+ },
91
+ }
92
+ f.sections << s
93
+
94
+ f.generate
95
+ Dtrace::Dof.loaddof(f, 'testmodule')
96
+ end
97
+
98
+ end