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,304 @@
|
|
|
1
|
+
#include "sink.h"
|
|
2
|
+
#include <errno.h>
|
|
3
|
+
#include <poll.h>
|
|
4
|
+
#include <sched.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
#include <time.h>
|
|
9
|
+
#include <unistd.h>
|
|
10
|
+
|
|
11
|
+
/* A row as text. The writer thread turns each row it takes from the ring into one line of the
|
|
12
|
+
* recording: a JSON array of integers, led by the row's opcode. Calls, returns and keywords are
|
|
13
|
+
* formatted into the batch's buffer, and the rarer rows are written one at a time. Nothing here
|
|
14
|
+
* touches a Ruby object. */
|
|
15
|
+
|
|
16
|
+
static void write_json_string(FILE *f, const char *s, long len) {
|
|
17
|
+
fputc('"', f);
|
|
18
|
+
for (long i = 0; i < len; i++) {
|
|
19
|
+
unsigned char c = (unsigned char)s[i];
|
|
20
|
+
switch (c) {
|
|
21
|
+
case '"': fputs("\\\"", f); break;
|
|
22
|
+
case '\\': fputs("\\\\", f); break;
|
|
23
|
+
case '\b': fputs("\\b", f); break;
|
|
24
|
+
case '\f': fputs("\\f", f); break;
|
|
25
|
+
case '\n': fputs("\\n", f); break;
|
|
26
|
+
case '\r': fputs("\\r", f); break;
|
|
27
|
+
case '\t': fputs("\\t", f); break;
|
|
28
|
+
default:
|
|
29
|
+
if (c < 0x20) {
|
|
30
|
+
fprintf(f, "\\u%04x", c);
|
|
31
|
+
} else {
|
|
32
|
+
fputc(c, f);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
fputc('"', f);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* A negative length marks an interned nil (e.g. an anonymous class name): the offline logger writes
|
|
40
|
+
* JSON null for it, so we match that byte-for-byte rather than crash. */
|
|
41
|
+
void ra_write_dict(FILE *file, int64_t id, const char *string, long len) {
|
|
42
|
+
fprintf(file, "[0,%lld,", (long long)id);
|
|
43
|
+
if (len < 0) {
|
|
44
|
+
fputs("null", file);
|
|
45
|
+
} else {
|
|
46
|
+
write_json_string(file, string, len);
|
|
47
|
+
}
|
|
48
|
+
fputs("]\n", file);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static void consume_dict(sink *s, slot *sl) {
|
|
52
|
+
RA_GUARD(s, sl->dict_id >= 0, );
|
|
53
|
+
|
|
54
|
+
ra_write_dict(s->file, sl->dict_id, sl->dict_str.ptr, sl->dict_str.len);
|
|
55
|
+
free(sl->dict_str.ptr);
|
|
56
|
+
sl->dict_str.ptr = NULL;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void write_bool(FILE *f, int64_t v) { fputs(v ? "true" : "false", f); }
|
|
60
|
+
|
|
61
|
+
void ra_write_path(FILE *file, const int64_t *fields) {
|
|
62
|
+
fprintf(file, "[%d", OP_PATH);
|
|
63
|
+
for (int i = 0; i < PATH_FIELDS; i++) {
|
|
64
|
+
fputc(',', file);
|
|
65
|
+
if (i == F_PATH_CLASS_METHOD) {
|
|
66
|
+
write_bool(file, fields[i]);
|
|
67
|
+
} else {
|
|
68
|
+
fprintf(file, "%lld", (long long)fields[i]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
fputs("]\n", file);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* The digits of an integer, written at `at`. Returns where the next character goes. */
|
|
75
|
+
static char *put_int(char *at, int64_t value) {
|
|
76
|
+
char digits[20];
|
|
77
|
+
int count = 0;
|
|
78
|
+
uint64_t rest = value < 0 ? (uint64_t)0 - (uint64_t)value : (uint64_t)value;
|
|
79
|
+
if (value < 0) *at++ = '-';
|
|
80
|
+
do { digits[count++] = (char)('0' + rest % 10); rest /= 10; } while (rest);
|
|
81
|
+
while (count) *at++ = digits[--count];
|
|
82
|
+
return at;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static char *put_field(char *at, int64_t value) {
|
|
86
|
+
*at++ = ',';
|
|
87
|
+
return put_int(at, value);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Calls, returns and keywords are nearly all of what a recording holds, so their rows are formatted
|
|
91
|
+
* straight from the packed words, with no slot in between. The widest is a keywords row with MAX_ARGS
|
|
92
|
+
* keywords at tier 3: 53 integers of at most 21 characters each, so RA_ROW_TEXT_MAX bytes hold any of
|
|
93
|
+
* them. Each returns where the text ends, or NULL for a row whose tail makes no sense.
|
|
94
|
+
*
|
|
95
|
+
* A row's tail is its tier, the true count, the count stored, the receiver's id, and then the stored
|
|
96
|
+
* values' classes, their object ids and, in a keywords row, their names. */
|
|
97
|
+
static char *open_row(char *at, int op, const uint64_t *fields, int count) {
|
|
98
|
+
*at++ = '[';
|
|
99
|
+
at = put_int(at, op);
|
|
100
|
+
for (int i = 0; i < count; i++) at = put_field(at, (int64_t)fields[i]);
|
|
101
|
+
return at;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static char *close_row(char *at) {
|
|
105
|
+
*at++ = ']';
|
|
106
|
+
*at++ = '\n';
|
|
107
|
+
return at;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static int stored(const uint64_t *tail) {
|
|
111
|
+
int64_t argn = (int64_t)tail[2];
|
|
112
|
+
return (argn < 0 || argn > MAX_ARGS) ? -1 : (int)argn;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* [OP_CALL, tree, step, path, file, line], then at tier 2 the tier, the count and each class, and at
|
|
116
|
+
* tier 3 the tier, the count, the receiver's id and each class with its object id. */
|
|
117
|
+
static char *format_call(const uint64_t *row, char *at) {
|
|
118
|
+
at = open_row(at, OP_CALL, row + 1, CALL_FIELDS);
|
|
119
|
+
if (row[0] & RA_ROW_TAIL) {
|
|
120
|
+
const uint64_t *tail = row + 1 + CALL_FIELDS;
|
|
121
|
+
int64_t tier = (int64_t)tail[0];
|
|
122
|
+
int argn = stored(tail);
|
|
123
|
+
if ((tier != 2 && tier != 3) || argn < 0) return NULL;
|
|
124
|
+
at = put_field(put_field(at, tier), (int64_t)tail[1]);
|
|
125
|
+
if (tier == 3) at = put_field(at, (int64_t)tail[3]);
|
|
126
|
+
for (int i = 0; i < argn; i++) {
|
|
127
|
+
at = put_field(at, (int64_t)tail[4 + i]);
|
|
128
|
+
if (tier == 3) at = put_field(at, (int64_t)tail[4 + argn + i]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return close_row(at);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* [OP_RETURN, tree, step, class, object id]. An Array, which a tier of 1 marks, adds its true size
|
|
135
|
+
* and the class and id of each element stored. */
|
|
136
|
+
static char *format_return(const uint64_t *row, char *at) {
|
|
137
|
+
const uint64_t *tail = row + 1 + 4;
|
|
138
|
+
int argn = (row[0] & RA_ROW_TAIL) ? stored(tail) : -1;
|
|
139
|
+
if (argn < 0) return NULL;
|
|
140
|
+
|
|
141
|
+
at = open_row(at, OP_RETURN, row + 1, 4);
|
|
142
|
+
if (tail[0] == 1) {
|
|
143
|
+
at = put_field(at, (int64_t)tail[1]);
|
|
144
|
+
for (int i = 0; i < argn; i++) at = put_field(put_field(at, (int64_t)tail[4 + i]), (int64_t)tail[4 + argn + i]);
|
|
145
|
+
}
|
|
146
|
+
return close_row(at);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* [OP_KWARGS, tree, step, tier, count], then each keyword's name and class and, at tier 3, its
|
|
150
|
+
* value's object id. An IVARS row is the same with its own opcode: each ivar a call wrote. */
|
|
151
|
+
static char *format_named(int op, const uint64_t *row, char *at) {
|
|
152
|
+
const uint64_t *tail = row + 1 + 2;
|
|
153
|
+
int argn = (row[0] & RA_ROW_TAIL) ? stored(tail) : -1;
|
|
154
|
+
if (argn < 0) return NULL;
|
|
155
|
+
|
|
156
|
+
at = open_row(at, op, row + 1, 2);
|
|
157
|
+
at = put_field(put_field(at, (int64_t)tail[0]), (int64_t)tail[1]);
|
|
158
|
+
for (int i = 0; i < argn; i++) {
|
|
159
|
+
at = put_field(put_field(at, (int64_t)tail[4 + 2 * argn + i]), (int64_t)tail[4 + i]);
|
|
160
|
+
if (tail[0] == 3) at = put_field(at, (int64_t)tail[4 + argn + i]);
|
|
161
|
+
}
|
|
162
|
+
return close_row(at);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* [OP_VALUE, tree, step, role, key, how, print]: one value a probed call carried or returned. */
|
|
166
|
+
static char *format_value(const uint64_t *row, char *at) {
|
|
167
|
+
return close_row(open_row(at, OP_VALUE, row + 1, 6));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
int ra_formatted(int kind) {
|
|
171
|
+
return kind == SLOT_CALL || kind == SLOT_RETURN || kind == SLOT_KWARGS || kind == SLOT_VALUE || kind == SLOT_IVARS;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
char *ra_format_row(const uint64_t *row, char *at) {
|
|
175
|
+
switch (row[0] & 0xff) {
|
|
176
|
+
case SLOT_CALL: return format_call(row, at);
|
|
177
|
+
case SLOT_RETURN: return format_return(row, at);
|
|
178
|
+
case SLOT_VALUE: return format_value(row, at);
|
|
179
|
+
case SLOT_IVARS: return format_named(OP_IVARS, row, at);
|
|
180
|
+
default: return format_named(OP_KWARGS, row, at);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Tier-4 unwind row: [OP_UNWIND, tree, step, exception_class_id, raise_file_id, raise_line,
|
|
185
|
+
* missing_name_id, receiver_class_id], from rec[0..6]. The last four are -1 where the run had nothing
|
|
186
|
+
* to say: no backtrace, or an exception that is not a missing name. */
|
|
187
|
+
static void consume_unwind(sink *s, slot *sl) {
|
|
188
|
+
int64_t *r = sl->rec;
|
|
189
|
+
fprintf(s->file, "[%d,%lld,%lld,%lld,%lld,%lld,%lld,%lld]\n", OP_UNWIND, (long long)r[0], (long long)r[1],
|
|
190
|
+
(long long)r[2], (long long)r[3], (long long)r[4], (long long)r[5], (long long)r[6]);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* Entry-point row: [OP_ENTRY, tree, entry_point_id], one per tree, from rec[0..1]. */
|
|
194
|
+
static void consume_entry(sink *s, slot *sl) {
|
|
195
|
+
int64_t *r = sl->rec;
|
|
196
|
+
fprintf(s->file, "[%d,%lld,%lld]\n", OP_ENTRY, (long long)r[0], (long long)r[1]);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* A request or job that ran inside a tree with an entry point of its own: [OP_INNER_ENTRY, tree,
|
|
200
|
+
* identity_id], from rec[0..1]. A tree has one for each such request or job. */
|
|
201
|
+
static void consume_inner_entry(sink *s, slot *sl) {
|
|
202
|
+
int64_t *r = sl->rec;
|
|
203
|
+
fprintf(s->file, "[%d,%lld,%lld]\n", OP_INNER_ENTRY, (long long)r[0], (long long)r[1]);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* The name a method_missing was asked for: [OP_ANSWERED, tree, step, name_id], from rec[0..2]. */
|
|
207
|
+
static void consume_answered(sink *s, slot *sl) {
|
|
208
|
+
int64_t *r = sl->rec;
|
|
209
|
+
fprintf(s->file, "[%d,%lld,%lld,%lld]\n", OP_ANSWERED, (long long)r[0], (long long)r[1], (long long)r[2]);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* Roll the segment: open the next file first so a failure leaves the current one intact rather than
|
|
213
|
+
* stranding the stream with no file. */
|
|
214
|
+
/* Every segment is read by itself, so each says what format it is in, on its first line. Returns
|
|
215
|
+
* the bytes written. */
|
|
216
|
+
int64_t ra_mark_format(FILE *file) {
|
|
217
|
+
int written = fprintf(file, "[%d,%d]\n", OP_FORMAT, RA_FORMAT_VERSION);
|
|
218
|
+
return written > 0 ? written : 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static void consume_roll(sink *s, slot *sl) {
|
|
222
|
+
char *newpath = sl->dict_str.ptr;
|
|
223
|
+
if (newpath) {
|
|
224
|
+
FILE *nf = fopen(newpath, "a");
|
|
225
|
+
if (nf) {
|
|
226
|
+
if (s->file) { fflush(s->file); fclose(s->file); }
|
|
227
|
+
s->file = nf;
|
|
228
|
+
s->write_failed = 0;
|
|
229
|
+
s->bytes_written = ra_mark_format(nf);
|
|
230
|
+
} else {
|
|
231
|
+
char msg[256];
|
|
232
|
+
__atomic_fetch_add(&ra_write_errors, 1, __ATOMIC_RELAXED);
|
|
233
|
+
snprintf(msg, sizeof(msg), "runtime_analysis native: could not open segment %s: %s\n",
|
|
234
|
+
newpath, strerror(errno));
|
|
235
|
+
ra_report_once(s, msg);
|
|
236
|
+
}
|
|
237
|
+
free(newpath);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* A write can fail: a full disk, an I/O error. Raising that into the recorded program would hurt
|
|
242
|
+
* it, so the first failure on a stream is reported on stderr and the rest pass. Called straight
|
|
243
|
+
* after the write or the flush, while errno is still the one it left. */
|
|
244
|
+
void ra_note_io_error(sink *s) {
|
|
245
|
+
if (ferror(s->file)) {
|
|
246
|
+
if (!s->write_failed) {
|
|
247
|
+
s->write_failed = 1;
|
|
248
|
+
__atomic_fetch_add(&ra_write_errors, 1, __ATOMIC_RELAXED);
|
|
249
|
+
}
|
|
250
|
+
char msg[256];
|
|
251
|
+
snprintf(msg, sizeof(msg), "runtime_analysis native: write error on output segment: %s\n",
|
|
252
|
+
strerror(errno));
|
|
253
|
+
ra_report_once(s, msg);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
void ra_consume_slot(sink *s, slot *sl) {
|
|
258
|
+
switch (sl->kind) {
|
|
259
|
+
case SLOT_DICT:
|
|
260
|
+
RA_GUARD(s, s->file, );
|
|
261
|
+
consume_dict(s, sl);
|
|
262
|
+
ra_note_io_error(s);
|
|
263
|
+
s->bytes_written = ftello(s->file);
|
|
264
|
+
break;
|
|
265
|
+
case SLOT_PATH:
|
|
266
|
+
RA_GUARD(s, s->file, );
|
|
267
|
+
ra_write_path(s->file, sl->rec);
|
|
268
|
+
ra_note_io_error(s);
|
|
269
|
+
s->bytes_written = ftello(s->file);
|
|
270
|
+
break;
|
|
271
|
+
case SLOT_UNWIND:
|
|
272
|
+
RA_GUARD(s, s->file, );
|
|
273
|
+
consume_unwind(s, sl);
|
|
274
|
+
ra_note_io_error(s);
|
|
275
|
+
s->bytes_written = ftello(s->file);
|
|
276
|
+
break;
|
|
277
|
+
case SLOT_ENTRY:
|
|
278
|
+
RA_GUARD(s, s->file, );
|
|
279
|
+
consume_entry(s, sl);
|
|
280
|
+
ra_note_io_error(s);
|
|
281
|
+
s->bytes_written = ftello(s->file);
|
|
282
|
+
break;
|
|
283
|
+
case SLOT_ANSWERED:
|
|
284
|
+
RA_GUARD(s, s->file, );
|
|
285
|
+
consume_answered(s, sl);
|
|
286
|
+
ra_note_io_error(s);
|
|
287
|
+
s->bytes_written = ftello(s->file);
|
|
288
|
+
break;
|
|
289
|
+
case SLOT_INNER_ENTRY:
|
|
290
|
+
RA_GUARD(s, s->file, );
|
|
291
|
+
consume_inner_entry(s, sl);
|
|
292
|
+
ra_note_io_error(s);
|
|
293
|
+
s->bytes_written = ftello(s->file);
|
|
294
|
+
break;
|
|
295
|
+
case SLOT_ROLL:
|
|
296
|
+
consume_roll(s, sl);
|
|
297
|
+
break;
|
|
298
|
+
/* coverage:off -- invariant guard only a bug in the extension reaches */
|
|
299
|
+
default:
|
|
300
|
+
RA_GUARD(s, 0 && "unknown slot kind", );
|
|
301
|
+
/* coverage:on */
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|