ruby-static-tracing 0.0.6 → 0.0.7
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 +4 -4
- data/ext/ruby-static-tracing/extconf.rb +2 -2
- data/ext/ruby-static-tracing/linux/tracepoint.c +4 -3
- data/lib/ruby-static-tracing/configuration.rb +1 -3
- data/lib/ruby-static-tracing/platform.rb +2 -42
- data/lib/ruby-static-tracing/provider.rb +1 -2
- data/lib/ruby-static-tracing/tracepoint.rb +1 -2
- data/lib/ruby-static-tracing/{tracers → tracer}/base.rb +3 -3
- data/lib/ruby-static-tracing/{tracers → tracer}/concerns/latency_tracer.rb +3 -5
- data/lib/ruby-static-tracing/{tracers → tracer}/helpers.rb +1 -1
- data/lib/ruby-static-tracing/{tracers/latency_tracer.rb → tracer/latency.rb} +3 -4
- data/lib/ruby-static-tracing/{tracers/stack_tracer.rb → tracer/stack.rb} +3 -5
- data/lib/ruby-static-tracing/tracer.rb +5 -0
- data/lib/ruby-static-tracing/tracers.rb +40 -2
- data/lib/ruby-static-tracing/version.rb +1 -1
- data/lib/ruby-static-tracing.rb +4 -12
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39954c9a0d6ad64110b48b91b8900daf274a292ee2dea064560f68f43f8cc266
|
4
|
+
data.tar.gz: 527f1c4b74aa68d01aad5d71b717fea2e3fd006206ac39f7c7ba8dec004dbb03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7460cb3b9d32d96e888337f7464981dc221b4762a4735f6f3e13334eada3000a1148c1c7c5051ce5f5b737f3e869c4dd6566b791781c73606b9269543fa39316
|
7
|
+
data.tar.gz: 6c80c8393ba0109ba5b1d0e979626b0eeb7401b94d41b1e4d8241be4ab317306fafab0c378cd463d74a42ce213a35f0c3c62c701194b074b0e9596684f675b0d
|
@@ -17,17 +17,17 @@ def lib_dir
|
|
17
17
|
end
|
18
18
|
# - Linux, via libstapsdt
|
19
19
|
if StaticTracing::Platform.linux?
|
20
|
-
abort 'libstapsdt.h is missing, please install libstapsdt' unless find_header('libstapsdt.h')
|
21
20
|
|
22
21
|
LIB_DIRS = [LIB_DIR, RbConfig::CONFIG['libdir']]
|
23
22
|
HEADER_DIRS = [
|
24
23
|
File.join(BASE_DIR, 'include'),
|
25
|
-
File.join(BASE_DIR, 'lib', 'libstapsdt'),
|
24
|
+
File.join(BASE_DIR, 'lib', 'libstapsdt', 'src'),
|
26
25
|
RbConfig::CONFIG['includedir']
|
27
26
|
]
|
28
27
|
|
29
28
|
dir_config(MKMF_TARGET, HEADER_DIRS, LIB_DIRS)
|
30
29
|
|
30
|
+
abort 'libstapsdt.h is missing, please install libstapsdt' unless find_header('libstapsdt.h')
|
31
31
|
have_header 'libstapsdt.h'
|
32
32
|
|
33
33
|
unless have_library('stapsdt')
|
@@ -121,9 +121,9 @@ static Tracepoint_arg_types
|
|
121
121
|
printf("ERROR - passed %i args, maximum 6 argument types can be passed", *argc);
|
122
122
|
return NULL;
|
123
123
|
}
|
124
|
-
|
124
|
+
int i;
|
125
125
|
Tracepoint_arg_types *args = malloc(*argc * sizeof(Tracepoint_arg_types));
|
126
|
-
for (
|
126
|
+
for (i = 0; i < *argc; i++)
|
127
127
|
{
|
128
128
|
VALUE str = rb_funcall(rb_ary_entry(vargs, i), rb_intern("to_s"), 0, Qnil);
|
129
129
|
const char* cStr = RSTRING_PTR(str);
|
@@ -158,7 +158,8 @@ static Tracepoint_fire_arg
|
|
158
158
|
|
159
159
|
Tracepoint_fire_arg *args = malloc(*argc * sizeof(Tracepoint_fire_arg));
|
160
160
|
//printf("SIZE: %i ARGC: %i \n", sizeof(Tracepoint_fire_arg), *argc);
|
161
|
-
|
161
|
+
int i;
|
162
|
+
for (i = 0; i < *argc; i++)
|
162
163
|
{
|
163
164
|
VALUE val = rb_ary_entry(vargs, i);
|
164
165
|
switch(TYPE(val))
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'singleton'
|
4
|
-
|
5
3
|
module StaticTracing
|
6
4
|
class Configuration
|
7
5
|
module Modes
|
@@ -41,7 +39,7 @@ module StaticTracing
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def add_tracer(tracer)
|
44
|
-
|
42
|
+
Tracers.add(tracer)
|
45
43
|
end
|
46
44
|
|
47
45
|
private
|
@@ -3,38 +3,6 @@
|
|
3
3
|
module StaticTracing
|
4
4
|
module Platform
|
5
5
|
extend self
|
6
|
-
UNSUPPORTED_POST_INSTALL_MESSAGE = %(
|
7
|
-
WARNING: You have installed this on an unsupported platform, somehow.
|
8
|
-
|
9
|
-
You should verify for yourself that the behavior on your platform is safe.
|
10
|
-
)
|
11
|
-
|
12
|
-
LINUX_POST_INSTALL_MESSAGE = %(
|
13
|
-
WARNING: you will need a new kernel (4.14+) that supports eBPF.
|
14
|
-
|
15
|
-
You should use the newest possible version of bpftrace
|
16
|
-
).freeze
|
17
|
-
|
18
|
-
DARWIN_POST_INSTALL_MESSAGE = %(
|
19
|
-
WARNING: tracing with dtrace will not work with SIP enabled.
|
20
|
-
|
21
|
-
SIP is enabled by default on recent versions of OSX. You can
|
22
|
-
check if SIP is enabled with:
|
23
|
-
|
24
|
-
csrutil status
|
25
|
-
|
26
|
-
If you want to test your probes out locally, you will need to at
|
27
|
-
least allow dtrace. To do this, you must reboot into recovery mode
|
28
|
-
by holding CMD + R while your Mac is booting. Once it has booted,
|
29
|
-
open a terminal and type:
|
30
|
-
|
31
|
-
csrutil clear
|
32
|
-
csrutil enable --without-dtrace
|
33
|
-
|
34
|
-
After this, you should be able to use dtrace on the tracepoints you
|
35
|
-
define here. If it still doesn't work, you can disable SIP entirely
|
36
|
-
but this is not recommended for security purposes.
|
37
|
-
).freeze
|
38
6
|
|
39
7
|
def linux?
|
40
8
|
/linux/.match(RUBY_PLATFORM)
|
@@ -44,16 +12,8 @@ module StaticTracing
|
|
44
12
|
/darwin/.match(RUBY_PLATFORM)
|
45
13
|
end
|
46
14
|
|
47
|
-
def
|
48
|
-
|
49
|
-
if linux?
|
50
|
-
LINUX_POST_INSTALL_MESSAGE
|
51
|
-
elsif darwin?
|
52
|
-
DARWIN_POST_INSTALL_MESSAGE
|
53
|
-
else
|
54
|
-
UNSUPPORTED_POST_INSTALL_MESSAGE
|
55
|
-
end
|
56
|
-
end
|
15
|
+
def supported_platform?
|
16
|
+
linux? || darwin?
|
57
17
|
end
|
58
18
|
end
|
59
19
|
end
|
@@ -42,8 +42,7 @@ module StaticTracing
|
|
42
42
|
attr_reader :namespace
|
43
43
|
|
44
44
|
def initialize(namespace)
|
45
|
-
if StaticTracing::Platform.
|
46
|
-
StaticTracing::Platform.darwin?
|
45
|
+
if StaticTracing::Platform.supported_platform?
|
47
46
|
provider_initialize(namespace)
|
48
47
|
else
|
49
48
|
StaticTracing.issue_disabled_tracepoints_warning
|
@@ -26,8 +26,7 @@ module StaticTracing
|
|
26
26
|
validate_args(args)
|
27
27
|
@args = args
|
28
28
|
|
29
|
-
if StaticTracing::Platform.
|
30
|
-
StaticTracing::Platform.darwin?
|
29
|
+
if StaticTracing::Platform.supported_platform?
|
31
30
|
tracepoint_initialize(provider, name, args)
|
32
31
|
else
|
33
32
|
StaticTracing.issue_disabled_tracepoints_warning
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'unmixer'
|
2
2
|
using Unmixer
|
3
3
|
|
4
|
-
require 'ruby-static-tracing/
|
4
|
+
require 'ruby-static-tracing/tracer/helpers'
|
5
5
|
|
6
6
|
module StaticTracing
|
7
|
-
module
|
7
|
+
module Tracer
|
8
8
|
class Base
|
9
9
|
class << self
|
10
|
-
include
|
10
|
+
include Tracer::Helpers
|
11
11
|
|
12
12
|
def register(klass, *method_names, provider: nil)
|
13
13
|
provider ||= underscore(klass.name)
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ruby-static-tracing/tracers/latency_tracer'
|
4
|
-
|
5
3
|
module StaticTracing
|
6
|
-
module
|
4
|
+
module Tracer
|
7
5
|
module Concerns
|
8
|
-
module
|
6
|
+
module Latency
|
9
7
|
def self.included(base)
|
10
8
|
methods = base.public_instance_methods(false)
|
11
|
-
StaticTracing::
|
9
|
+
StaticTracing::Tracer::Latency.register(base, methods)
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'ruby-static-tracing/tracers/base'
|
3
2
|
|
4
3
|
module StaticTracing
|
5
|
-
module
|
6
|
-
class
|
4
|
+
module Tracer
|
5
|
+
class Latency < Base
|
7
6
|
set_wrapping_function -> (*args, &block) {
|
8
7
|
start_time = StaticTracing.nsec
|
9
8
|
result = super(*args, &block)
|
10
9
|
duration = StaticTracing.nsec - start_time
|
11
10
|
method_name = __method__.to_s
|
12
|
-
provider =
|
11
|
+
provider = Tracer::Helpers.underscore(self.class.name)
|
13
12
|
Tracepoints.get(provider, method_name).fire(method_name, duration)
|
14
13
|
result
|
15
14
|
}
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ruby-static-tracing/tracers/base'
|
4
|
-
|
5
3
|
module StaticTracing
|
6
|
-
module
|
7
|
-
class
|
4
|
+
module Tracer
|
5
|
+
class Stack < Base
|
8
6
|
set_wrapping_function -> (*args, &block) {
|
9
7
|
current_stack = self.send(:caller).join("\n")
|
10
8
|
method_name = __method__.to_s
|
11
|
-
provider =
|
9
|
+
provider = Tracer::Helpers.underscore(self.class.name)
|
12
10
|
Tracepoints.get(provider, method_name).fire(method_name, current_stack)
|
13
11
|
super(*args, &block)
|
14
12
|
}
|
@@ -1,4 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module StaticTracing
|
4
|
+
class Tracers
|
5
|
+
class InvalidTracerError < StandardError
|
6
|
+
def initialize
|
7
|
+
msg = <<~MSG
|
8
|
+
You need to add a valid tracer.
|
9
|
+
|
10
|
+
To create a valid tracer please inherit from StaticTracing::Tracer::Base
|
11
|
+
and follow the guide on how to create tracers
|
12
|
+
MSG
|
13
|
+
super(msg)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def add(tracer)
|
19
|
+
raise InvalidTracerError unless tracer < StaticTracing::Tracer::Base
|
20
|
+
tracers << tracer
|
21
|
+
end
|
22
|
+
|
23
|
+
def enable!
|
24
|
+
tracers.each(&:enable!)
|
25
|
+
end
|
26
|
+
|
27
|
+
def disable!
|
28
|
+
tracers.each(&:disable!)
|
29
|
+
end
|
30
|
+
|
31
|
+
def clean
|
32
|
+
@tracers = []
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def tracers
|
38
|
+
@tracers ||= []
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ruby-static-tracing.rb
CHANGED
@@ -8,6 +8,7 @@ require 'ruby-static-tracing/provider'
|
|
8
8
|
require 'ruby-static-tracing/tracepoint'
|
9
9
|
require 'ruby-static-tracing/tracepoints'
|
10
10
|
require 'ruby-static-tracing/configuration'
|
11
|
+
require 'ruby-static-tracing/tracer'
|
11
12
|
require 'ruby-static-tracing/tracers'
|
12
13
|
|
13
14
|
# FIXME Including StaticTracing should cause every method in a module or class to be registered
|
@@ -45,7 +46,7 @@ module StaticTracing
|
|
45
46
|
# Overwrite the definition of all functions that are enabled
|
46
47
|
# with a wrapped version that has tracing enabled
|
47
48
|
def enable!
|
48
|
-
|
49
|
+
StaticTracing::Tracers.enable!
|
49
50
|
StaticTracing::Provider.enable!
|
50
51
|
@enabled = true
|
51
52
|
end
|
@@ -53,20 +54,11 @@ module StaticTracing
|
|
53
54
|
# Overwrite the definition of all functions to their original definition,
|
54
55
|
# no longer wrapping them
|
55
56
|
def disable!
|
56
|
-
|
57
|
+
StaticTracing::Tracers.disable!
|
57
58
|
StaticTracing::Provider.disable!
|
58
59
|
@enabled = false
|
59
60
|
end
|
60
61
|
|
61
|
-
# Retrieves a hash of all registered providers
|
62
|
-
def providers
|
63
|
-
@providers ||= {}
|
64
|
-
end
|
65
|
-
|
66
|
-
def tracers
|
67
|
-
@tracers ||= []
|
68
|
-
end
|
69
|
-
|
70
62
|
def toggle_tracing!
|
71
63
|
enabled? ? disable! : enable!
|
72
64
|
end
|
@@ -76,4 +68,4 @@ module StaticTracing
|
|
76
68
|
end
|
77
69
|
end
|
78
70
|
|
79
|
-
require 'ruby-static-tracing/ruby_static_tracing' if StaticTracing::Platform.
|
71
|
+
require 'ruby-static-tracing/ruby_static_tracing' if StaticTracing::Platform.supported_platform?
|
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.7
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unmixer
|
@@ -161,14 +161,15 @@ files:
|
|
161
161
|
- lib/ruby-static-tracing/provider.rb
|
162
162
|
- lib/ruby-static-tracing/tracepoint.rb
|
163
163
|
- lib/ruby-static-tracing/tracepoints.rb
|
164
|
+
- lib/ruby-static-tracing/tracer.rb
|
165
|
+
- lib/ruby-static-tracing/tracer/base.rb
|
166
|
+
- lib/ruby-static-tracing/tracer/concerns/latency_tracer.rb
|
167
|
+
- lib/ruby-static-tracing/tracer/helpers.rb
|
168
|
+
- lib/ruby-static-tracing/tracer/latency.rb
|
169
|
+
- lib/ruby-static-tracing/tracer/stack.rb
|
164
170
|
- lib/ruby-static-tracing/tracers.rb
|
165
|
-
- lib/ruby-static-tracing/tracers/base.rb
|
166
|
-
- lib/ruby-static-tracing/tracers/concerns/latency_tracer.rb
|
167
|
-
- lib/ruby-static-tracing/tracers/helpers.rb
|
168
|
-
- lib/ruby-static-tracing/tracers/latency_tracer.rb
|
169
|
-
- lib/ruby-static-tracing/tracers/stack_tracer.rb
|
170
171
|
- lib/ruby-static-tracing/version.rb
|
171
|
-
homepage: https://github.com/
|
172
|
+
homepage: https://github.com/dalehamel/ruby-static-tracing
|
172
173
|
licenses:
|
173
174
|
- MIT
|
174
175
|
metadata: {}
|