ruby-static-tracing 0.0.2 → 0.0.3
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.
- checksums.yaml +5 -5
- data/ext/ruby-static-tracing/darwin/provider.c +128 -0
- data/ext/ruby-static-tracing/darwin/provider.h +62 -0
- data/ext/ruby-static-tracing/darwin/ruby_static_tracing.c +48 -0
- data/ext/ruby-static-tracing/darwin/tracepoint.c +231 -0
- data/ext/ruby-static-tracing/darwin/tracepoint.h +52 -0
- data/ext/ruby-static-tracing/extconf.rb +45 -5
- data/ext/ruby-static-tracing/{linux → include}/ruby_static_tracing.h +3 -6
- data/ext/ruby-static-tracing/lib/deps-extconf.rb +47 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/example/demo.c +42 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c +41 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h +34 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.c +30 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.h +8 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c +27 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h +3 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c +208 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h +66 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c +176 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h +46 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/section.c +30 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/section.h +21 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c +563 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h +46 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c +67 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h +28 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/util.c +12 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/src/util.h +6 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c +77 -0
- data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c +25 -0
- data/ext/ruby-static-tracing/lib/post-extconf.rb +37 -0
- data/ext/ruby-static-tracing/linux/provider.c +1 -1
- data/ext/ruby-static-tracing/linux/provider.h +2 -7
- data/ext/ruby-static-tracing/linux/ruby_static_tracing.c +4 -3
- data/ext/ruby-static-tracing/linux/tracepoint.c +0 -1
- data/ext/ruby-static-tracing/linux/tracepoint.h +1 -5
- data/ext/ruby-static-tracing/linux/types.h +11 -0
- data/lib/ruby-static-tracing.rb +5 -7
- data/lib/ruby-static-tracing/platform.rb +48 -0
- data/lib/ruby-static-tracing/provider.rb +18 -1
- data/lib/ruby-static-tracing/tracepoint.rb +15 -3
- data/lib/ruby-static-tracing/tracepoints.rb +36 -0
- data/lib/ruby-static-tracing/tracers.rb +1 -0
- data/lib/ruby-static-tracing/tracers/base.rb +68 -0
- data/lib/ruby-static-tracing/tracers/helpers.rb +17 -0
- data/lib/ruby-static-tracing/tracers/latency_tracer.rb +13 -60
- data/lib/ruby-static-tracing/tracers/stack_tracer.rb +19 -0
- data/lib/ruby-static-tracing/version.rb +1 -1
- metadata +41 -5
@@ -16,6 +16,22 @@ module StaticTracing
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def enable!
|
20
|
+
providers.values.each do |provider|
|
21
|
+
provider.enable
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def disable!
|
26
|
+
providers.values.each do |provider|
|
27
|
+
provider.disable
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def clean
|
32
|
+
@providers = {}
|
33
|
+
end
|
34
|
+
|
19
35
|
private
|
20
36
|
|
21
37
|
def providers
|
@@ -26,7 +42,8 @@ module StaticTracing
|
|
26
42
|
attr_reader :namespace
|
27
43
|
|
28
44
|
def initialize(namespace)
|
29
|
-
if StaticTracing::Platform.linux?
|
45
|
+
if StaticTracing::Platform.linux? ||
|
46
|
+
StaticTracing::Platform.darwin?
|
30
47
|
provider_initialize(namespace)
|
31
48
|
else
|
32
49
|
StaticTracing.issue_disabled_tracepoints_warning
|
@@ -3,7 +3,17 @@
|
|
3
3
|
module StaticTracing
|
4
4
|
class Tracepoint #:nodoc:
|
5
5
|
|
6
|
-
class InvalidArgumentError < StandardError
|
6
|
+
class InvalidArgumentError < StandardError
|
7
|
+
def initialize(argument, expected_type)
|
8
|
+
error_message = <<~ERROR_MESSAGE
|
9
|
+
|
10
|
+
We expected the fire arguments to match with the ones specified on the creation of the Tracepoint
|
11
|
+
|
12
|
+
You passed #{argument} => #{argument.class} and we expected the argument to be type #{expected_type}
|
13
|
+
ERROR_MESSAGE
|
14
|
+
super(error_message)
|
15
|
+
end
|
16
|
+
end
|
7
17
|
class InvalidArgType < StandardError; end
|
8
18
|
|
9
19
|
VALID_ARGS_TYPES = [Integer, String]
|
@@ -16,7 +26,8 @@ module StaticTracing
|
|
16
26
|
validate_args(args)
|
17
27
|
@args = args
|
18
28
|
|
19
|
-
if StaticTracing::Platform.linux?
|
29
|
+
if StaticTracing::Platform.linux? ||
|
30
|
+
StaticTracing::Platform.darwin?
|
20
31
|
tracepoint_initialize(provider, name, args)
|
21
32
|
else
|
22
33
|
StaticTracing.issue_disabled_tracepoints_warning
|
@@ -25,8 +36,9 @@ module StaticTracing
|
|
25
36
|
|
26
37
|
def fire(*values)
|
27
38
|
values.each_with_index do |arg, i|
|
28
|
-
raise InvalidArgumentError unless arg.is_a?(args[i])
|
39
|
+
raise InvalidArgumentError.new(arg, args[i]) unless arg.is_a?(args[i])
|
29
40
|
end
|
41
|
+
_fire_tracepoint(values)
|
30
42
|
end
|
31
43
|
|
32
44
|
def enabled?
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StaticTracing
|
4
|
+
class Tracepoints
|
5
|
+
class ProviderMissingError < StandardError; end
|
6
|
+
class TracepointMissingError < StandardError; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def add(provider, name, data_types)
|
10
|
+
tracepoints[provider][name.to_s] ||= begin
|
11
|
+
StaticTracing::Tracepoint.new(provider, name.to_s, *data_types)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(provider, name)
|
16
|
+
tracepoints
|
17
|
+
.fetch(provider) { raise_error(ProviderMissingError) }
|
18
|
+
.fetch(name) { raise_error(TracepointMissingError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def clean
|
22
|
+
@tracepoints ||= Hash.new { |hash, key| hash[key] = {} }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def tracepoints
|
28
|
+
@tracepoints ||= Hash.new { |hash, key| hash[key] = {} }
|
29
|
+
end
|
30
|
+
|
31
|
+
def raise_error(error)
|
32
|
+
raise error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'unmixer'
|
2
|
+
using Unmixer
|
3
|
+
|
4
|
+
require 'ruby-static-tracing/tracers/helpers'
|
5
|
+
|
6
|
+
module StaticTracing
|
7
|
+
module Tracers
|
8
|
+
class Base
|
9
|
+
class << self
|
10
|
+
include Tracers::Helpers
|
11
|
+
|
12
|
+
def register(klass, *method_names, provider: nil)
|
13
|
+
provider ||= underscore(klass.name)
|
14
|
+
method_overrides = function_wrapper.new(provider, @wrapping_function, @data_types)
|
15
|
+
modified_classes[klass] ||= method_overrides
|
16
|
+
modified_classes[klass].add_override(method_names.flatten)
|
17
|
+
end
|
18
|
+
|
19
|
+
def enable!
|
20
|
+
modified_classes.each do |klass, wrapped_methods|
|
21
|
+
klass.prepend(wrapped_methods)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def disable!
|
26
|
+
modified_classes.each do |klass, wrapped_methods|
|
27
|
+
klass.instance_eval { unprepend(wrapped_methods) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def function_wrapper
|
34
|
+
Class.new(Module) do
|
35
|
+
def initialize(provider, wrapping_function, data_types)
|
36
|
+
@provider = provider
|
37
|
+
@wrapping_function = wrapping_function
|
38
|
+
@data_types = data_types
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_override(methods)
|
42
|
+
methods.each do |method|
|
43
|
+
Tracepoints.add(@provider, method, @data_types)
|
44
|
+
define_method(method.to_s, @wrapping_function)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def modified_classes
|
51
|
+
@modified_classes ||= {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_tracepoint_data_types(*args)
|
55
|
+
@data_types = *args
|
56
|
+
end
|
57
|
+
|
58
|
+
def tracepoint_data_types
|
59
|
+
@data_types
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_wrapping_function(callable)
|
63
|
+
@wrapping_function = callable
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module StaticTracing
|
2
|
+
module Tracers
|
3
|
+
module Helpers
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def underscore(class_name)
|
7
|
+
class_name.gsub(/::/, '_').
|
8
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
9
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
10
|
+
tr("-", "_").
|
11
|
+
downcase
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
@@ -1,67 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require '
|
3
|
-
|
4
|
-
using Unmixer
|
2
|
+
require 'ruby-static-tracing/tracers/base'
|
5
3
|
|
6
4
|
module StaticTracing
|
7
5
|
module Tracers
|
8
|
-
class LatencyTracer
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class << self
|
24
|
-
def register(klass, method_names, provider: nil)
|
25
|
-
provider ||= underscore(klass.name)
|
26
|
-
latency_module = LatencyModuleGenerator.new(provider, Array(method_names))
|
27
|
-
modified_classes[klass] = latency_module
|
28
|
-
end
|
29
|
-
|
30
|
-
def enable!
|
31
|
-
modified_classes.each do |klass, latency_module|
|
32
|
-
klass.prepend latency_module
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def disable!
|
37
|
-
modified_classes.each do |klass, latency_module|
|
38
|
-
klass.instance_eval { unprepend latency_module }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def fire_tracepoint(provider, name, duration)
|
43
|
-
return
|
44
|
-
tracepoint(provider, name).fire(name, duration)
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def tracepoint(provider, name)
|
50
|
-
@tracepoints[name] ||= StaticTracing::Tracepoint.new(provider, name, String, Interger)
|
51
|
-
end
|
52
|
-
|
53
|
-
def modified_classes
|
54
|
-
@modified_classes ||= {}
|
55
|
-
end
|
56
|
-
|
57
|
-
def underscore(class_name)
|
58
|
-
class_name.gsub(/::/, '_').
|
59
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
60
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
61
|
-
tr("-", "_").
|
62
|
-
downcase
|
63
|
-
end
|
64
|
-
end
|
6
|
+
class LatencyTracer < Base
|
7
|
+
set_wrapping_function -> (*args, &block) {
|
8
|
+
start_time = StaticTracing.nsec
|
9
|
+
result = super(*args, &block)
|
10
|
+
duration = StaticTracing.nsec - start_time
|
11
|
+
method_name = __method__.to_s
|
12
|
+
provider = Tracers::Helpers.underscore(self.class.name)
|
13
|
+
Tracepoints.get(provider, method_name).fire(method_name, duration)
|
14
|
+
result
|
15
|
+
}
|
16
|
+
|
17
|
+
set_tracepoint_data_types(String, Integer)
|
65
18
|
end
|
66
19
|
end
|
67
20
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby-static-tracing/tracers/base'
|
4
|
+
|
5
|
+
module StaticTracing
|
6
|
+
module Tracers
|
7
|
+
class StackTracer < Base
|
8
|
+
set_wrapping_function -> (*args, &block) {
|
9
|
+
current_stack = self.send(:caller).join("\n")
|
10
|
+
method_name = __method__.to_s
|
11
|
+
provider = Tracers::Helpers.underscore(self.class.name)
|
12
|
+
Tracepoints.get(provider, method_name).fire(method_name, current_stack)
|
13
|
+
super(*args, &block)
|
14
|
+
}
|
15
|
+
|
16
|
+
set_tracepoint_data_types(String, String)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-static-tracing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -85,30 +85,66 @@ description: " A Ruby C extension that enables defining static tracepoints\n
|
|
85
85
|
email: dale.hamel@srvthe.net
|
86
86
|
executables: []
|
87
87
|
extensions:
|
88
|
+
- ext/ruby-static-tracing/lib/deps-extconf.rb
|
88
89
|
- ext/ruby-static-tracing/extconf.rb
|
90
|
+
- ext/ruby-static-tracing/lib/post-extconf.rb
|
89
91
|
extra_rdoc_files: []
|
90
92
|
files:
|
93
|
+
- ext/ruby-static-tracing/darwin/provider.c
|
94
|
+
- ext/ruby-static-tracing/darwin/provider.h
|
95
|
+
- ext/ruby-static-tracing/darwin/ruby_static_tracing.c
|
96
|
+
- ext/ruby-static-tracing/darwin/tracepoint.c
|
97
|
+
- ext/ruby-static-tracing/darwin/tracepoint.h
|
91
98
|
- ext/ruby-static-tracing/extconf.rb
|
99
|
+
- ext/ruby-static-tracing/include/ruby_static_tracing.h
|
100
|
+
- ext/ruby-static-tracing/lib/deps-extconf.rb
|
101
|
+
- ext/ruby-static-tracing/lib/libstapsdt/example/demo.c
|
102
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c
|
103
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h
|
104
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/errors.c
|
105
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/errors.h
|
106
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c
|
107
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h
|
108
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c
|
109
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h
|
110
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c
|
111
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h
|
112
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/section.c
|
113
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/section.h
|
114
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c
|
115
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h
|
116
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c
|
117
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h
|
118
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/util.c
|
119
|
+
- ext/ruby-static-tracing/lib/libstapsdt/src/util.h
|
120
|
+
- ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c
|
121
|
+
- ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c
|
122
|
+
- ext/ruby-static-tracing/lib/post-extconf.rb
|
92
123
|
- ext/ruby-static-tracing/linux/provider.c
|
93
124
|
- ext/ruby-static-tracing/linux/provider.h
|
94
125
|
- ext/ruby-static-tracing/linux/ruby_static_tracing.c
|
95
|
-
- ext/ruby-static-tracing/linux/ruby_static_tracing.h
|
96
126
|
- ext/ruby-static-tracing/linux/tracepoint.c
|
97
127
|
- ext/ruby-static-tracing/linux/tracepoint.h
|
128
|
+
- ext/ruby-static-tracing/linux/types.h
|
98
129
|
- lib/ruby-static-tracing.rb
|
99
130
|
- lib/ruby-static-tracing/configuration.rb
|
100
131
|
- lib/ruby-static-tracing/platform.rb
|
101
132
|
- lib/ruby-static-tracing/provider.rb
|
102
133
|
- lib/ruby-static-tracing/tracepoint.rb
|
134
|
+
- lib/ruby-static-tracing/tracepoints.rb
|
103
135
|
- lib/ruby-static-tracing/tracers.rb
|
136
|
+
- lib/ruby-static-tracing/tracers/base.rb
|
104
137
|
- lib/ruby-static-tracing/tracers/concerns/latency_tracer.rb
|
138
|
+
- lib/ruby-static-tracing/tracers/helpers.rb
|
105
139
|
- lib/ruby-static-tracing/tracers/latency_tracer.rb
|
140
|
+
- lib/ruby-static-tracing/tracers/stack_tracer.rb
|
106
141
|
- lib/ruby-static-tracing/version.rb
|
107
142
|
homepage: https://github.com/dalehamel/ruby-static-tracing
|
108
143
|
licenses:
|
109
144
|
- MIT
|
110
145
|
metadata: {}
|
111
|
-
post_install_message:
|
146
|
+
post_install_message: "\n WARNING: you will need a new kernel (4.14+) that supports
|
147
|
+
eBPF.\n\n You should use the newest possible version of bpftrace\n "
|
112
148
|
rdoc_options: []
|
113
149
|
require_paths:
|
114
150
|
- lib
|
@@ -124,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
160
|
version: '0'
|
125
161
|
requirements: []
|
126
162
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.6.
|
163
|
+
rubygems_version: 2.7.6.2
|
128
164
|
signing_key:
|
129
165
|
specification_version: 4
|
130
166
|
summary: USDT tracing for Ruby
|