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
@@ -0,0 +1,153 @@
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 TestDtraceProvider < Test::Unit::TestCase
11
+
12
+ def test_provider_with_module
13
+ Dtrace::Provider.create :test0, { :module => 'test1module' } do |p|
14
+ p.probe :test
15
+ end
16
+
17
+ t = Dtrace.new
18
+ matches = 0
19
+ t.each_probe do |p|
20
+ if p.to_s == "test0#{$$}:test1module:test_provider_with_module:test"
21
+ matches += 1
22
+ end
23
+ end
24
+ assert_equal 1, matches
25
+ end
26
+
27
+ def test_probe_with_function_no_args
28
+ Dtrace::Provider.create :test10 do |p|
29
+ p.probe :test, { :function => :foo }
30
+ end
31
+
32
+ t = Dtrace.new
33
+ matches = 0
34
+ t.each_probe do |p|
35
+ if p.to_s == "test10#{$$}:ruby:foo:test"
36
+ matches += 1
37
+ end
38
+ end
39
+ assert_equal 1, matches
40
+ end
41
+
42
+ def test_probe_with_function_and_args
43
+ Dtrace::Provider.create :test11 do |p|
44
+ p.probe :test, { :function => :foo }, :integer, :integer
45
+ end
46
+
47
+ t = Dtrace.new
48
+ matches = 0
49
+ t.each_probe do |p|
50
+ if p.to_s == "test11#{$$}:ruby:foo:test"
51
+ matches += 1
52
+ end
53
+ end
54
+ assert_equal 1, matches
55
+ end
56
+
57
+ def test_probe_no_args
58
+ Dtrace::Provider.create :test1 do |p|
59
+ p.probe :test
60
+ end
61
+
62
+ t = Dtrace.new
63
+ matches = 0
64
+ t.each_probe do |p|
65
+ if p.to_s == "test1#{$$}:ruby:test_probe_no_args:test"
66
+ matches += 1
67
+ end
68
+ end
69
+ assert_equal 1, matches
70
+ end
71
+
72
+ def test_probe_with_char_arg
73
+ Dtrace::Provider.create :test2 do |p|
74
+ p.probe :test, :string
75
+ end
76
+
77
+ t = Dtrace.new
78
+ matches = 0
79
+ t.each_probe do |p|
80
+ if p.to_s == "test2#{$$}:ruby:test_probe_with_char_arg:test"
81
+ matches += 1
82
+ end
83
+ end
84
+ assert_equal 1, matches
85
+ end
86
+
87
+ def test_probe_with_int_arg
88
+ Dtrace::Provider.create :test3 do |p|
89
+ p.probe :test, :integer
90
+ end
91
+
92
+ t = Dtrace.new
93
+ matches = 0
94
+ t.each_probe do |p|
95
+ if p.to_s == "test3#{$$}:ruby:test_probe_with_int_arg:test"
96
+ matches += 1
97
+ end
98
+ end
99
+ assert_equal 1, matches
100
+ end
101
+
102
+ def test_probe_with_two_args
103
+ Dtrace::Provider.create :test4 do |p|
104
+ p.probe :test, :integer, :integer
105
+ end
106
+
107
+ t = Dtrace.new
108
+ matches = 0
109
+ t.each_probe do |p|
110
+ if p.to_s == "test4#{$$}:ruby:test_probe_with_two_args:test"
111
+ matches += 1
112
+ end
113
+ end
114
+ assert_equal 1, matches
115
+ end
116
+
117
+ def test_multiple_probes_with_two_args
118
+ Dtrace::Provider.create :test5 do |p|
119
+ p.probe :test1, :integer, :integer
120
+ p.probe :test2, :integer, :integer
121
+ end
122
+
123
+ t = Dtrace.new
124
+ matches = 0
125
+ t.each_probe do |p|
126
+ if p.to_s =~ /^test5#{$$}:ruby:test_multiple_probes_with_two_args:test/
127
+ matches += 1
128
+ end
129
+ end
130
+ assert_equal 2, matches
131
+ end
132
+
133
+ def test_multiple_probes
134
+ Dtrace::Provider.create :test6 do |p|
135
+ p.probe :test1, :integer
136
+ p.probe :test2, :integer
137
+ p.probe :test3, :integer
138
+ p.probe :test4, :integer
139
+ p.probe :test5, :integer
140
+ end
141
+
142
+ t = Dtrace.new
143
+ matches = 0
144
+ t.each_probe do |p|
145
+ if p.to_s =~ /^test6#{$$}:ruby:test_multiple_probes:test/
146
+ matches += 1
147
+ end
148
+ end
149
+ assert_equal 5, matches
150
+ end
151
+
152
+ end
153
+
@@ -0,0 +1,51 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2007 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'test/unit'
8
+
9
+ # Test repeatedly using DTrace in the same process. Show that we can
10
+ # reopen the DTrace handle multiple times, without explictly closing
11
+ # it (that happens in GC, so in this script that's probably right at
12
+ # the end).
13
+
14
+ class TestDtraceRepeat < Test::Unit::TestCase
15
+
16
+ def test_repeats
17
+ (0..9).each do |i|
18
+ t = Dtrace.new
19
+ t.setopt("bufsize", "4m")
20
+ t.setopt("aggsize", "4m")
21
+
22
+ progtext = 'syscall:::entry { trace("foo"); }'
23
+
24
+ prog = t.compile progtext
25
+ prog.execute
26
+ t.go
27
+
28
+ # Let some activity happen.
29
+ sleep 1
30
+
31
+ c = Dtrace::Consumer.new(t)
32
+ assert c
33
+
34
+ i = 0
35
+ c.consume do |d|
36
+ assert d
37
+ assert_not_nil d.cpu
38
+ assert_equal 'syscall', d.probe.provider
39
+ assert_not_nil d.probe.func
40
+ assert_equal 'entry', d.probe.name
41
+
42
+ d.data.each do |r|
43
+ assert_equal 'foo', r.value
44
+ end
45
+ c.finish
46
+ i = i + 1
47
+ end
48
+ assert i > 0
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2007 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'test/unit'
8
+
9
+ class TestDtrace < Test::Unit::TestCase
10
+ def test_rubyprobe
11
+ t = Dtrace.new
12
+ t.setopt("bufsize", "4m")
13
+
14
+ progtext = <<EOD
15
+ ruby*:::ruby-probe
16
+ {
17
+ trace(copyinstr(arg0));
18
+ trace(copyinstr(arg1));
19
+ }
20
+ EOD
21
+
22
+ prog = t.compile progtext
23
+ prog.execute
24
+ t.go
25
+
26
+ c = Dtrace::Consumer.new(t)
27
+
28
+ # Leopard's ruby-probe is DTracer, Solaris's is Tracer.
29
+ begin
30
+ trace_module = DTracer
31
+ rescue NameError
32
+ trace_module = Tracer
33
+ end
34
+
35
+ (0..9).each do |i|
36
+ trace_module.fire("foo", i.to_s)
37
+ end
38
+
39
+ data = []
40
+ c.consume_once do |d|
41
+ data << d
42
+ end
43
+
44
+ (0..9).each do |i|
45
+ d = data.shift
46
+ assert_equal("foo", d.data[0].value)
47
+ assert_equal(i.to_s, d.data[1].value)
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,108 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2007 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'test/unit'
8
+
9
+ # Tests for the feature allowing you to filter DtraceData types
10
+
11
+ class TestDtraceTypefilter < Test::Unit::TestCase
12
+ def test_filter
13
+ t = Dtrace.new
14
+ t.setopt("bufsize", "4m")
15
+ t.setopt("aggsize", "4m")
16
+
17
+ progtext =<<EOD
18
+ profile-1000
19
+ {
20
+ @a[execname] = count();
21
+ @b[execname] = count();
22
+ }
23
+
24
+ profile-10
25
+ {
26
+ trace("foo");
27
+ printa(@a);
28
+ printf("bar");
29
+ printa(@b);
30
+ }
31
+ EOD
32
+
33
+ prog = t.compile progtext
34
+ prog.execute
35
+ t.go
36
+
37
+ sleep 1
38
+
39
+ c = Dtrace::Consumer.new(t)
40
+ assert c
41
+
42
+ data = []
43
+ c.consume_once(Dtrace::AggregateSet) do |d|
44
+ data << d
45
+ end
46
+
47
+ assert data.length > 0
48
+ data.each do |d|
49
+ assert d
50
+ assert_equal Dtrace::Data, d.class
51
+ d.data.each do |agg|
52
+ assert_equal Dtrace::AggregateSet, agg.class
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ def test_filter_two_classes
59
+ t = Dtrace.new
60
+ t.setopt("bufsize", "4m")
61
+ t.setopt("aggsize", "4m")
62
+
63
+ progtext =<<EOD
64
+ profile-1000
65
+ {
66
+ @a[execname] = count();
67
+ @b[execname] = count();
68
+ }
69
+
70
+ profile-10
71
+ {
72
+ trace("foo");
73
+ printa(@a);
74
+ printf("bar");
75
+ printa(@b);
76
+ }
77
+ EOD
78
+
79
+ prog = t.compile progtext
80
+ prog.execute
81
+ t.go
82
+
83
+ sleep 1
84
+
85
+ c = Dtrace::Consumer.new(t)
86
+ assert c
87
+
88
+ data = []
89
+ c.consume_once(Dtrace::AggregateSet, Dtrace::PrintfRecord) do |d|
90
+ data << d
91
+ end
92
+
93
+ assert data.length > 0
94
+ data.each do |d|
95
+ assert d
96
+ assert_equal Dtrace::Data, d.class
97
+ d.data.each do |r|
98
+ if r.respond_to?(:add_aggregate)
99
+ assert_equal Dtrace::AggregateSet, r.class
100
+ else
101
+ assert_equal Dtrace::PrintfRecord, r.class
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # Ruby-Dtrace
3
+ # (c) 2007 Chris Andrews <chris@nodnol.org>
4
+ #
5
+
6
+ require 'dtrace'
7
+ require 'test/unit'
8
+
9
+ # Tests using the DTrace profile provider.
10
+
11
+ class TestLegacyConsumer < Test::Unit::TestCase
12
+ def test_aggregate_group
13
+ t = Dtrace.new
14
+ t.setopt("bufsize", "4m")
15
+ t.setopt("aggsize", "4m")
16
+
17
+ progtext =<<EOD
18
+ profile-1000
19
+ {
20
+ @a[execname] = count();
21
+ @b[execname] = count();
22
+ }
23
+
24
+ profile-1
25
+ {
26
+ printa(@a);
27
+ printa(@b);
28
+ }
29
+ EOD
30
+
31
+ prog = t.compile progtext
32
+ prog.execute
33
+ t.go
34
+
35
+ sleep 3
36
+
37
+ c = DtraceConsumer.new(t)
38
+ assert c
39
+
40
+ data = []
41
+ c.consume_once do |d|
42
+ data << d
43
+ end
44
+
45
+ assert data.length > 0
46
+ data.each do |d|
47
+ assert d
48
+ assert_equal Dtrace::Data, d.class
49
+ d.data.each do |agg|
50
+ assert_equal Dtrace::AggregateSet, agg.class
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chrisa-ruby-dtrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Andrews
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: chris@nodnol.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - examples/scsi.rb
26
+ - ext/dof
27
+ - ext/dof/constants.c
28
+ - ext/dof/dof.h
29
+ - ext/dof/dof_api.c
30
+ - ext/dof/dof_helper.c
31
+ - ext/dof/extconf.rb
32
+ - ext/dof/file.c
33
+ - ext/dof/generator.c
34
+ - ext/dof/header.c
35
+ - ext/dof/Makefile
36
+ - ext/dof/mkmf.log
37
+ - ext/dof/parser.c
38
+ - ext/dof/parser.h
39
+ - ext/dof/section.c
40
+ - ext/dtrace_aggdata.c
41
+ - ext/dtrace_api.c
42
+ - ext/dtrace_api.h
43
+ - ext/dtrace_bufdata.c
44
+ - ext/dtrace_dropdata.c
45
+ - ext/dtrace_errdata.c
46
+ - ext/dtrace_hdl.c
47
+ - ext/dtrace_probe.c
48
+ - ext/dtrace_probedata.c
49
+ - ext/dtrace_probedesc.c
50
+ - ext/dtrace_process.c
51
+ - ext/dtrace_program.c
52
+ - ext/dtrace_programinfo.c
53
+ - ext/dtrace_recdesc.c
54
+ - ext/dtrace_util.c
55
+ - ext/extconf.rb
56
+ - ext/i386-solaris2.11
57
+ - ext/i386-solaris2.11/dtrace_probe.c
58
+ - ext/i686-darwin8.10.1
59
+ - ext/i686-darwin8.10.1/dtrace_probe.c
60
+ - ext/sparc-solaris2.10
61
+ - ext/sparc-solaris2.10/dtrace_probe.c
62
+ - ext/stubs.txt
63
+ - lib/dtrace
64
+ - lib/dtrace/aggregate.rb
65
+ - lib/dtrace/aggregateset.rb
66
+ - lib/dtrace/consumer.rb
67
+ - lib/dtrace/data.rb
68
+ - lib/dtrace/dof
69
+ - lib/dtrace/dof/file.rb
70
+ - lib/dtrace/dof/section
71
+ - lib/dtrace/dof/section/strtab.rb
72
+ - lib/dtrace/dof/section.rb
73
+ - lib/dtrace/dof.rb
74
+ - lib/dtrace/printfrecord.rb
75
+ - lib/dtrace/probe.rb
76
+ - lib/dtrace/probedata.rb
77
+ - lib/dtrace/probedesc.rb
78
+ - lib/dtrace/provider
79
+ - lib/dtrace/provider/probedef.rb
80
+ - lib/dtrace/provider.rb
81
+ - lib/dtrace/record.rb
82
+ - lib/dtrace/stackrecord.rb
83
+ - lib/dtrace/tracer.rb
84
+ - lib/dtrace/version.rb
85
+ - lib/dtrace/version.rb~
86
+ - lib/dtrace.rb
87
+ - lib/dtraceconsumer.rb
88
+ - plugin/dtrace
89
+ - plugin/dtrace/bin
90
+ - plugin/dtrace/bin/dtracer.rb
91
+ - plugin/dtrace/init.rb
92
+ - plugin/dtrace/lib
93
+ - plugin/dtrace/lib/dtrace_helper.rb
94
+ - plugin/dtrace/lib/dtrace_report.rb
95
+ - plugin/dtrace/lib/dtracer.rb
96
+ - plugin/dtrace/lib/dtracer_client.rb
97
+ - plugin/dtrace/public
98
+ - plugin/dtrace/public/stylesheets
99
+ - plugin/dtrace/public/stylesheets/dtrace.css
100
+ - plugin/dtrace/Rakefile
101
+ - plugin/dtrace/README
102
+ - plugin/dtrace/scripts
103
+ - plugin/dtrace/scripts/default.d
104
+ - plugin/dtrace/scripts/rails_mysql.d
105
+ - plugin/dtrace/tasks
106
+ - plugin/dtrace/tasks/dtrace.rake
107
+ - plugin/dtrace/test
108
+ - plugin/dtrace/test/dtrace_test.rb
109
+ - plugin/dtrace/views
110
+ - plugin/dtrace/views/dtrace
111
+ - plugin/dtrace/views/dtrace/_report.rhtml
112
+ - test/apple-dof
113
+ - test/disabled_probe_effect.txt
114
+ - test/dof
115
+ - test/dof2
116
+ - test/test_disabled_probe_effect.rb
117
+ - test/test_dof_generator.rb
118
+ - test/test_dof_helper.rb
119
+ - test/test_dof_parser.rb
120
+ - test/test_dof_providers.rb
121
+ - test/test_dof_strtabs.rb
122
+ - test/test_dtrace.rb
123
+ - test/test_dtrace_aggregates.rb
124
+ - test/test_dtrace_drops_errors.rb
125
+ - test/test_dtrace_probe.rb
126
+ - test/test_dtrace_probes.rb
127
+ - test/test_dtrace_processes.rb
128
+ - test/test_dtrace_profile.rb
129
+ - test/test_dtrace_provider.rb
130
+ - test/test_dtrace_repeat.rb
131
+ - test/test_dtrace_rubyprobe.rb
132
+ - test/test_dtrace_typefilter.rb
133
+ - test/test_legacy_consumer.rb
134
+ - README.txt
135
+ - History.txt
136
+ - Manifest.txt
137
+ - Rakefile
138
+ has_rdoc: true
139
+ homepage: http://ruby-dtrace.rubyforge.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: "0"
150
+ version:
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: "0"
156
+ version:
157
+ requirements: []
158
+
159
+ rubyforge_project: ruby-dtrace
160
+ rubygems_version: 1.0.1
161
+ signing_key:
162
+ specification_version: 2
163
+ summary: ruby-dtrace is Ruby bindings for Dtrace, which lets you write D-based programs in Ruby, and add probes to your Ruby programs.
164
+ test_files: []
165
+