runtime_analysis 1.0.0
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 +7 -0
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +96 -0
- data/README.md +164 -0
- data/editor/nvim/README.md +278 -0
- data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
- data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
- data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
- data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
- data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
- data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
- data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
- data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
- data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
- data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
- data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
- data/editor/nvim/plugin/runtime_analysis.lua +71 -0
- data/examples/trackers/PROMPT.md +86 -0
- data/examples/trackers/honeybadger.rb +19 -0
- data/examples/trackers/sentry.rb +16 -0
- data/ext/runtime_analysis/extconf.rb +68 -0
- data/ext/runtime_analysis/fast.c +775 -0
- data/ext/runtime_analysis/fast.h +59 -0
- data/ext/runtime_analysis/hold.c +560 -0
- data/ext/runtime_analysis/init.c +36 -0
- data/ext/runtime_analysis/names.c +78 -0
- data/ext/runtime_analysis/names.h +28 -0
- data/ext/runtime_analysis/novelty.c +139 -0
- data/ext/runtime_analysis/novelty.h +22 -0
- data/ext/runtime_analysis/os.c +73 -0
- data/ext/runtime_analysis/os.h +32 -0
- data/ext/runtime_analysis/ring.c +445 -0
- data/ext/runtime_analysis/rows.c +304 -0
- data/ext/runtime_analysis/sink.c +485 -0
- data/ext/runtime_analysis/sink.h +240 -0
- data/ext/runtime_analysis/state.c +254 -0
- data/ext/runtime_analysis/state.h +57 -0
- data/ext/runtime_analysis/wrapper.c +278 -0
- data/ext/runtime_analysis/wrapper.h +24 -0
- data/lib/runtime_analysis/errors.rb +34 -0
- data/lib/runtime_analysis/failsafe.rb +123 -0
- data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
- data/lib/runtime_analysis/host/declared.rb +152 -0
- data/lib/runtime_analysis/host/inject.rb +90 -0
- data/lib/runtime_analysis/host/job_runners.rb +27 -0
- data/lib/runtime_analysis/host/middleware.rb +23 -0
- data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
- data/lib/runtime_analysis/host/railtie.rb +42 -0
- data/lib/runtime_analysis/host/reports.rb +54 -0
- data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
- data/lib/runtime_analysis/host/web.rb +22 -0
- data/lib/runtime_analysis/host.rb +34 -0
- data/lib/runtime_analysis/inject.rb +5 -0
- data/lib/runtime_analysis/minitest.rb +9 -0
- data/lib/runtime_analysis/native/build.rb +17 -0
- data/lib/runtime_analysis/native/byte_size.rb +27 -0
- data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
- data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
- data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
- data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
- data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
- data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
- data/lib/runtime_analysis/native/sink.rb +12 -0
- data/lib/runtime_analysis/native.rb +74 -0
- data/lib/runtime_analysis/platform.rb +30 -0
- data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
- data/lib/runtime_analysis/query/index/graph.rb +107 -0
- data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
- data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
- data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
- data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
- data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
- data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
- data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
- data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
- data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
- data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
- data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
- data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
- data/lib/runtime_analysis/query/index/reading.rb +80 -0
- data/lib/runtime_analysis/query/index/shapes.rb +142 -0
- data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
- data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
- data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
- data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
- data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
- data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
- data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
- data/lib/runtime_analysis/query/index/signatures.rb +93 -0
- data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
- data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
- data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
- data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
- data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
- data/lib/runtime_analysis/query/index/static/method.rb +19 -0
- data/lib/runtime_analysis/query/index/static/params.rb +52 -0
- data/lib/runtime_analysis/query/index/static/source.rb +69 -0
- data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
- data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
- data/lib/runtime_analysis/query/index/static/value.rb +17 -0
- data/lib/runtime_analysis/query/index/static/values.rb +71 -0
- data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
- data/lib/runtime_analysis/query/index/static.rb +85 -0
- data/lib/runtime_analysis/query/index.rb +32 -0
- data/lib/runtime_analysis/query/nodes.rb +60 -0
- data/lib/runtime_analysis/query/project/config.rb +108 -0
- data/lib/runtime_analysis/query/project.rb +40 -0
- data/lib/runtime_analysis/query/report/document.rb +84 -0
- data/lib/runtime_analysis/query/report/finding.rb +15 -0
- data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
- data/lib/runtime_analysis/query/report/list.rb +15 -0
- data/lib/runtime_analysis/query/report/location.rb +14 -0
- data/lib/runtime_analysis/query/report/one_row.rb +14 -0
- data/lib/runtime_analysis/query/report/outline.rb +15 -0
- data/lib/runtime_analysis/query/report/paint.rb +34 -0
- data/lib/runtime_analysis/query/report/related.rb +11 -0
- data/lib/runtime_analysis/query/report/table.rb +15 -0
- data/lib/runtime_analysis/query/report/text.rb +13 -0
- data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
- data/lib/runtime_analysis/query/report.rb +35 -0
- data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
- data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
- data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
- data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
- data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
- data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
- data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
- data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
- data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
- data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
- data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
- data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
- data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
- data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
- data/lib/runtime_analysis/query/surfaces.rb +14 -0
- data/lib/runtime_analysis/query/tools/base.rb +86 -0
- data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
- data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
- data/lib/runtime_analysis/query/tools/origins.rb +47 -0
- data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
- data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
- data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
- data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
- data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
- data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
- data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
- data/lib/runtime_analysis/query/tools.rb +34 -0
- data/lib/runtime_analysis/query.rb +33 -0
- data/lib/runtime_analysis/recording/blob.rb +13 -0
- data/lib/runtime_analysis/recording/format.rb +32 -0
- data/lib/runtime_analysis/recording/opcodes.rb +30 -0
- data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
- data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
- data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
- data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
- data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
- data/lib/runtime_analysis/recording/seen.rb +63 -0
- data/lib/runtime_analysis/recording/sink.rb +19 -0
- data/lib/runtime_analysis/recording/source_blob.rb +20 -0
- data/lib/runtime_analysis/recording.rb +52 -0
- data/lib/runtime_analysis/rspec.rb +8 -0
- data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
- data/lib/runtime_analysis/ruby_parsing.rb +98 -0
- data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
- data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
- data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
- data/lib/runtime_analysis/trace/configuration.rb +115 -0
- data/lib/runtime_analysis/trace/entries.rb +47 -0
- data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
- data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
- data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
- data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
- data/lib/runtime_analysis/trace/hold.rb +142 -0
- data/lib/runtime_analysis/trace/inclusion.rb +46 -0
- data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
- data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
- data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
- data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
- data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
- data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
- data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
- data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
- data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
- data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
- data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
- data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
- data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
- data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
- data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
- data/lib/runtime_analysis/trace/installer.rb +149 -0
- data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
- data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
- data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
- data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
- data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
- data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
- data/lib/runtime_analysis/trace/mechanism.rb +28 -0
- data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
- data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
- data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
- data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
- data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
- data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
- data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
- data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
- data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
- data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
- data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
- data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
- data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
- data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
- data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
- data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
- data/lib/runtime_analysis/trace/novelty.rb +17 -0
- data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
- data/lib/runtime_analysis/trace/pure/state.rb +94 -0
- data/lib/runtime_analysis/trace/pure.rb +15 -0
- data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
- data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
- data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
- data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
- data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
- data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
- data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
- data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
- data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
- data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
- data/lib/runtime_analysis/trace/recorder.rb +149 -0
- data/lib/runtime_analysis/trace/state.rb +16 -0
- data/lib/runtime_analysis/trace.rb +142 -0
- data/lib/runtime_analysis/version.rb +6 -0
- data/lib/runtime_analysis/web.rb +6 -0
- data/lib/runtime_analysis.rb +125 -0
- metadata +330 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "state"
|
|
4
|
+
require_relative "recorder/paths"
|
|
5
|
+
require_relative "recorder/class_name"
|
|
6
|
+
require_relative "recorder/fingerprint"
|
|
7
|
+
require_relative "recorder/raise_site"
|
|
8
|
+
require_relative "recorder/unwinding"
|
|
9
|
+
require_relative "installer/registry"
|
|
10
|
+
require_relative "inclusion"
|
|
11
|
+
require_relative "recorder/reachability"
|
|
12
|
+
require_relative "recorder/frame_key"
|
|
13
|
+
require_relative "recorder/row_emission"
|
|
14
|
+
require_relative "recorder/tree_steps"
|
|
15
|
+
require_relative "recorder/safe_steps"
|
|
16
|
+
require_relative "nil_origin"
|
|
17
|
+
require "runtime_analysis/failsafe"
|
|
18
|
+
|
|
19
|
+
module RuntimeAnalysis
|
|
20
|
+
module Trace
|
|
21
|
+
class Recorder
|
|
22
|
+
include RowEmission
|
|
23
|
+
include Reachability
|
|
24
|
+
include TreeSteps
|
|
25
|
+
include SafeSteps
|
|
26
|
+
|
|
27
|
+
ENTERED = Object.new.freeze
|
|
28
|
+
|
|
29
|
+
BLOCK_FORM_OFFSET = 3
|
|
30
|
+
RUBY_OFFSET = 3
|
|
31
|
+
ENTRY_KEYWORDS_AS_HASH = 5
|
|
32
|
+
|
|
33
|
+
attr_reader :novelty, :logger, :hold, :seen
|
|
34
|
+
|
|
35
|
+
def self.class_names = ClassName
|
|
36
|
+
def self.raise_site(error) = RaiseSite.of(error)
|
|
37
|
+
def self.missing(error) = RaiseSite.missing(error)
|
|
38
|
+
def self.raised_since(handled) = Unwinding.since(handled)
|
|
39
|
+
|
|
40
|
+
def initialize(registry:, inclusion:, logger:, capture:)
|
|
41
|
+
choose_calls_by(registry, inclusion, capture.novelty)
|
|
42
|
+
write_to(logger, capture.tier, capture.hold)
|
|
43
|
+
@seen = capture.seen
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def record(id, receiver, args = nil, kwargs = nil, &block)
|
|
47
|
+
token = before(id, receiver, args, kwargs, BLOCK_FORM_OFFSET)
|
|
48
|
+
token ? traced(token, &block) : block.call
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def capture_head(id, receiver)
|
|
52
|
+
state = State.current
|
|
53
|
+
return nil if state.capturing?
|
|
54
|
+
|
|
55
|
+
state.capture { head_for(id, receiver, state) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def head_for(id, receiver, state)
|
|
59
|
+
entry = @registry.fetch(id)
|
|
60
|
+
return nil unless reachable?(entry, state)
|
|
61
|
+
|
|
62
|
+
head = [frame_for(entry, receiver), *enter(state, id, receiver, entry), gem?(entry),
|
|
63
|
+
entry.fetch(ENTRY_KEYWORDS_AS_HASH), entry.fetch(7)]
|
|
64
|
+
record_call? ? head : ENTERED
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def emit_tail(head, receiver, args, kwargs, loc)
|
|
68
|
+
return leave(State.current) unless direct?(head, loc)
|
|
69
|
+
|
|
70
|
+
State.current.capture { tail_for(head, receiver, *received(head, args, kwargs), loc) }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def tail_for(head, receiver, args, kwargs, loc)
|
|
74
|
+
stamp_entry(head.fetch(1)) if State.current.first_record?
|
|
75
|
+
emit(head, loc, receiver, args, kwargs)
|
|
76
|
+
emit_answered(head, args)
|
|
77
|
+
return emit_values(head, receiver, args, kwargs) if head.fetch(HEAD_PROBED)
|
|
78
|
+
|
|
79
|
+
@tier >= 3 ? head[1, 2] : ENTERED
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def stamp_inner_entry
|
|
83
|
+
state = State.current
|
|
84
|
+
tree = state.tree
|
|
85
|
+
state.capture { log_inner_entry(tree) } if tree
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def stats
|
|
89
|
+
counts = { routes: @paths.size }
|
|
90
|
+
counts.merge!(recorded: @novelty.recorded, skipped: @novelty.skipped) if @novelty
|
|
91
|
+
counts.merge!(hold_counts) if @hold
|
|
92
|
+
counts
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def nil_origin(error, root)
|
|
96
|
+
State.current.capture { NilOrigin.facts(error, @logger, @paths, root: root) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def choose_calls_by(registry, inclusion, novelty)
|
|
102
|
+
@registry = registry
|
|
103
|
+
@inclusion = inclusion
|
|
104
|
+
@novelty = novelty
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def write_to(logger, tier, hold)
|
|
108
|
+
@logger = logger
|
|
109
|
+
@tier = tier
|
|
110
|
+
@hold = hold
|
|
111
|
+
@paths = Paths.new
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def hold_counts
|
|
115
|
+
{ kept: @hold.kept, largest_request: @logger.largest_request, reported_outside_request: @hold.unplaced }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def complete(token, error, result)
|
|
119
|
+
return unless token.instance_of?(Array)
|
|
120
|
+
|
|
121
|
+
State.current.capture { log_outcome(token, error, result) }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def log_outcome(token, error, result)
|
|
125
|
+
if error
|
|
126
|
+
log_unwind(token, error) if @tier >= 4
|
|
127
|
+
else
|
|
128
|
+
log_returned(token, result)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def record_call?
|
|
133
|
+
@novelty.nil? || @novelty.record?(State.current.path_hash)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def path_for(frame, loc)
|
|
137
|
+
state = State.current
|
|
138
|
+
@paths.define(state.path_hash, state.parent_hash, frame, loc)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def frame_for(entry, receiver)
|
|
142
|
+
name, class_method, file, line = entry
|
|
143
|
+
# rubocop:disable Style/CaseEquality -- host object: is_a? would be a message sent to it
|
|
144
|
+
[ClassName.of(receiver), name, file, line, class_method || Module === receiver]
|
|
145
|
+
# rubocop:enable Style/CaseEquality
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/native"
|
|
4
|
+
require_relative "pure"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Trace
|
|
8
|
+
class State < (Native.loaded? ? Object : Pure.state)
|
|
9
|
+
KEY = :runtime_analysis_state
|
|
10
|
+
|
|
11
|
+
def self.current
|
|
12
|
+
Thread.current[KEY] ||= new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "native"
|
|
4
|
+
require_relative "trace/state"
|
|
5
|
+
require_relative "trace/inclusion"
|
|
6
|
+
require_relative "trace/recorder"
|
|
7
|
+
require_relative "trace/mechanism"
|
|
8
|
+
require_relative "trace/installer"
|
|
9
|
+
require_relative "trace/novelty"
|
|
10
|
+
require_relative "trace/hold"
|
|
11
|
+
require_relative "trace/entries"
|
|
12
|
+
require_relative "trace/nil_origin"
|
|
13
|
+
require_relative "trace/configuration"
|
|
14
|
+
|
|
15
|
+
module RuntimeAnalysis
|
|
16
|
+
module Trace
|
|
17
|
+
NATIVE_OFFSET = 2
|
|
18
|
+
|
|
19
|
+
Capture = Struct.new(:tier, :novelty, :mechanism, :builders, :hold, :probe, :seen, :ivars, keyword_init: true)
|
|
20
|
+
|
|
21
|
+
class Capture
|
|
22
|
+
def initialize(tier: Configuration.tier(:calls), mechanism: :native, seen: Recording.unreported, **rest)
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
include(*Mechanism.entries)
|
|
29
|
+
include Installer.body_sync
|
|
30
|
+
include Hold.requests
|
|
31
|
+
include Entries
|
|
32
|
+
|
|
33
|
+
def start(logger:, inclusion:, capture: Capture.new, registry: Installer.registry_after(@registry), called: nil)
|
|
34
|
+
@registry = registry
|
|
35
|
+
@recorder = Recorder.new(registry:, inclusion:, logger:, capture:)
|
|
36
|
+
@installer = Installer.new(registry: registry, inclusion: inclusion, called: called, capture: capture,
|
|
37
|
+
wrapper: Mechanism.wrapper(capture.mechanism, tier: capture.tier))
|
|
38
|
+
activate(capture.tier, capture.builders)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def start_configured(configuration, logger)
|
|
42
|
+
inclusion = configuration.inclusion
|
|
43
|
+
start(logger: logger, inclusion: inclusion, called: configuration.called_names(inclusion),
|
|
44
|
+
capture: configuration.capture(logger))
|
|
45
|
+
sweep
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def sweep
|
|
49
|
+
@installer&.sweep
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def stop
|
|
53
|
+
@enabled = false
|
|
54
|
+
stop_wrapper
|
|
55
|
+
@visibility_sync&.disable
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def enabled?
|
|
59
|
+
@enabled == true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
attr_reader :registry
|
|
63
|
+
|
|
64
|
+
def seen = @recorder.seen
|
|
65
|
+
|
|
66
|
+
def configuration = Configuration.new
|
|
67
|
+
|
|
68
|
+
def raised_since(handled) = Recorder.raised_since(handled)
|
|
69
|
+
|
|
70
|
+
def on_defined(mod, name, class_method:)
|
|
71
|
+
@installer.on_defined(mod, name, class_method: class_method)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def on_removed(mod, name, class_method:)
|
|
75
|
+
@installer.on_removed(mod, name, class_method: class_method)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def visibility_changed(mod)
|
|
79
|
+
@installer.resync(mod)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def wrapped_original(method)
|
|
83
|
+
return nil unless wraps?(method.owner)
|
|
84
|
+
|
|
85
|
+
@installer.own_beneath(method) || @installer.last_original(method.owner, method.name)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def never_wrapped = @installer.never_wrapped
|
|
89
|
+
|
|
90
|
+
def wraps?(mod) = !@installer.nil? && @installer.wraps?(mod)
|
|
91
|
+
|
|
92
|
+
def unwrapped(bodies)
|
|
93
|
+
Failsafe.attempt(bodies) { bodies.map { |body| (wrapped_original(body) if method_object?(body)) || body } }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def method_object?(object)
|
|
97
|
+
# rubocop:disable Style/CaseEquality -- host object: is_a? would be a message sent to it
|
|
98
|
+
Method === object || UnboundMethod === object
|
|
99
|
+
# rubocop:enable Style/CaseEquality
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def pause_discovery
|
|
103
|
+
@installer&.pause
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def resume_discovery
|
|
107
|
+
@installer&.resume
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def stats
|
|
111
|
+
info = { running: enabled? }
|
|
112
|
+
info.merge!(Native.stats) if Native.loaded?
|
|
113
|
+
info.merge!(@recorder.stats) if @recorder
|
|
114
|
+
info.merge(Failsafe.stats)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def record_before_native(id, receiver, args, kwargs, depth = NATIVE_OFFSET)
|
|
118
|
+
return nil unless enabled?
|
|
119
|
+
|
|
120
|
+
@recorder.before(id, receiver, args, kwargs, depth)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def record_finish(token, error, result)
|
|
124
|
+
@recorder.finish(token, error, result)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def record_exit
|
|
128
|
+
@recorder.exit_tree
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def activate(tier, builders)
|
|
134
|
+
Installer.watch_builders(builders, @installer)
|
|
135
|
+
@installer.install
|
|
136
|
+
visibility_sync.enable
|
|
137
|
+
@enabled = true
|
|
138
|
+
start_wrapper(tier)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "runtime_analysis/version"
|
|
4
|
+
require_relative "runtime_analysis/errors"
|
|
5
|
+
require_relative "runtime_analysis/platform"
|
|
6
|
+
require_relative "runtime_analysis/failsafe"
|
|
7
|
+
require_relative "runtime_analysis/recording"
|
|
8
|
+
require_relative "runtime_analysis/native"
|
|
9
|
+
require_relative "runtime_analysis/trace"
|
|
10
|
+
require_relative "runtime_analysis/recording/sink"
|
|
11
|
+
require_relative "runtime_analysis/host"
|
|
12
|
+
|
|
13
|
+
# no-unit-test: entry-point module + public API, covered by lib/runtime_analysis_spec.rb
|
|
14
|
+
module RuntimeAnalysis
|
|
15
|
+
class Error < StandardError; end
|
|
16
|
+
|
|
17
|
+
Middleware ||= Host.middleware
|
|
18
|
+
Web ||= Host.web
|
|
19
|
+
|
|
20
|
+
class << self
|
|
21
|
+
def configure
|
|
22
|
+
yield configuration if block_given?
|
|
23
|
+
configuration
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def configuration
|
|
27
|
+
@configuration ||= Trace.configuration
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def start!
|
|
31
|
+
return if running? || Failsafe.off?
|
|
32
|
+
|
|
33
|
+
configuration.check!
|
|
34
|
+
@logger = Recording.open(configuration)
|
|
35
|
+
start_tracing
|
|
36
|
+
@running = true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def start_tracing
|
|
40
|
+
Host.install_job_runners if configuration.errors_only
|
|
41
|
+
Trace.start_configured(configuration, @logger)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def follow(framework)
|
|
45
|
+
Host.follow(framework)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def finish!
|
|
49
|
+
return unless running?
|
|
50
|
+
|
|
51
|
+
@running = false
|
|
52
|
+
Failsafe.attempt { close_recording }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def finish_at_exit
|
|
56
|
+
at_exit { finish! }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def close_recording
|
|
60
|
+
Trace.stop
|
|
61
|
+
Recording.close(configuration, @logger, Trace.registry.files, Trace.seen)
|
|
62
|
+
Recording.never_wrapped(configuration, Trace.never_wrapped)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def running?
|
|
66
|
+
@running == true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def stats
|
|
70
|
+
Trace.stats
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def pause_discovery
|
|
74
|
+
Trace.pause_discovery
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def resume_discovery
|
|
78
|
+
Trace.resume_discovery
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def entry_point
|
|
82
|
+
Trace.entry_point
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def entry_point=(identity)
|
|
86
|
+
Trace.entry_point = identity
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def with_entry_point(identity, &)
|
|
90
|
+
Trace.with_entry_point(identity, &)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def with_entry_point_unless_set(identity, &)
|
|
94
|
+
entry_point ? with_inner_entry(identity, &) : with_entry_point(identity, &)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def inner_entry
|
|
98
|
+
Trace.inner_entry
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def with_inner_entry(identity, &)
|
|
102
|
+
Trace.with_inner_entry(identity, &)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def request(identity = nil, &)
|
|
106
|
+
Trace.request(identity, &)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def job(identity = nil, &)
|
|
110
|
+
request(identity) { Host.remembering(&) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def reported(error, &)
|
|
114
|
+
Host.reported(error, &)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def keep_request
|
|
118
|
+
Trace.keep_request
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def nil_origin(error)
|
|
122
|
+
Trace.nil_origin(error)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|