Class: Insight::Instrumentation::Instrument
- Inherits:
-
Object
- Object
- Insight::Instrumentation::Instrument
- Includes:
- Backstage, Logging
- Defined in:
- lib/insight/instrumentation/instrument.rb
Defined Under Namespace
Classes: MethodCall, Timing
Constant Summary
- @@call_seq =
0
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) all_collectors
- - (Object) collectors_for(method_call)
- - (Object) duration
- - (Object) finish(env, status, headers, body)
- - (Object) finish_event(method_call, arguments, start_time, result)
-
- (Instrument) initialize
constructor
A new instance of Instrument.
- - (Object) run(object, context = "::", kind = :instance, called_at = caller[0], method = "<unknown>", args = [], &blk)
- - (Object) start(env)
- - (Object) start_event(method_call, arguments)
Methods included from Logging
Methods included from Backstage
Constructor Details
- (Instrument) initialize
A new instance of Instrument
32 33 34 35 |
# File 'lib/insight/instrumentation/instrument.rb', line 32 def initialize() @start = Time.now @collectors = nil end |
Class Method Details
+ (Object) seq_number
26 27 28 29 30 |
# File 'lib/insight/instrumentation/instrument.rb', line 26 def self.seq_number Thread.exclusive do return @@call_seq += 1 end end |
Instance Method Details
- (Object) all_collectors
87 88 89 |
# File 'lib/insight/instrumentation/instrument.rb', line 87 def all_collectors PackageDefinition.all_collectors end |
- (Object) collectors_for(method_call)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/insight/instrumentation/instrument.rb', line 56 def collectors_for(method_call) probe_chain = if method_call.kind == :instance InstanceProbe.get_probe_chain(method_call.context) else ClassProbe.get_probe_chain(method_call.context) end collectors = probe_chain.inject([]) do |list, probe| probe.collectors(method_call.method) end logger.debug do "Probe chain for: #{method_call.context} #{method_call.kind} #{method_call.method}:\n #{collectors.map{|col| col.class.name}.join(", ")}" end collectors end |
- (Object) duration
104 105 106 |
# File 'lib/insight/instrumentation/instrument.rb', line 104 def duration @timing.duration end |
- (Object) finish(env, status, headers, body)
97 98 99 100 101 102 |
# File 'lib/insight/instrumentation/instrument.rb', line 97 def finish(env, status, headers, body) @timing = Timing.new(@start, @start, Time.now) all_collectors.each do |collector| collector.request_finish(env, status, headers, body, @timing) end end |
- (Object) finish_event(method_call, arguments, start_time, result)
79 80 81 82 83 84 85 |
# File 'lib/insight/instrumentation/instrument.rb', line 79 def finish_event(method_call, arguments, start_time, result) timing = Timing.new(@start, start_time, Time.now) logger.debug{ "Finishing event: #{method_call.context} #{method_call.kind} #{method_call.method}" } collectors_for(method_call).each do |collector| collector.after_detect(method_call, timing, arguments, result) end end |
- (Object) run(object, context = "::", kind = :instance, called_at = caller[0], method = "<unknown>", args = [], &blk)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/insight/instrumentation/instrument.rb', line 41 def run(object, context="::", kind=:instance, called_at = caller[0], method = "<unknown>", args=[], &blk) file, line, rest = called_at.split(':') call_number = backstage{ self.class.seq_number } method_call = backstage{ MethodCall.new(call_number, caller(1), file, line, object, context, kind, method, Thread::current) } #$stderr.puts [method_call.context, method_call.method].inspect start_time = Time.now backstage do start_event(method_call, args) end result = blk.call # execute the provided code block backstage do finish_event(method_call, args, start_time, result) end end |
- (Object) start(env)
91 92 93 94 95 |
# File 'lib/insight/instrumentation/instrument.rb', line 91 def start(env) all_collectors.each do |collector| collector.request_start(env, @start) end end |
- (Object) start_event(method_call, arguments)
71 72 73 74 75 76 77 |
# File 'lib/insight/instrumentation/instrument.rb', line 71 def start_event(method_call, arguments) logger.debug{ "Starting event: #{method_call.context} #{method_call.kind} #{method_call.method}" } collectors_for(method_call).each do |collector| collector.before_detect(method_call, arguments) end end |