Class: Necropsy::Analyzers::Dynamic::TracePointCollector
- Inherits:
-
Object
- Object
- Necropsy::Analyzers::Dynamic::TracePointCollector
- Defined in:
- lib/necropsy/analyzers/dynamic/trace_point_collector.rb
Class Method Summary collapse
- .install_at_exit(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) ⇒ Object
- .record(root:, output:, sample_rate: 1.0) ⇒ Object
Instance Method Summary collapse
-
#initialize(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) ⇒ TracePointCollector
constructor
A new instance of TracePointCollector.
- #install_at_exit ⇒ Object
- #record ⇒ Object
Constructor Details
#initialize(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) ⇒ TracePointCollector
Returns a new instance of TracePointCollector.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/necropsy/analyzers/dynamic/trace_point_collector.rb', line 20 def initialize(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) @root = File.(root) @output = output @sample_rate = sample_rate.to_f raise Error, 'sample_rate must be between 0.0 and 1.0' unless @sample_rate.between?(0.0, 1.0) @nodes = {} @edges = {} @stacks = {}.compare_by_identity @lock = Mutex.new @merge = merge @run_id = run_id end |
Class Method Details
.install_at_exit(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) ⇒ Object
16 17 18 |
# File 'lib/necropsy/analyzers/dynamic/trace_point_collector.rb', line 16 def self.install_at_exit(root:, output:, sample_rate: 1.0, merge: false, run_id: nil) new(root: root, output: output, sample_rate: sample_rate, merge: merge, run_id: run_id).install_at_exit end |
.record(root:, output:, sample_rate: 1.0) ⇒ Object
12 13 14 |
# File 'lib/necropsy/analyzers/dynamic/trace_point_collector.rb', line 12 def self.record(root:, output:, sample_rate: 1.0, &) new(root: root, output: output, sample_rate: sample_rate).record(&) end |
Instance Method Details
#install_at_exit ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/necropsy/analyzers/dynamic/trace_point_collector.rb', line 44 def install_at_exit started_at = Time.now.utc tracer = TracePoint.new(:call, :return) { |event| capture(event) } tracer.enable at_exit do tracer.disable write_payload(started_at: started_at, finished_at: Time.now.utc) rescue StandardError => e warn "Necropsy TracePoint collector failed: #{e.}" end end |
#record ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/necropsy/analyzers/dynamic/trace_point_collector.rb', line 34 def record started_at = Time.now.utc tracer = TracePoint.new(:call, :return) { |event| capture(event) } tracer.enable yield ensure tracer&.disable write_payload(started_at: started_at, finished_at: Time.now.utc) end |