Class: DTrace::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-dtrace/subscriber.rb

Constant Summary collapse

MAX_INT =
2147483647
@@probes =
{}
@@enabled =
false

Class Method Summary collapse

Class Method Details

.call(notification, start_time, end_time, id, payload) ⇒ Object

Rails 3.x define instruments as blocks that wrap code. When the code finishes executing, subscribers are called with the start and end time.



26
27
28
# File 'lib/rails-dtrace/subscriber.rb', line 26

def call(notification, start_time, end_time, id, payload)
  fire_probe(notification, id, payload, 'event', start_time, end_time)
end

.find_or_create_probe(probe_func, probe_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rails-dtrace/subscriber.rb', line 41

def find_or_create_probe(probe_func, probe_name)
  probe_id = "#{probe_func}::#{probe_name}"

  unless probes.keys.include?(probe_id)
    probe = provider.probe(probe_func, probe_name, :string, :string, :integer)
    probes[probe_id] = probe

    logger.debug "Adding DTrace probe: #{probe_id}"

    provider.disable if @@enabled
    provider.enable
    @@enabled = true
  end

  probes[probe_id]
end

.finish(notification, id, payload) ⇒ Object



37
38
39
# File 'lib/rails-dtrace/subscriber.rb', line 37

def finish(notification, id, payload)
  fire_probe(notification, id, payload, 'exit')
end

.loggerObject



15
16
17
# File 'lib/rails-dtrace/subscriber.rb', line 15

def logger
  @logger ||= Rails.logger if defined?(Rails)
end

.providerObject



19
20
21
# File 'lib/rails-dtrace/subscriber.rb', line 19

def provider
  @provider ||= DTrace::Provider.new
end

.start(notification, id, payload) ⇒ Object

Rails 4.x defines instruments in a different way, where #start is called when the block begins and #finish is called when the block ends.



33
34
35
# File 'lib/rails-dtrace/subscriber.rb', line 33

def start(notification, id, payload)
  fire_probe(notification, id, payload, 'entry')
end