ruby-static-tracing 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5bea8f6cfef0a767f1cabe69d7e719944ed236974b5fab9885b86f7a81e884c
4
- data.tar.gz: 82382b83d719379a7b11288e6ecc8a552de29c123067fa75ba8f8f5cffb40d13
3
+ metadata.gz: 39954c9a0d6ad64110b48b91b8900daf274a292ee2dea064560f68f43f8cc266
4
+ data.tar.gz: 527f1c4b74aa68d01aad5d71b717fea2e3fd006206ac39f7c7ba8dec004dbb03
5
5
  SHA512:
6
- metadata.gz: 39811b0423ecbe035ed85f00b3baeb34f889f52752bcb0952781b93db8c5d81a611240bc954943cd4257563c6f7b0f6e96e98e70a6915625e37c37550e97eaef
7
- data.tar.gz: b49a83b3c09ada4e06402d3265c6016a334dffd0ce667a27c30c0828340a2654aa92b568573435a624e1980024d74b55d40efcee495526ae7f90d3d6988673a8
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 (int i = 0; i < *argc; i++)
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
- for (int i = 0; i < *argc; i++)
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
- StaticTracing.tracers << tracer
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 post_install_message
48
- message = begin
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.linux? ||
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.linux? ||
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/tracers/helpers'
4
+ require 'ruby-static-tracing/tracer/helpers'
5
5
 
6
6
  module StaticTracing
7
- module Tracers
7
+ module Tracer
8
8
  class Base
9
9
  class << self
10
- include Tracers::Helpers
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 Tracers
4
+ module Tracer
7
5
  module Concerns
8
- module LatencyTracer
6
+ module Latency
9
7
  def self.included(base)
10
8
  methods = base.public_instance_methods(false)
11
- StaticTracing::Tracers::LatencyTracer.register(base, methods)
9
+ StaticTracing::Tracer::Latency.register(base, methods)
12
10
  end
13
11
  end
14
12
  end
@@ -1,5 +1,5 @@
1
1
  module StaticTracing
2
- module Tracers
2
+ module Tracer
3
3
  module Helpers
4
4
  extend self
5
5
 
@@ -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 Tracers
6
- class LatencyTracer < Base
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 = Tracers::Helpers.underscore(self.class.name)
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 Tracers
7
- class StackTracer < Base
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 = Tracers::Helpers.underscore(self.class.name)
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
  }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tracer/base'
4
+ require_relative 'tracer/latency'
5
+ require_relative 'tracer/stack'
@@ -1,4 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'tracers/latency_tracer'
4
- require_relative 'tracers/stack_tracer'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StaticTracing
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
@@ -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
- tracers.each(&:enable!)
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
- tracers.each(&:disable!)
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.linux? || StaticTracing::Platform.darwin?
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.6
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-10 00:00:00.000000000 Z
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/shopify/ruby-static-tracing
172
+ homepage: https://github.com/dalehamel/ruby-static-tracing
172
173
  licenses:
173
174
  - MIT
174
175
  metadata: {}