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,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Recording
|
|
5
|
+
module RaiseIds
|
|
6
|
+
ABSENT = -1
|
|
7
|
+
|
|
8
|
+
def self.of(raised_at, missing)
|
|
9
|
+
file, line = raised_at
|
|
10
|
+
name, receiver = missing
|
|
11
|
+
[file, name, receiver].map { |string| string ? yield(string) : ABSENT }.insert(1, line || ABSENT)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require_relative "opcodes"
|
|
6
|
+
require_relative "raise_ids"
|
|
7
|
+
require "runtime_analysis/recording"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Recording
|
|
11
|
+
class RubySink
|
|
12
|
+
module Tails
|
|
13
|
+
MAX_ARGS = 16
|
|
14
|
+
KEYWORD_VALUE = 2
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def arg_tail(arg_classes, receiver_id, arg_ids)
|
|
19
|
+
return tier3_tail(arg_classes.to_a, receiver_id, arg_ids) if receiver_id
|
|
20
|
+
return if arg_classes.nil? || arg_classes.empty?
|
|
21
|
+
|
|
22
|
+
[2, arg_classes.size, *arg_classes.first(MAX_ARGS).map { |name| intern(name) }]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def tier3_tail(classes, receiver_id, arg_ids)
|
|
26
|
+
kept = classes.first(MAX_ARGS).each_with_index.flat_map { |name, at| [intern(name), arg_ids.fetch(at)] }
|
|
27
|
+
[3, classes.size, receiver_id, *kept]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def kwarg_entries(kwarg_classes, kwarg_ids)
|
|
31
|
+
kwarg_classes.first(MAX_ARGS).flat_map do |name, klass|
|
|
32
|
+
pair = [intern(name), intern(klass)]
|
|
33
|
+
kwarg_ids ? pair << kwarg_ids.fetch(name) : pair
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def element_tail(elements)
|
|
38
|
+
return unless elements
|
|
39
|
+
|
|
40
|
+
count, pairs = elements
|
|
41
|
+
[count, *pairs.first(MAX_ARGS).flat_map { |name, id| [intern(name), id] }]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
include Opcodes
|
|
46
|
+
include Tails
|
|
47
|
+
|
|
48
|
+
FILE = "query_parameters.json"
|
|
49
|
+
FLUSH_EVERY = 100
|
|
50
|
+
|
|
51
|
+
def initialize(recording_dir)
|
|
52
|
+
@path = File.join(recording_dir, FILE)
|
|
53
|
+
@dict = {}
|
|
54
|
+
@defined = Set.new
|
|
55
|
+
@unflushed = 0
|
|
56
|
+
@mutex = Mutex.new
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# rubocop:disable Metrics/ParameterLists -- hot path: a row object would be allocated for every recorded call
|
|
60
|
+
def log_call(stack_uuid:, step:, path:, call_file:, call_line:, arg_classes: nil, receiver_id: nil, arg_ids: nil)
|
|
61
|
+
record do
|
|
62
|
+
[CALL, tree(stack_uuid), step, route(path), intern(call_file), call_line || -1,
|
|
63
|
+
*arg_tail(arg_classes, receiver_id, arg_ids)]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
# rubocop:enable Metrics/ParameterLists
|
|
67
|
+
|
|
68
|
+
def log_return(stack_uuid:, step:, return_class:, return_id:, elements: nil)
|
|
69
|
+
record { [RETURN, tree(stack_uuid), step, intern(return_class), return_id, *element_tail(elements)] }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def log_kwargs(stack_uuid:, step:, kwarg_classes:, kwarg_ids: nil)
|
|
73
|
+
record do
|
|
74
|
+
[KWARGS, tree(stack_uuid), step, kwarg_ids ? 3 : 2, kwarg_classes.size,
|
|
75
|
+
*kwarg_entries(kwarg_classes, kwarg_ids)]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def log_unwind(stack_uuid:, step:, exception_class:, raised_at: nil, missing: nil)
|
|
80
|
+
record do
|
|
81
|
+
[UNWIND, tree(stack_uuid), step, intern(exception_class),
|
|
82
|
+
*RaiseIds.of(raised_at, missing) { |string| intern(string) }]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def log_entry(stack_uuid:, entry_point:)
|
|
87
|
+
record { [ENTRY, tree(stack_uuid), intern(entry_point)] }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def log_inner_entry(stack_uuid:, identity:)
|
|
91
|
+
record { [INNER_ENTRY, tree(stack_uuid), intern(identity)] }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def log_answered(stack_uuid:, step:, name:)
|
|
95
|
+
record { [ANSWERED, tree(stack_uuid), step, intern(name)] }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# rubocop:disable Metrics/ParameterLists -- hot path: a row object would be allocated for every probed value
|
|
99
|
+
def log_value(stack_uuid:, step:, role:, key:, how:, print:)
|
|
100
|
+
record { [VALUE, tree(stack_uuid), step, role, role == KEYWORD_VALUE ? intern(key) : key, how, print] }
|
|
101
|
+
end
|
|
102
|
+
# rubocop:enable Metrics/ParameterLists
|
|
103
|
+
|
|
104
|
+
def finish!
|
|
105
|
+
@mutex.synchronize { close if @file }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
def tree(number) = "#{Process.pid}-#{number}"
|
|
111
|
+
|
|
112
|
+
def route(path)
|
|
113
|
+
define(path) if undefined?(path)
|
|
114
|
+
path.id
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def define(path)
|
|
118
|
+
define(path.parent) if undefined?(path.parent)
|
|
119
|
+
@defined << path.id
|
|
120
|
+
write path_row(path)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def undefined?(path) = path && !@defined.include?(path.id)
|
|
124
|
+
|
|
125
|
+
def path_row(path)
|
|
126
|
+
[PATH, path.id, path.parent&.id || 0, *frame_fields(path.frame), intern(path.call_file), path.call_line || -1]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def frame_fields((klass, name, file, line, class_method))
|
|
130
|
+
[intern(klass), class_method, intern(name), intern(file), line || -1]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def intern(string)
|
|
134
|
+
@dict.fetch(string) { intern_new(string) }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def intern_new(string)
|
|
138
|
+
id = @dict.size
|
|
139
|
+
@dict[string] = id
|
|
140
|
+
write [DICT, id, string]
|
|
141
|
+
id
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def close
|
|
145
|
+
@file.close
|
|
146
|
+
@file = nil
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def write(row)
|
|
150
|
+
file.puts JSON.dump(row)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def record
|
|
154
|
+
@mutex.synchronize do
|
|
155
|
+
write yield
|
|
156
|
+
@unflushed += 1
|
|
157
|
+
flush unless @unflushed < FLUSH_EVERY
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def flush
|
|
162
|
+
file.flush
|
|
163
|
+
@unflushed = 0
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def file
|
|
167
|
+
@file ||= open_file
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def open_file
|
|
171
|
+
FileUtils.mkdir_p(File.dirname(@path))
|
|
172
|
+
File.new(@path, "a").tap { |f| f.puts JSON.dump(Recording.format_header) }
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "socket"
|
|
6
|
+
require "time"
|
|
7
|
+
require_relative "source_blob"
|
|
8
|
+
require "runtime_analysis/version"
|
|
9
|
+
require_relative "format"
|
|
10
|
+
require "runtime_analysis/errors"
|
|
11
|
+
require "runtime_analysis/platform"
|
|
12
|
+
|
|
13
|
+
module RuntimeAnalysis
|
|
14
|
+
module Recording
|
|
15
|
+
module RunManifest
|
|
16
|
+
Run = Struct.new(:pid, :environment, :label, :probe, :started_at, :ended_at, :hostname, :git_sha, :tier,
|
|
17
|
+
:adaptive, :recorder, :trees, :entry_points, :run_entry_points, :entry_points_capped, :sources,
|
|
18
|
+
keyword_init: true)
|
|
19
|
+
|
|
20
|
+
GEM = File.expand_path("../../..", __dir__)
|
|
21
|
+
GEMSPEC = ":./runtime_analysis.gemspec"
|
|
22
|
+
ENVIRONMENTS = %w[RAILS_ENV RACK_ENV APP_ENV].freeze
|
|
23
|
+
|
|
24
|
+
LISTED = 50
|
|
25
|
+
|
|
26
|
+
module_function
|
|
27
|
+
|
|
28
|
+
def write(config, pid: Process.pid, now: Time.now)
|
|
29
|
+
FileUtils.mkdir_p(config.recording_dir)
|
|
30
|
+
File.write(path(config.recording_dir, pid), JSON.generate(fields(config, pid, now)))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def fields(config, pid, now)
|
|
34
|
+
{ pid: pid, environment: environment(config), label: config.label, probe: config.probe,
|
|
35
|
+
started_at: now.utc.iso8601, hostname: Socket.gethostname, git_sha: git_sha, tier: config.tier,
|
|
36
|
+
adaptive: config.adaptive ? true : false, recorder: recorder }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def environment(config)
|
|
40
|
+
config.environment || ENV.values_at(*ENVIRONMENTS).compact.first || ("test" if test_frameworks.any?)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_frameworks
|
|
44
|
+
[defined?(::RSpec.configure), Object.const_defined?("Minitest::Test")]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def recorder(gem = GEM)
|
|
48
|
+
{ version: VERSION, sha: git("-C", gem, "rev-parse", "HEAD", GEMSPEC)&.lines&.first&.chomp,
|
|
49
|
+
format: Format.meaning }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def pin(config, files, pid: Process.pid)
|
|
53
|
+
add(config, pid, "sources" => blobs(files))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def seen(config, tally, pid: Process.pid, now: Time.now)
|
|
57
|
+
add(config, pid, tally.to_h.merge("environment" => environment(config), "ended_at" => now.utc.iso8601))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def never_wrapped(config, methods, pid: Process.pid)
|
|
61
|
+
add(config, pid, "never_wrapped" => { "count" => methods.size, "methods" => methods.first(LISTED) })
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def add(config, pid, fields)
|
|
65
|
+
file = path(config.recording_dir, pid)
|
|
66
|
+
replace(file, JSON.generate(said(config, file, pid).merge(fields)))
|
|
67
|
+
rescue SystemCallError, Errors.unreadable_json
|
|
68
|
+
nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def said(config, file, pid)
|
|
72
|
+
JSON.parse(File.read(file))
|
|
73
|
+
rescue Errors.missing_file
|
|
74
|
+
fields(config, pid, Time.now).transform_keys(&:to_s)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def replace(file, content)
|
|
78
|
+
File.write("#{file}.new", content)
|
|
79
|
+
File.rename("#{file}.new", file)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def blobs(files)
|
|
83
|
+
files.filter_map { |source| (blob = SourceBlob.of(source)) && [source, blob] }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def run(**fields) = Run.new(**fields)
|
|
87
|
+
|
|
88
|
+
def read_all(dir)
|
|
89
|
+
Dir.glob(File.join(dir, "run.*.json")).to_h do |file|
|
|
90
|
+
fields = JSON.parse(File.read(file), symbolize_names: true)
|
|
91
|
+
run = Run.new(**fields.slice(*Run.members), sources: fields[:sources].to_h)
|
|
92
|
+
[run.pid, run]
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def path(dir, pid)
|
|
97
|
+
File.join(dir, format("run.%d.json", pid))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def git_sha = git("rev-parse", "HEAD")&.chomp
|
|
101
|
+
|
|
102
|
+
def git(*command)
|
|
103
|
+
said = IO.popen(["git", *command], err: Platform.discard, &:read)
|
|
104
|
+
said if Process.last_status.success?
|
|
105
|
+
rescue SystemCallError
|
|
106
|
+
nil
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through seen_spec.rb, which counts nothing through Seen.nothing.
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Recording
|
|
7
|
+
class Seen
|
|
8
|
+
class Nothing
|
|
9
|
+
def tree(_entry_point); end
|
|
10
|
+
|
|
11
|
+
def to_h = {}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through seen_spec.rb, which counts trees through Seen.
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Recording
|
|
7
|
+
class Seen
|
|
8
|
+
class Tally
|
|
9
|
+
SPEC_ENTRY = %r{\A(\./)?(spec|test)/|_(spec|test)\.rb:\d+\z}
|
|
10
|
+
|
|
11
|
+
def initialize(limit)
|
|
12
|
+
@trees = { "spec" => 0, "run" => 0, "unknown" => 0 }
|
|
13
|
+
@entry_points = Hash.new(0)
|
|
14
|
+
@capped = false
|
|
15
|
+
@limit = limit
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def tree(entry_point)
|
|
19
|
+
@trees[kind(entry_point)] += 1
|
|
20
|
+
keep(entry_point) if entry_point
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_h
|
|
24
|
+
{ "trees" => @trees.dup, "entry_points" => @entry_points.size, "run_entry_points" => runs,
|
|
25
|
+
"entry_points_capped" => @capped }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def keep(entry_point)
|
|
31
|
+
return @capped = true unless @entry_points.key?(entry_point) || @entry_points.size < @limit
|
|
32
|
+
|
|
33
|
+
@entry_points[entry_point] += 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def kind(entry_point)
|
|
37
|
+
return "unknown" unless entry_point
|
|
38
|
+
|
|
39
|
+
SPEC_ENTRY.match?(entry_point) ? "spec" : "run"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def runs
|
|
43
|
+
@entry_points.reject { |entry_point, _| SPEC_ENTRY.match?(entry_point) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/platform"
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Recording
|
|
7
|
+
class Seen
|
|
8
|
+
ENTRY_POINTS_A_LONG_LIVED_SERVER_MAY_KEEP = 10_000
|
|
9
|
+
SECONDS_BETWEEN_REPORTS = 60
|
|
10
|
+
|
|
11
|
+
def self.nothing = Nothing.new
|
|
12
|
+
|
|
13
|
+
def initialize(limit: ENTRY_POINTS_A_LONG_LIVED_SERVER_MAY_KEEP, every: SECONDS_BETWEEN_REPORTS,
|
|
14
|
+
lock: Mutex.new, clock: Platform.public_method(:monotonic_seconds), &report)
|
|
15
|
+
@limit = limit
|
|
16
|
+
@lock = lock
|
|
17
|
+
@report = report
|
|
18
|
+
wait(every, clock)
|
|
19
|
+
count_for(Process.pid)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def tree(entry_point)
|
|
23
|
+
@report&.call(self) if @lock.synchronize { due_after(entry_point) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_h
|
|
27
|
+
@lock.synchronize { @tally.to_h }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def wait(every, clock)
|
|
33
|
+
@every = every
|
|
34
|
+
@clock = clock
|
|
35
|
+
@due = clock.call + every
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def count_for(pid)
|
|
39
|
+
@pid = pid
|
|
40
|
+
@tally = Tally.new(@limit)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def due_after(entry_point)
|
|
44
|
+
forked = forked?
|
|
45
|
+
@tally.tree(entry_point)
|
|
46
|
+
forked || due?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def forked?
|
|
50
|
+
pid = Process.pid
|
|
51
|
+
!pid.equal?(@pid) && count_for(pid)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def due?
|
|
55
|
+
now = @clock.call
|
|
56
|
+
now >= @due && (@due = now + @every)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
require_relative "seen/tally"
|
|
63
|
+
require_relative "seen/nothing"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/native"
|
|
4
|
+
require_relative "ruby_sink"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Recording
|
|
8
|
+
module Sink
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def build(config)
|
|
12
|
+
return RubySink.new(config.recording_dir) if config.mechanism == :pure
|
|
13
|
+
|
|
14
|
+
Native.logger(recording_dir: config.recording_dir, rotate: config.rotate, retain: config.retain,
|
|
15
|
+
hold: config.errors_only ? true : false, ring: config.ring)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through recording_spec.rb and run_manifest_spec.rb, which pin sources by blob id.
|
|
4
|
+
|
|
5
|
+
require_relative "blob"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Recording
|
|
9
|
+
module SourceBlob
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def of(path)
|
|
13
|
+
content = File.binread(path)
|
|
14
|
+
Blob.id(content)
|
|
15
|
+
rescue SystemCallError
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: recording/recording_spec.rb asserts the facade; the root has no room for it beside this file
|
|
4
|
+
|
|
5
|
+
require_relative "recording/blob"
|
|
6
|
+
require_relative "recording/format"
|
|
7
|
+
require_relative "recording/opcodes"
|
|
8
|
+
require_relative "recording/raise_ids"
|
|
9
|
+
require_relative "recording/run_manifest"
|
|
10
|
+
require_relative "recording/seen"
|
|
11
|
+
|
|
12
|
+
module RuntimeAnalysis
|
|
13
|
+
module Recording
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def open(configuration)
|
|
17
|
+
Sink.build(configuration).tap { RunManifest.write(configuration) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def close(configuration, logger, files, seen)
|
|
21
|
+
logger.finish!
|
|
22
|
+
RunManifest.pin(configuration, files)
|
|
23
|
+
RunManifest.seen(configuration, seen)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def seen(configuration)
|
|
27
|
+
return Seen.nothing if configuration.errors_only
|
|
28
|
+
|
|
29
|
+
Seen.new { |tally| RunManifest.seen(configuration, tally) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def unreported = Seen.new
|
|
33
|
+
|
|
34
|
+
def never_wrapped(configuration, methods) = RunManifest.never_wrapped(configuration, methods)
|
|
35
|
+
|
|
36
|
+
def runs(dir) = RunManifest.read_all(dir)
|
|
37
|
+
|
|
38
|
+
def run(**fields) = RunManifest.run(**fields)
|
|
39
|
+
|
|
40
|
+
def opcode(name) = Opcodes.fetch(name)
|
|
41
|
+
|
|
42
|
+
def check_format(version) = Format.check(version)
|
|
43
|
+
|
|
44
|
+
def newer_format = Format.newer
|
|
45
|
+
|
|
46
|
+
def format_header = Format.header
|
|
47
|
+
|
|
48
|
+
def blob_id(content) = Blob.id(content)
|
|
49
|
+
|
|
50
|
+
def raise_ids = RaiseIds
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module RubyParsing
|
|
5
|
+
module Packages
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def installed(name) = Gem::Specification.stubs_for(name)
|
|
9
|
+
|
|
10
|
+
def satisfying?(version, wanted) = Gem::Requirement.new(wanted).satisfied_by?(version)
|
|
11
|
+
|
|
12
|
+
def specification(name, version, &) = Gem::Specification.new(name, version, &)
|
|
13
|
+
|
|
14
|
+
def specification_at(path) = Gem::Specification.load(path)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "ruby_parsing/packages"
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module RubyParsing
|
|
7
|
+
CONSTANTS = %i[constant_read_node constant_path_node].freeze
|
|
8
|
+
DYNAMIC_PART = :DynamicPartsInConstantPathError
|
|
9
|
+
PRISM_1_UNWRITTEN_PART = :MissingNodesInConstantPathError
|
|
10
|
+
PRISM_2_UNWRITTEN_PART = :ErrorRecoveryNodesInConstantPathError
|
|
11
|
+
UNREADABLE_PATHS = [DYNAMIC_PART, PRISM_1_UNWRITTEN_PART, PRISM_2_UNWRITTEN_PART].freeze
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def available?
|
|
15
|
+
defined?(Prism) ? true : chosen? && require("prism")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def tree_of(text, **) = parser.parse(text, **).value
|
|
19
|
+
|
|
20
|
+
def tree_of_file(path) = parser.parse_file(path).value
|
|
21
|
+
|
|
22
|
+
def errors_in(text) = parser.parse(text).errors
|
|
23
|
+
|
|
24
|
+
def visitor = parser.const_get(:Visitor)
|
|
25
|
+
|
|
26
|
+
def kind(node) = node&.type
|
|
27
|
+
|
|
28
|
+
def kinds(*names)
|
|
29
|
+
unknown = names.reject { |name| kind?(name) }
|
|
30
|
+
raise ArgumentError, "no kind of node: #{unknown.join(", ")}" unless unknown.empty?
|
|
31
|
+
|
|
32
|
+
names.freeze
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def by_kind(table)
|
|
36
|
+
kinds(*table.keys)
|
|
37
|
+
table.freeze
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def call?(node) = kind(node) == :call_node
|
|
41
|
+
|
|
42
|
+
def definition?(node) = kind(node) == :def_node
|
|
43
|
+
|
|
44
|
+
def symbol?(node) = kind(node) == :symbol_node
|
|
45
|
+
|
|
46
|
+
def block?(node) = kind(node) == :block_node
|
|
47
|
+
|
|
48
|
+
def statements?(node) = kind(node) == :statements_node
|
|
49
|
+
|
|
50
|
+
def array?(node) = kind(node) == :array_node
|
|
51
|
+
|
|
52
|
+
def self?(node) = kind(node) == :self_node
|
|
53
|
+
|
|
54
|
+
def nil_literal?(node) = kind(node) == :nil_node
|
|
55
|
+
|
|
56
|
+
def keyword_hash?(node) = kind(node) == :keyword_hash_node
|
|
57
|
+
|
|
58
|
+
def pair?(node) = kind(node) == :assoc_node
|
|
59
|
+
|
|
60
|
+
def constant?(node) = CONSTANTS.include?(kind(node))
|
|
61
|
+
|
|
62
|
+
def bare_call?(node, names)
|
|
63
|
+
call?(node) && node.receiver.nil? && names.include?(node.name)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def full_name(node)
|
|
67
|
+
node.full_name if constant?(node)
|
|
68
|
+
rescue *unreadable_paths
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def specification(name, version, &) = Packages.specification(name, version, &)
|
|
73
|
+
|
|
74
|
+
def specification_at(path) = Packages.specification_at(path)
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def parser
|
|
79
|
+
require "prism" unless defined?(Prism)
|
|
80
|
+
Prism
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def chosen?
|
|
84
|
+
Gem.loaded_specs.key?("prism") || Packages.installed("prism").one?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def kind?(name)
|
|
88
|
+
constant = name.to_s.split("_").map(&:capitalize).join
|
|
89
|
+
parser.const_defined?(constant, false) && parser.const_get(constant) < Prism::Node
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def unreadable_paths
|
|
93
|
+
path = Prism::ConstantPathNode
|
|
94
|
+
(path.constants & UNREADABLE_PATHS).map { |name| path.const_get(name) }
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through trace_spec.rb, which starts the tracer from a configuration.
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Trace
|
|
7
|
+
class Configuration
|
|
8
|
+
module Capturing
|
|
9
|
+
def capture(logger)
|
|
10
|
+
Capture.new(novelty: (Novelty.new if adaptive), tier: tier, builders: class_builders, mechanism: mechanism,
|
|
11
|
+
hold: hold(logger), probe: probe, seen: Recording.seen(self),
|
|
12
|
+
ivars: record_ivars ? true : false)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def called_names(inclusion)
|
|
16
|
+
return nil unless inclusion.gems?
|
|
17
|
+
|
|
18
|
+
Installer.called_names(included.map { |directory| File.expand_path(directory) })
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def hold(logger)
|
|
24
|
+
return nil unless errors_only
|
|
25
|
+
|
|
26
|
+
Failsafe.attempt { NilOrigin.configure(self) }
|
|
27
|
+
Hold.new(logger: logger, signal: error_signal, warn_untold: true)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|