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,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Index
|
|
6
|
+
class Reading
|
|
7
|
+
class Values
|
|
8
|
+
UNPRINTED = [false, 0].freeze
|
|
9
|
+
PRINTED_ARGS = 16
|
|
10
|
+
ROLES = { 0 => :received, 1 => :argument, 2 => :keyword, 3 => :returned }.freeze
|
|
11
|
+
|
|
12
|
+
attr_reader :receiver, :args, :kwargs, :return
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@receiver = UNPRINTED
|
|
16
|
+
@args = []
|
|
17
|
+
@kwargs = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def set(role, key, print)
|
|
21
|
+
setter = ROLES[role]
|
|
22
|
+
__send__(setter, key, print) if setter
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def received(_key, print)
|
|
28
|
+
@receiver = print
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def keyword(name, print)
|
|
32
|
+
kwargs << [name, print]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def returned(_key, print)
|
|
36
|
+
@return = print
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def argument(position, print)
|
|
40
|
+
return unless (0...PRINTED_ARGS).cover?(position)
|
|
41
|
+
|
|
42
|
+
args[position] = print
|
|
43
|
+
args.map! { |each| each || UNPRINTED }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/recording"
|
|
4
|
+
require_relative "reading/frame"
|
|
5
|
+
require_relative "reading/path"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Query
|
|
9
|
+
module Index
|
|
10
|
+
class Reading
|
|
11
|
+
Arg = Struct.new(:klass, :oid)
|
|
12
|
+
Call = Struct.new(:uuid, :step, :call_file, :call_line, :container, :callee,
|
|
13
|
+
:tier, :argc, :receiver_oid, :args, :path, :inferred, keyword_init: true)
|
|
14
|
+
Return = Struct.new(:uuid, :step, :klass, :oid, :elements, keyword_init: true)
|
|
15
|
+
Kwarg = Struct.new(:name, :klass, :oid)
|
|
16
|
+
Kwargs = Struct.new(:uuid, :step, :tier, :kw_argc, :kwargs, keyword_init: true)
|
|
17
|
+
Unwind = Struct.new(:uuid, :step, :klass, :file, :line, :missing, :receiver, keyword_init: true)
|
|
18
|
+
Entry = Struct.new(:uuid, :identity, keyword_init: true)
|
|
19
|
+
InnerEntry = Struct.new(:uuid, :identity, keyword_init: true)
|
|
20
|
+
Value = Struct.new(:uuid, :step, :role, :key, :print, keyword_init: true)
|
|
21
|
+
Answered = Struct.new(:uuid, :step, :name, keyword_init: true)
|
|
22
|
+
|
|
23
|
+
KINDS = { arg: Arg, call: Call, return: Return, kwarg: Kwarg, kwargs: Kwargs, unwind: Unwind, entry: Entry,
|
|
24
|
+
inner_entry: InnerEntry, value: Value, answered: Answered, frame: Frame }.freeze
|
|
25
|
+
UNKNOWN_PATH = Path.new(nil, nil, Frame.new("", false, "", "", nil), "", nil)
|
|
26
|
+
|
|
27
|
+
attr_reader :streams, :runs
|
|
28
|
+
|
|
29
|
+
def self.load(dir)
|
|
30
|
+
new(dir)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.row(kind, *, **) = KINDS.fetch(kind).new(*, **)
|
|
34
|
+
def self.segments(dir) = Stream.native_streams(dir).flat_map(&:paths)
|
|
35
|
+
def self.trees(rows) = rows.reduce(TreeBuilder.new, :<<).trees
|
|
36
|
+
|
|
37
|
+
def initialize(dir)
|
|
38
|
+
@dir = dir
|
|
39
|
+
@streams = Stream.discover(dir)
|
|
40
|
+
@runs = Recording.runs(dir)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def trees
|
|
44
|
+
@trees ||= recorded.reject { |tree| reruns.superseded?(tree) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def superseded = recorded.size - trees.size
|
|
48
|
+
|
|
49
|
+
def declared = Declared.newest(@dir, runs)
|
|
50
|
+
|
|
51
|
+
def errors_only?
|
|
52
|
+
segments = streams.flat_map(&:paths)
|
|
53
|
+
segments.any? && segments.all? { |segment| Stream.held?(segment) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def spec_trees = trees.select(&:spec?)
|
|
57
|
+
def run_trees = trees.select(&:run?)
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def recorded
|
|
62
|
+
@recorded ||= streams.flat_map { |stream| build(stream) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def reruns
|
|
66
|
+
@reruns ||= Reruns.new(recorded)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def build(stream)
|
|
70
|
+
Reading.trees(stream.to_enum(:each_row)).each { |tree| tree.run = runs[tree.pid] }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
require_relative "reading/stream"
|
|
78
|
+
require_relative "reading/tree_builder"
|
|
79
|
+
require_relative "reading/reruns"
|
|
80
|
+
require_relative "reading/declared"
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "graph"
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Index
|
|
8
|
+
class Shapes
|
|
9
|
+
Shape = Struct.new(:classes, :messages, :elements, :keys, :spec_calls, :run_calls, :senders, :inferred,
|
|
10
|
+
keyword_init: true)
|
|
11
|
+
|
|
12
|
+
class Shape
|
|
13
|
+
def calls = spec_calls + run_calls
|
|
14
|
+
def nil_count = classes.fetch("NilClass", 0)
|
|
15
|
+
def message_names = messages.keys
|
|
16
|
+
def class_names = classes.keys
|
|
17
|
+
def empty? = classes.empty?
|
|
18
|
+
|
|
19
|
+
def merge(other)
|
|
20
|
+
inside = %i[elements keys].to_h { |part| [part, held(other, part)] }
|
|
21
|
+
self.class.new(**tallies(other), **counts(other), **inside, inferred: inferred && other.inferred)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def held(other, part) = [self[part], other[part]].compact.reduce(:merge)
|
|
25
|
+
|
|
26
|
+
def tallies(other)
|
|
27
|
+
%i[classes messages senders].to_h do |part|
|
|
28
|
+
[part, self[part].to_h.merge(other[part].to_h) { |_, here, there| here + there }]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def counts(other)
|
|
33
|
+
{ spec_calls: spec_calls + other.spec_calls, run_calls: run_calls + other.run_calls }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.classes_only(graph) = new(graph, messages: false)
|
|
38
|
+
def self.shape(**) = Shape.new(**)
|
|
39
|
+
|
|
40
|
+
def initialize(graph, messages: true)
|
|
41
|
+
@graph = graph
|
|
42
|
+
@messages = messages
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def return_shape(identity) = returns_of(@graph.nodes_of(identity))
|
|
46
|
+
def argument_shape(identity, position) = arguments_of(@graph.nodes_of(identity), position)
|
|
47
|
+
def kwarg_shape(identity, name) = keywords_of(@graph.nodes_of(identity), name)
|
|
48
|
+
|
|
49
|
+
def returns_of(nodes)
|
|
50
|
+
returned = nodes.select(&:returned?)
|
|
51
|
+
shape(returned, &:return).tap { |result| result.elements = element_shape(returned) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def arguments_of(nodes, position)
|
|
55
|
+
given(nodes) { |node| node.call.args.at(position) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def keywords_of(nodes, name)
|
|
59
|
+
given(nodes) { |node| kwarg(node, name) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def receivers_of(nodes)
|
|
63
|
+
result = empty_shape
|
|
64
|
+
sent_to_instances(nodes).each { |node| tally(result, node, node.callee.klass, received(node)) }
|
|
65
|
+
result
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def messages_to(tree, oid, after:, before: nil)
|
|
69
|
+
return [] if oid.nil? || oid.zero?
|
|
70
|
+
|
|
71
|
+
tree.nodes.select { |node| node.call.receiver_oid == oid && within?(node.step, after, before) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def sent_to_instances(nodes)
|
|
77
|
+
nodes.reject { |node| node.callee.class_method }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def given(nodes, &value)
|
|
81
|
+
shape(nodes.select(&value), inside: true, &value)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def received(node) = messages_for(node, node.call.receiver_oid, false)
|
|
85
|
+
|
|
86
|
+
def within?(step, after, before)
|
|
87
|
+
step > after && (before.nil? || step <= before)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def shape(nodes, inside: false, &value)
|
|
91
|
+
result = empty_shape
|
|
92
|
+
nodes.each { |node| add(result, node, value.call(node), inside) }
|
|
93
|
+
result
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def add(result, node, value, inside)
|
|
97
|
+
tally(result, node, value.klass, messages_for(node, value.oid, inside))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def element_shape(returned)
|
|
101
|
+
result = empty_shape
|
|
102
|
+
returned.each do |node|
|
|
103
|
+
node.return.elements.each { |el| tally(result, node, el.klass, messages_for(node, el.oid, false)) }
|
|
104
|
+
end
|
|
105
|
+
result
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def messages_for(node, oid, inside)
|
|
109
|
+
return [] unless @messages
|
|
110
|
+
|
|
111
|
+
return messages_to(node.tree, oid, after: node.last_step) unless inside
|
|
112
|
+
|
|
113
|
+
messages_to(node.tree, oid, after: node.step, before: node.last_step)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def tally(result, node, klass, messages)
|
|
117
|
+
result.classes[klass] += 1
|
|
118
|
+
messages.each { |message| sent(result, message) }
|
|
119
|
+
count_origin(result, node)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def sent(result, message)
|
|
123
|
+
result.messages[message.callee.name] += 1
|
|
124
|
+
result.senders[[message.callee.identity, message.container.identity]] += 1
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def count_origin(result, node)
|
|
128
|
+
node.tree.spec? ? result.spec_calls += 1 : result.run_calls += 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def empty_shape
|
|
132
|
+
Shape.new(classes: Hash.new(0), messages: Hash.new(0), senders: Hash.new(0), spec_calls: 0,
|
|
133
|
+
run_calls: 0)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def kwarg(node, name)
|
|
137
|
+
node.kwargs&.kwargs&.find { |kw| kw.name == name }
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Index
|
|
6
|
+
class Signatures
|
|
7
|
+
module ActiveSupport
|
|
8
|
+
STRING = %w[camelize camelcase underscore titleize titlecase humanize pluralize singularize dasherize
|
|
9
|
+
parameterize classify demodulize deconstantize tableize foreign_key squish truncate
|
|
10
|
+
strip_heredoc upcase_first downcase_first indent].freeze
|
|
11
|
+
DURATION = %w[second seconds minute minutes hour hours day days week weeks fortnight fortnights
|
|
12
|
+
month months year years].freeze
|
|
13
|
+
HASH = %w[symbolize_keys stringify_keys deep_symbolize_keys deep_stringify_keys deep_merge
|
|
14
|
+
reverse_merge deep_dup compact_blank].freeze
|
|
15
|
+
|
|
16
|
+
RETURNS = {
|
|
17
|
+
"String" => STRING.to_h { |name| [name, ["String"]] },
|
|
18
|
+
"Numeric" => DURATION.to_h { |name| [name, ["ActiveSupport::Duration"]] },
|
|
19
|
+
"Hash" => HASH.to_h { |name| [name, ["Hash"]] }
|
|
20
|
+
.merge("with_indifferent_access" => ["ActiveSupport::HashWithIndifferentAccess"]),
|
|
21
|
+
"Object" => { "blank?" => ["bool"], "present?" => ["bool"], "in?" => ["bool"],
|
|
22
|
+
"presence" => %w[self nil], "to_json" => ["String"], "to_param" => ["String"],
|
|
23
|
+
"to_query" => ["String"] }
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
26
|
+
def self.returns = RETURNS
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|