riptide 0.1.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 +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +157 -0
- data/exe/riptide +6 -0
- data/ext/riptide/extconf.rb +49 -0
- data/ext/riptide/riptide_native.c +892 -0
- data/ext/riptide/ruby_source.rb +80 -0
- data/lib/minitest/riptide_plugin.rb +20 -0
- data/lib/riptide/analysis/fixture.rb +21 -0
- data/lib/riptide/analysis/ruby.rb +208 -0
- data/lib/riptide/analysis/schema.rb +60 -0
- data/lib/riptide/analysis/sql.rb +83 -0
- data/lib/riptide/analyzer.rb +138 -0
- data/lib/riptide/assertions.rb +82 -0
- data/lib/riptide/audit.rb +433 -0
- data/lib/riptide/change.rb +41 -0
- data/lib/riptide/cli.rb +109 -0
- data/lib/riptide/collectors.rb +386 -0
- data/lib/riptide/configuration.rb +63 -0
- data/lib/riptide/diff.rb +54 -0
- data/lib/riptide/env.rb +61 -0
- data/lib/riptide/git.rb +193 -0
- data/lib/riptide/harvest.rb +87 -0
- data/lib/riptide/index.rb +458 -0
- data/lib/riptide/inputs.rb +273 -0
- data/lib/riptide/layout.rb +45 -0
- data/lib/riptide/recorder.rb +374 -0
- data/lib/riptide/resolver.rb +67 -0
- data/lib/riptide/runner.rb +21 -0
- data/lib/riptide/scope.rb +39 -0
- data/lib/riptide/selector.rb +209 -0
- data/lib/riptide/session.rb +74 -0
- data/lib/riptide/source.rb +449 -0
- data/lib/riptide/store.rb +446 -0
- data/lib/riptide/tracer.rb +176 -0
- data/lib/riptide/version.rb +9 -0
- data/lib/riptide.rb +69 -0
- data/riptide.gemspec +34 -0
- metadata +116 -0
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
// Riptide::Tracer. Probes sit on the VM's own trace instructions in the app's
|
|
2
|
+
// code and nowhere else, each instruction sequence with a hook list of its
|
|
3
|
+
// own, so Rails and gems run untraced and YJIT keeps its compiled code. A line
|
|
4
|
+
// probe turns itself off after its first hit and comes back when a window
|
|
5
|
+
// opens or closes, so a test pays once per distinct line it runs, however hot the
|
|
6
|
+
// line is. Method, block and class entries and class ends stay armed: they
|
|
7
|
+
// record receivers and load facts, and they're where YJIT would otherwise
|
|
8
|
+
// jump into app code that a probe coming back later can't reach.
|
|
9
|
+
//
|
|
10
|
+
// Every in-scope line, method entry and block entry goes to load facts while
|
|
11
|
+
// its thread is inside a class body, or else to the innermost open window: a
|
|
12
|
+
// test's, a test class's, or the process's, which is always open and is all
|
|
13
|
+
// there is at boot.
|
|
14
|
+
//
|
|
15
|
+
// A test's body runs in windows of its own, one per top-level statement. The
|
|
16
|
+
// hook switches them when the test method itself reaches a line in another
|
|
17
|
+
// statement, and charges the time since the last switch to the one that was
|
|
18
|
+
// running, so the test's window keeps only what ran around its body.
|
|
19
|
+
//
|
|
20
|
+
// Hooks this close to the VM need Ruby's internal headers, which the build
|
|
21
|
+
// gets from Ruby's source. On a Ruby without them the tracer says so and
|
|
22
|
+
// riptide records nothing.
|
|
23
|
+
|
|
24
|
+
#include "riptide_build.h"
|
|
25
|
+
|
|
26
|
+
#ifndef RIPTIDE_UNSUPPORTED
|
|
27
|
+
|
|
28
|
+
#include "vm_core.h"
|
|
29
|
+
#include "iseq.h"
|
|
30
|
+
#include "ractor_core.h"
|
|
31
|
+
#include "ruby/debug.h"
|
|
32
|
+
#include <time.h>
|
|
33
|
+
|
|
34
|
+
// Words per instruction, by opcode.
|
|
35
|
+
extern const uint8_t rb_vm_insn_len_info[];
|
|
36
|
+
|
|
37
|
+
static VALUE mRiptide;
|
|
38
|
+
static VALUE mTracer;
|
|
39
|
+
|
|
40
|
+
static VALUE stacks = Qnil; // thread => [class, frame depth, body iseq, ...] being defined
|
|
41
|
+
static long loading = 0; // classes being defined, summed over threads
|
|
42
|
+
|
|
43
|
+
static VALUE window = Qnil; // relative path => byte map String, for the innermost window
|
|
44
|
+
static VALUE receivers = Qnil; // class => true for each receiver of an in-scope method in it, nil in the process's
|
|
45
|
+
static VALUE enclosing = Qnil; // [[window, receivers], ...] for the windows around it, the process's first
|
|
46
|
+
static VALUE last_receiver = Qnil;
|
|
47
|
+
static VALUE load_facts = Qnil; // relative path => { line => Array of classes }
|
|
48
|
+
static VALUE load_called = Qnil; // relative path => { line => true } for called code
|
|
49
|
+
static VALUE owner_files = Qnil; // class => { relative path => true }
|
|
50
|
+
|
|
51
|
+
static const rb_iseq_t *body_iseq; // the test method whose statements are split, or NULL
|
|
52
|
+
static long body_depth; // how many windows enclose the test's
|
|
53
|
+
static long *body_starts; // each statement's first line, ascending
|
|
54
|
+
static long body_count;
|
|
55
|
+
static VALUE body_windows = Qnil; // statement's first line => [window, receivers]
|
|
56
|
+
static VALUE body_times = Qnil; // statement's first line => seconds
|
|
57
|
+
static VALUE body_outer = Qnil; // [window, receivers] of the test itself
|
|
58
|
+
static VALUE statement = Qnil; // the first line of the statement running now
|
|
59
|
+
static double statement_since;
|
|
60
|
+
|
|
61
|
+
static VALUE last_relative = Qnil;
|
|
62
|
+
static VALUE last_map = Qnil;
|
|
63
|
+
static VALUE last_pinned = Qnil;
|
|
64
|
+
|
|
65
|
+
static int installed = 0;
|
|
66
|
+
|
|
67
|
+
#define EVENTS (RUBY_EVENT_LINE | RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS | RUBY_EVENT_END)
|
|
68
|
+
#define ENTRIES (RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS)
|
|
69
|
+
|
|
70
|
+
// Ruby keeps this one to vm_trace.c.
|
|
71
|
+
typedef struct rb_event_hook_struct {
|
|
72
|
+
rb_event_hook_flag_t hook_flags;
|
|
73
|
+
rb_event_flag_t events;
|
|
74
|
+
rb_event_hook_func_t func;
|
|
75
|
+
VALUE data;
|
|
76
|
+
struct rb_event_hook_struct *next;
|
|
77
|
+
struct {
|
|
78
|
+
rb_thread_t *th;
|
|
79
|
+
unsigned int target_line;
|
|
80
|
+
} filter;
|
|
81
|
+
} hook_t;
|
|
82
|
+
|
|
83
|
+
// The probes in one instruction sequence, sorted by pc.
|
|
84
|
+
typedef struct {
|
|
85
|
+
const rb_iseq_t *iseq;
|
|
86
|
+
const rb_hook_list_t *hooks; // the iseq's hook list, which other tools' targeted hooks join
|
|
87
|
+
VALUE relative;
|
|
88
|
+
int class_body;
|
|
89
|
+
unsigned int count;
|
|
90
|
+
unsigned int *pc;
|
|
91
|
+
int *line;
|
|
92
|
+
rb_event_flag_t *events; // everything the VM has at the pc, not just ours
|
|
93
|
+
VALUE *plain; // the instruction untraced, or 0 for a probe that stays armed
|
|
94
|
+
} probes_t;
|
|
95
|
+
|
|
96
|
+
// Line probes that went off, to turn back on when the next test starts.
|
|
97
|
+
static VALUE **rearm_at;
|
|
98
|
+
static VALUE *rearm_word;
|
|
99
|
+
static long rearm_len, rearm_cap;
|
|
100
|
+
|
|
101
|
+
static void
|
|
102
|
+
push_rearm(VALUE *at, VALUE word)
|
|
103
|
+
{
|
|
104
|
+
if (rearm_len == rearm_cap) {
|
|
105
|
+
rearm_cap = rearm_cap ? rearm_cap * 2 : 4096;
|
|
106
|
+
REALLOC_N(rearm_at, VALUE *, rearm_cap);
|
|
107
|
+
REALLOC_N(rearm_word, VALUE, rearm_cap);
|
|
108
|
+
}
|
|
109
|
+
rearm_at[rearm_len] = at;
|
|
110
|
+
rearm_word[rearm_len] = word;
|
|
111
|
+
rearm_len++;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static void
|
|
115
|
+
rearm(void)
|
|
116
|
+
{
|
|
117
|
+
for (long i = 0; i < rearm_len; i++) *rearm_at[i] = rearm_word[i];
|
|
118
|
+
rearm_len = 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static VALUE
|
|
122
|
+
identity_hash(void)
|
|
123
|
+
{
|
|
124
|
+
VALUE hash = rb_hash_new();
|
|
125
|
+
rb_funcall(hash, rb_intern("compare_by_identity"), 0);
|
|
126
|
+
return hash;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static VALUE
|
|
130
|
+
current_stack(int create)
|
|
131
|
+
{
|
|
132
|
+
VALUE thread = rb_thread_current();
|
|
133
|
+
VALUE stack = rb_hash_lookup2(stacks, thread, Qnil);
|
|
134
|
+
if (NIL_P(stack) && create) {
|
|
135
|
+
stack = rb_ary_new();
|
|
136
|
+
rb_hash_aset(stacks, thread, stack);
|
|
137
|
+
}
|
|
138
|
+
return stack;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static void
|
|
142
|
+
nested_set(VALUE outer, VALUE key, VALUE inner_key)
|
|
143
|
+
{
|
|
144
|
+
VALUE inner = rb_hash_lookup2(outer, key, Qnil);
|
|
145
|
+
if (NIL_P(inner)) {
|
|
146
|
+
inner = rb_hash_new();
|
|
147
|
+
rb_hash_aset(outer, key, inner);
|
|
148
|
+
}
|
|
149
|
+
rb_hash_aset(inner, inner_key, Qtrue);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Frames on the hooked thread's stack, deeper is bigger.
|
|
153
|
+
static long
|
|
154
|
+
frame_depth(rb_trace_arg_t *arg)
|
|
155
|
+
{
|
|
156
|
+
return RUBY_VM_END_CONTROL_FRAME(arg->ec) - arg->cfp;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static VALUE
|
|
160
|
+
current_owner(VALUE stack)
|
|
161
|
+
{
|
|
162
|
+
return rb_ary_entry(stack, -3);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Nil once the thread has no class bodies left.
|
|
166
|
+
static VALUE
|
|
167
|
+
pop_owner(VALUE stack)
|
|
168
|
+
{
|
|
169
|
+
rb_ary_pop(stack);
|
|
170
|
+
rb_ary_pop(stack);
|
|
171
|
+
rb_ary_pop(stack);
|
|
172
|
+
loading--;
|
|
173
|
+
if (RARRAY_LEN(stack) > 0) return stack;
|
|
174
|
+
|
|
175
|
+
rb_hash_delete(stacks, rb_thread_current());
|
|
176
|
+
return Qnil;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Whether the innermost class body is still running: its frame is still
|
|
180
|
+
// on the stack where it opened, running the body.
|
|
181
|
+
static int
|
|
182
|
+
body_open(VALUE stack, rb_trace_arg_t *arg)
|
|
183
|
+
{
|
|
184
|
+
long depth = FIX2LONG(rb_ary_entry(stack, -2));
|
|
185
|
+
if (frame_depth(arg) < depth) return 0;
|
|
186
|
+
|
|
187
|
+
const rb_control_frame_t *cfp = RUBY_VM_END_CONTROL_FRAME(arg->ec) - depth;
|
|
188
|
+
return (VALUE)cfp->iseq == rb_ary_entry(stack, -1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// The thread's class bodies, without the ones it left with no end event.
|
|
192
|
+
// An error, a throw or anything else that unwinds a body skips its end,
|
|
193
|
+
// so a body counts until its frame is gone.
|
|
194
|
+
static VALUE
|
|
195
|
+
open_stack(rb_trace_arg_t *arg)
|
|
196
|
+
{
|
|
197
|
+
VALUE stack = current_stack(0);
|
|
198
|
+
while (!NIL_P(stack) && !body_open(stack, arg)) stack = pop_owner(stack);
|
|
199
|
+
return stack;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// A thread that died inside a class body never comes back to close it.
|
|
203
|
+
static int
|
|
204
|
+
drop_dead(VALUE thread, VALUE stack, VALUE arg)
|
|
205
|
+
{
|
|
206
|
+
(void)arg;
|
|
207
|
+
if (((rb_thread_t *)RTYPEDDATA_GET_DATA(thread))->status != THREAD_KILLED) return ST_CONTINUE;
|
|
208
|
+
|
|
209
|
+
loading -= RARRAY_LEN(stack) / 3;
|
|
210
|
+
return ST_DELETE;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// `class << obj` on a plain object opens a class nothing else will ever
|
|
214
|
+
// name, so it's tracked for loading but never kept as an owner. Lines that
|
|
215
|
+
// already went off come back first, so everything the class body runs is a
|
|
216
|
+
// load fact, even code the test ran before.
|
|
217
|
+
static void
|
|
218
|
+
on_class(VALUE klass, VALUE relative, rb_trace_arg_t *arg)
|
|
219
|
+
{
|
|
220
|
+
rb_hash_foreach(stacks, drop_dead, Qnil);
|
|
221
|
+
open_stack(arg);
|
|
222
|
+
if (loading == 0) rearm();
|
|
223
|
+
|
|
224
|
+
VALUE stack = current_stack(1);
|
|
225
|
+
rb_ary_push(stack, klass);
|
|
226
|
+
rb_ary_push(stack, LONG2FIX(frame_depth(arg)));
|
|
227
|
+
rb_ary_push(stack, (VALUE)arg->cfp->iseq);
|
|
228
|
+
loading++;
|
|
229
|
+
|
|
230
|
+
if (RB_TYPE_P(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON)) {
|
|
231
|
+
VALUE attached = rb_class_attached_object(klass);
|
|
232
|
+
if (!RB_TYPE_P(attached, T_CLASS) && !RB_TYPE_P(attached, T_MODULE)) return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
nested_set(owner_files, klass, relative);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static void
|
|
239
|
+
on_end(rb_trace_arg_t *arg)
|
|
240
|
+
{
|
|
241
|
+
VALUE stack = open_stack(arg);
|
|
242
|
+
if (!NIL_P(stack)) pop_owner(stack);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static void
|
|
246
|
+
record_load(VALUE relative, VALUE owner, VALUE lineno, int called)
|
|
247
|
+
{
|
|
248
|
+
if (called) nested_set(load_called, relative, lineno);
|
|
249
|
+
|
|
250
|
+
VALUE lines = rb_hash_lookup2(load_facts, relative, Qnil);
|
|
251
|
+
if (NIL_P(lines)) {
|
|
252
|
+
lines = rb_hash_new();
|
|
253
|
+
rb_hash_aset(load_facts, relative, lines);
|
|
254
|
+
}
|
|
255
|
+
VALUE owners = rb_hash_lookup2(lines, lineno, Qnil);
|
|
256
|
+
if (NIL_P(owners)) {
|
|
257
|
+
owners = rb_ary_new();
|
|
258
|
+
rb_hash_aset(lines, lineno, owners);
|
|
259
|
+
}
|
|
260
|
+
if (!RTEST(rb_ary_includes(owners, owner))) rb_ary_push(owners, owner);
|
|
261
|
+
nested_set(owner_files, owner, relative);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static void
|
|
265
|
+
record_window(VALUE relative, long line)
|
|
266
|
+
{
|
|
267
|
+
/* Code eval'd with a line before 1 doesn't sit on any line of the file. */
|
|
268
|
+
if (line < 1) return;
|
|
269
|
+
if (relative != last_relative) {
|
|
270
|
+
last_relative = relative;
|
|
271
|
+
last_map = Qnil;
|
|
272
|
+
}
|
|
273
|
+
if (NIL_P(last_map)) {
|
|
274
|
+
last_map = rb_hash_lookup2(window, relative, Qnil);
|
|
275
|
+
if (NIL_P(last_map)) {
|
|
276
|
+
last_map = rb_str_new(NULL, 256);
|
|
277
|
+
memset(RSTRING_PTR(last_map), 0, 256);
|
|
278
|
+
rb_hash_aset(window, relative, last_map);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
long len = RSTRING_LEN(last_map);
|
|
283
|
+
if (line >= len) {
|
|
284
|
+
long grown = line * 2 + 1;
|
|
285
|
+
rb_str_resize(last_map, grown);
|
|
286
|
+
memset(RSTRING_PTR(last_map) + len, 0, grown - len);
|
|
287
|
+
}
|
|
288
|
+
RSTRING_PTR(last_map)[line] = 1;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
static long
|
|
292
|
+
find_probe(const probes_t *probes, unsigned int pc)
|
|
293
|
+
{
|
|
294
|
+
long low = 0, high = (long)probes->count - 1;
|
|
295
|
+
while (low <= high) {
|
|
296
|
+
long mid = (low + high) / 2;
|
|
297
|
+
if (probes->pc[mid] == pc) return mid;
|
|
298
|
+
if (probes->pc[mid] < pc) low = mid + 1;
|
|
299
|
+
else high = mid - 1;
|
|
300
|
+
}
|
|
301
|
+
return -1;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static void forget_last(void);
|
|
305
|
+
|
|
306
|
+
static double
|
|
307
|
+
seconds_now(void)
|
|
308
|
+
{
|
|
309
|
+
struct timespec ts;
|
|
310
|
+
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
311
|
+
return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static void
|
|
315
|
+
charge_statement(void)
|
|
316
|
+
{
|
|
317
|
+
double now = seconds_now();
|
|
318
|
+
if (!NIL_P(statement)) {
|
|
319
|
+
VALUE spent = rb_hash_lookup2(body_times, statement, DBL2NUM(0.0));
|
|
320
|
+
rb_hash_aset(body_times, statement, DBL2NUM(NUM2DBL(spent) + now - statement_since));
|
|
321
|
+
}
|
|
322
|
+
statement_since = now;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// The statement +line+ belongs to: the last one starting at or before it, or
|
|
326
|
+
// nil ahead of the first, like the method's own def line.
|
|
327
|
+
static VALUE
|
|
328
|
+
statement_of(long line)
|
|
329
|
+
{
|
|
330
|
+
long low = 0, high = body_count - 1, found = -1;
|
|
331
|
+
while (low <= high) {
|
|
332
|
+
long mid = (low + high) / 2;
|
|
333
|
+
if (body_starts[mid] <= line) {
|
|
334
|
+
found = mid;
|
|
335
|
+
low = mid + 1;
|
|
336
|
+
} else {
|
|
337
|
+
high = mid - 1;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return found < 0 ? Qnil : LONG2FIX(body_starts[found]);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Lines go to +start+'s window from here. Every line probe comes back, so
|
|
344
|
+
// each statement sees all of what it runs.
|
|
345
|
+
static void
|
|
346
|
+
switch_statement(VALUE start)
|
|
347
|
+
{
|
|
348
|
+
charge_statement();
|
|
349
|
+
VALUE entry;
|
|
350
|
+
if (NIL_P(start)) {
|
|
351
|
+
entry = body_outer;
|
|
352
|
+
} else {
|
|
353
|
+
entry = rb_hash_lookup2(body_windows, start, Qnil);
|
|
354
|
+
if (NIL_P(entry)) {
|
|
355
|
+
entry = rb_assoc_new(rb_hash_new(), identity_hash());
|
|
356
|
+
rb_hash_aset(body_windows, start, entry);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
window = RARRAY_AREF(entry, 0);
|
|
360
|
+
receivers = RARRAY_AREF(entry, 1);
|
|
361
|
+
statement = start;
|
|
362
|
+
rearm();
|
|
363
|
+
forget_last();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static void hook(VALUE data, rb_trace_arg_t *arg);
|
|
367
|
+
|
|
368
|
+
// Whether another hook on the iseq listens for +line+, like a debugger's
|
|
369
|
+
// breakpoint, so its instruction has to stay traced.
|
|
370
|
+
static int
|
|
371
|
+
line_heard_elsewhere(const probes_t *probes, int line)
|
|
372
|
+
{
|
|
373
|
+
for (const hook_t *h = (const hook_t *)probes->hooks->hooks; h; h = h->next) {
|
|
374
|
+
if (h->func == (rb_event_hook_func_t)hook || h->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) continue;
|
|
375
|
+
if (h->events & RUBY_EVENT_LINE && (h->filter.target_line == 0 || h->filter.target_line == (unsigned int)line)) return 1;
|
|
376
|
+
}
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
static void
|
|
381
|
+
hook(VALUE data, rb_trace_arg_t *arg)
|
|
382
|
+
{
|
|
383
|
+
probes_t *probes = (probes_t *)(data & ~(VALUE)RUBY_FIXNUM_FLAG);
|
|
384
|
+
rb_event_flag_t event = arg->event;
|
|
385
|
+
|
|
386
|
+
if (event == RUBY_EVENT_CLASS) {
|
|
387
|
+
on_class(arg->self, probes->relative, arg);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (event == RUBY_EVENT_END) {
|
|
391
|
+
on_end(arg);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// The VM moves the pc one word past the trace instruction while hooks run.
|
|
396
|
+
VALUE *encoded = (VALUE *)ISEQ_BODY(probes->iseq)->iseq_encoded;
|
|
397
|
+
unsigned int pc = (unsigned int)(arg->cfp->pc - encoded) - 1;
|
|
398
|
+
long i = find_probe(probes, pc);
|
|
399
|
+
if (i < 0) return;
|
|
400
|
+
|
|
401
|
+
// An entry is on the line it starts at, the def or the block's opening.
|
|
402
|
+
int line = event & ENTRIES ? ISEQ_BODY(probes->iseq)->location.first_lineno : probes->line[i];
|
|
403
|
+
VALUE lineno = INT2FIX(line);
|
|
404
|
+
|
|
405
|
+
// A one-line body has no line event, so its entry counts too.
|
|
406
|
+
if (probes->iseq == body_iseq && event & (RUBY_EVENT_LINE | RUBY_EVENT_CALL | RUBY_EVENT_B_CALL) && RARRAY_LEN(enclosing) == body_depth) {
|
|
407
|
+
VALUE start = statement_of(line);
|
|
408
|
+
if (start != statement) switch_statement(start);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (loading > 0) {
|
|
412
|
+
VALUE stack = open_stack(arg);
|
|
413
|
+
if (!NIL_P(stack)) {
|
|
414
|
+
record_load(probes->relative, current_owner(stack), lineno, !probes->class_body);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
record_window(probes->relative, line);
|
|
420
|
+
// A method that comes in later anywhere in the receiver's ancestry can
|
|
421
|
+
// take this call over, so the receiver's class counts, not just where the
|
|
422
|
+
// method lives. A class method's receiver is the class itself, whose
|
|
423
|
+
// singleton ancestry riptide expands later.
|
|
424
|
+
if (event == RUBY_EVENT_CALL && !NIL_P(receivers)) {
|
|
425
|
+
VALUE self = arg->self;
|
|
426
|
+
VALUE klass = RB_TYPE_P(self, T_CLASS) || RB_TYPE_P(self, T_MODULE) ? self : rb_obj_class(self);
|
|
427
|
+
if (klass != last_receiver) {
|
|
428
|
+
last_receiver = klass;
|
|
429
|
+
rb_hash_aset(receivers, klass, Qtrue);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// A global hook on this pc, like coverage, or another hook aimed at the
|
|
434
|
+
// line, like a breakpoint, needs it traced.
|
|
435
|
+
if (event == RUBY_EVENT_LINE && probes->plain[i] && !(probes->iseq->aux.exec.global_trace_events & probes->events[i]) && !line_heard_elsewhere(probes, line)) {
|
|
436
|
+
VALUE *at = &encoded[pc];
|
|
437
|
+
push_rearm(at, *at);
|
|
438
|
+
*at = probes->plain[i];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
static rb_ractor_t *
|
|
443
|
+
current_ractor(void)
|
|
444
|
+
{
|
|
445
|
+
return ((rb_thread_t *)RTYPEDDATA_GET_DATA(rb_thread_current()))->ractor;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
static VALUE
|
|
449
|
+
tracer_install(VALUE self)
|
|
450
|
+
{
|
|
451
|
+
(void)self;
|
|
452
|
+
if (installed) rb_raise(rb_eRuntimeError, "Riptide::Tracer is already installed");
|
|
453
|
+
|
|
454
|
+
installed = 1;
|
|
455
|
+
return Qnil;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Ruby keeps the succinct index from pc to instruction info to iseq.c.
|
|
459
|
+
#define IMMEDIATE_TABLE_SIZE 54
|
|
460
|
+
struct succ_index_table {
|
|
461
|
+
uint64_t imm_part[IMMEDIATE_TABLE_SIZE / 9];
|
|
462
|
+
struct succ_dict_block {
|
|
463
|
+
unsigned int rank;
|
|
464
|
+
uint64_t small_block_ranks;
|
|
465
|
+
uint64_t bits[512/64];
|
|
466
|
+
} succ_part[FLEX_ARY_LEN];
|
|
467
|
+
};
|
|
468
|
+
#define imm_block_rank_get(v, i) (((int)((v) >> ((i) * 7))) & 0x7f)
|
|
469
|
+
|
|
470
|
+
// Where each instruction info entry starts, worked out the way iseq.c's
|
|
471
|
+
// succ_index_table_invert does it.
|
|
472
|
+
static unsigned int *
|
|
473
|
+
info_positions(const struct rb_iseq_constant_body *body)
|
|
474
|
+
{
|
|
475
|
+
int size = (int)body->insns_info.size;
|
|
476
|
+
int max_pos = (int)body->iseq_size;
|
|
477
|
+
unsigned int *positions = ALLOC_N(unsigned int, size);
|
|
478
|
+
if (body->insns_info.positions) {
|
|
479
|
+
MEMCPY(positions, body->insns_info.positions, unsigned int, size);
|
|
480
|
+
return positions;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const struct succ_index_table *sd = body->insns_info.succ_index_table;
|
|
484
|
+
const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9;
|
|
485
|
+
const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512;
|
|
486
|
+
unsigned int *p = positions;
|
|
487
|
+
int r = -1;
|
|
488
|
+
for (int j = 0; j < imm_size; j++) {
|
|
489
|
+
for (int i = 0; i < 9; i++) {
|
|
490
|
+
int nr = imm_block_rank_get(sd->imm_part[j], i);
|
|
491
|
+
if (r != nr) *p++ = j * 9 + i;
|
|
492
|
+
r = nr;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
for (int k = 0; k < succ_size; k++) {
|
|
496
|
+
for (int j = 0; j < 8; j++) {
|
|
497
|
+
for (int i = 0; i < 64; i++) {
|
|
498
|
+
if (sd->succ_part[k].bits[j] & (((uint64_t)1) << i)) *p++ = k * 512 + j * 64 + i + IMMEDIATE_TABLE_SIZE;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return positions;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
static void
|
|
506
|
+
free_probes(probes_t *probes)
|
|
507
|
+
{
|
|
508
|
+
ruby_xfree(probes->pc);
|
|
509
|
+
ruby_xfree(probes->line);
|
|
510
|
+
ruby_xfree(probes->events);
|
|
511
|
+
ruby_xfree(probes->plain);
|
|
512
|
+
ruby_xfree(probes);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Finds every pc the tracer cares about, the way the VM decides what to
|
|
516
|
+
// trace: each instruction takes the events of the info entry it falls in.
|
|
517
|
+
static probes_t *
|
|
518
|
+
find_probes(const rb_iseq_t *iseq)
|
|
519
|
+
{
|
|
520
|
+
const struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
|
|
521
|
+
unsigned int info_size = body->insns_info.size;
|
|
522
|
+
if (info_size == 0) return NULL;
|
|
523
|
+
|
|
524
|
+
probes_t *probes = ZALLOC(probes_t);
|
|
525
|
+
probes->iseq = iseq;
|
|
526
|
+
probes->class_body = body->type == ISEQ_TYPE_CLASS;
|
|
527
|
+
probes->pc = ALLOC_N(unsigned int, info_size);
|
|
528
|
+
probes->line = ALLOC_N(int, info_size);
|
|
529
|
+
probes->events = ALLOC_N(rb_event_flag_t, info_size);
|
|
530
|
+
probes->plain = ALLOC_N(VALUE, info_size);
|
|
531
|
+
unsigned int capacity = info_size;
|
|
532
|
+
|
|
533
|
+
unsigned int *positions = info_size > 1 ? info_positions(body) : NULL;
|
|
534
|
+
int had_original = ISEQ_ORIGINAL_ISEQ(iseq) != NULL;
|
|
535
|
+
const VALUE *code = rb_iseq_original_iseq(iseq);
|
|
536
|
+
unsigned int entry = 0;
|
|
537
|
+
for (unsigned int pc = 0; pc < body->iseq_size; pc += rb_vm_insn_len_info[code[pc]]) {
|
|
538
|
+
while (positions && entry + 1 < info_size && positions[entry + 1] <= pc) entry++;
|
|
539
|
+
rb_event_flag_t events = body->insns_info.body[entry].events;
|
|
540
|
+
if (!(events & EVENTS)) continue;
|
|
541
|
+
|
|
542
|
+
if (probes->count == capacity) {
|
|
543
|
+
capacity *= 2;
|
|
544
|
+
REALLOC_N(probes->pc, unsigned int, capacity);
|
|
545
|
+
REALLOC_N(probes->line, int, capacity);
|
|
546
|
+
REALLOC_N(probes->events, rb_event_flag_t, capacity);
|
|
547
|
+
REALLOC_N(probes->plain, VALUE, capacity);
|
|
548
|
+
}
|
|
549
|
+
probes->pc[probes->count] = pc;
|
|
550
|
+
probes->line[probes->count] = body->insns_info.body[entry].line_no;
|
|
551
|
+
probes->events[probes->count] = events;
|
|
552
|
+
probes->count++;
|
|
553
|
+
}
|
|
554
|
+
if (!had_original) ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
|
|
555
|
+
if (positions) ruby_xfree(positions);
|
|
556
|
+
|
|
557
|
+
if (probes->count == 0) {
|
|
558
|
+
free_probes(probes);
|
|
559
|
+
return NULL;
|
|
560
|
+
}
|
|
561
|
+
return probes;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Aims the hook at +iseq+, one instruction sequence of a compiled app file.
|
|
565
|
+
// Code outside the app never fires it.
|
|
566
|
+
static VALUE
|
|
567
|
+
tracer_target(VALUE self, VALUE iseqw, VALUE relative)
|
|
568
|
+
{
|
|
569
|
+
(void)self;
|
|
570
|
+
const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
|
|
571
|
+
rb_iseq_t *mutable_iseq = (rb_iseq_t *)iseq;
|
|
572
|
+
struct rb_iseq_constant_body *body = (struct rb_iseq_constant_body *)ISEQ_BODY(iseq);
|
|
573
|
+
rb_ractor_t *ractor = current_ractor();
|
|
574
|
+
st_data_t existing;
|
|
575
|
+
rb_hook_list_t *list = NULL;
|
|
576
|
+
if (st_lookup(ractor->pub.targeted_hooks, (st_data_t)iseq, &existing)) {
|
|
577
|
+
list = (rb_hook_list_t *)existing;
|
|
578
|
+
for (hook_t *h = (hook_t *)list->hooks; h; h = h->next) {
|
|
579
|
+
if (h->func == (rb_event_hook_func_t)hook) return Qfalse;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
probes_t *probes = find_probes(iseq);
|
|
584
|
+
if (!probes) return Qfalse;
|
|
585
|
+
|
|
586
|
+
// Every iseq in a file shares its path, and the ractor keeps the iseqs
|
|
587
|
+
// themselves alive and in place.
|
|
588
|
+
if (relative != last_pinned) {
|
|
589
|
+
rb_gc_register_mark_object(relative);
|
|
590
|
+
last_pinned = relative;
|
|
591
|
+
}
|
|
592
|
+
probes->relative = relative;
|
|
593
|
+
|
|
594
|
+
VALUE *encoded = (VALUE *)body->iseq_encoded;
|
|
595
|
+
for (unsigned int i = 0; i < probes->count; i++) probes->plain[i] = encoded[probes->pc[i]];
|
|
596
|
+
|
|
597
|
+
hook_t *h = ZALLOC(hook_t);
|
|
598
|
+
h->hook_flags = RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG;
|
|
599
|
+
h->events = EVENTS;
|
|
600
|
+
h->func = (rb_event_hook_func_t)hook;
|
|
601
|
+
// A fixnum, so the GC marking the hook list leaves the pointer alone.
|
|
602
|
+
h->data = (VALUE)probes | RUBY_FIXNUM_FLAG;
|
|
603
|
+
if (!list) {
|
|
604
|
+
list = ZALLOC(rb_hook_list_t);
|
|
605
|
+
list->type = hook_list_type_targeted_iseq;
|
|
606
|
+
st_insert(ractor->pub.targeted_hooks, (st_data_t)iseq, (st_data_t)list);
|
|
607
|
+
}
|
|
608
|
+
probes->hooks = list;
|
|
609
|
+
h->next = (hook_t *)list->hooks;
|
|
610
|
+
list->hooks = (struct rb_event_hook_struct *)h;
|
|
611
|
+
list->events |= EVENTS;
|
|
612
|
+
mutable_iseq->aux.exec.local_hooks_cnt++;
|
|
613
|
+
|
|
614
|
+
// Tracing the iseq for events beyond the global ones picks up the hook
|
|
615
|
+
// list's events too. Going through a TracePoint instead would throw away
|
|
616
|
+
// everything YJIT has compiled, every time.
|
|
617
|
+
rb_event_flag_t global = iseq->aux.exec.global_trace_events;
|
|
618
|
+
rb_iseq_trace_set(iseq, global | EVENTS);
|
|
619
|
+
mutable_iseq->aux.exec.global_trace_events = global;
|
|
620
|
+
|
|
621
|
+
// Only a line probe the VM had untraced can go off and come back. One
|
|
622
|
+
// that was already traced belongs to something else, like coverage.
|
|
623
|
+
// Lines ahead of an entry stay armed, since YJIT can jump straight to
|
|
624
|
+
// them from compiled callers.
|
|
625
|
+
unsigned int entry = probes->count;
|
|
626
|
+
for (unsigned int i = 0; i < probes->count; i++) {
|
|
627
|
+
if (probes->events[i] & ENTRIES) {
|
|
628
|
+
entry = i;
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
for (unsigned int i = 0; i < probes->count; i++) {
|
|
633
|
+
int line_only = (probes->events[i] & EVENTS) == RUBY_EVENT_LINE;
|
|
634
|
+
if (!line_only || i < entry || encoded[probes->pc[i]] == probes->plain[i]) probes->plain[i] = 0;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
#if USE_YJIT || USE_ZJIT
|
|
638
|
+
// The interpreter hands an iseq to a JIT at a call count it can no
|
|
639
|
+
// longer reach, so probes that come back are always heard.
|
|
640
|
+
body->jit_entry_calls = ULONG_MAX / 2;
|
|
641
|
+
body->jit_exception_calls = ULONG_MAX / 2;
|
|
642
|
+
#endif
|
|
643
|
+
return Qtrue;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
static VALUE
|
|
647
|
+
tracer_installed_p(VALUE self)
|
|
648
|
+
{
|
|
649
|
+
(void)self;
|
|
650
|
+
return installed ? Qtrue : Qfalse;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
static void
|
|
654
|
+
forget_last(void)
|
|
655
|
+
{
|
|
656
|
+
last_relative = Qnil;
|
|
657
|
+
last_map = Qnil;
|
|
658
|
+
last_receiver = Qnil;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// A window inside the innermost one, which lines go to until it closes.
|
|
662
|
+
static VALUE
|
|
663
|
+
tracer_open_window(VALUE self)
|
|
664
|
+
{
|
|
665
|
+
(void)self;
|
|
666
|
+
rearm();
|
|
667
|
+
rb_ary_push(enclosing, rb_assoc_new(window, receivers));
|
|
668
|
+
window = rb_hash_new();
|
|
669
|
+
receivers = identity_hash();
|
|
670
|
+
forget_last();
|
|
671
|
+
return Qnil;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
static int
|
|
675
|
+
collect_lines(VALUE relative, VALUE map, VALUE result)
|
|
676
|
+
{
|
|
677
|
+
const char *bytes = RSTRING_PTR(map);
|
|
678
|
+
long len = RSTRING_LEN(map);
|
|
679
|
+
VALUE lines = rb_ary_new();
|
|
680
|
+
for (long i = 0; i < len; i++) {
|
|
681
|
+
if (bytes[i]) rb_ary_push(lines, LONG2FIX(i));
|
|
682
|
+
}
|
|
683
|
+
rb_hash_aset(result, relative, lines);
|
|
684
|
+
return ST_CONTINUE;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Splits the innermost window, a test's, by the statements of +iseqw+, the
|
|
688
|
+
// test method, which start at the lines in +starts+.
|
|
689
|
+
static VALUE
|
|
690
|
+
tracer_open_body(VALUE self, VALUE iseqw, VALUE starts)
|
|
691
|
+
{
|
|
692
|
+
(void)self;
|
|
693
|
+
if (body_iseq) rb_raise(rb_eRuntimeError, "a Riptide::Tracer body is already open");
|
|
694
|
+
|
|
695
|
+
body_count = RARRAY_LEN(starts);
|
|
696
|
+
body_starts = ALLOC_N(long, body_count);
|
|
697
|
+
for (long i = 0; i < body_count; i++) body_starts[i] = NUM2LONG(RARRAY_AREF(starts, i));
|
|
698
|
+
body_iseq = rb_iseqw_to_iseq(iseqw);
|
|
699
|
+
body_depth = RARRAY_LEN(enclosing);
|
|
700
|
+
body_windows = rb_hash_new();
|
|
701
|
+
body_times = rb_hash_new();
|
|
702
|
+
body_outer = rb_assoc_new(window, receivers);
|
|
703
|
+
statement = Qnil;
|
|
704
|
+
statement_since = seconds_now();
|
|
705
|
+
return Qnil;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
static int
|
|
709
|
+
collect_statement(VALUE start, VALUE entry, VALUE result)
|
|
710
|
+
{
|
|
711
|
+
VALUE lines = rb_hash_new();
|
|
712
|
+
rb_hash_foreach(RARRAY_AREF(entry, 0), collect_lines, lines);
|
|
713
|
+
VALUE seen = RARRAY_AREF(entry, 1);
|
|
714
|
+
rb_hash_aset(result, start, rb_ary_new_from_args(3, lines, rb_funcall(seen, rb_intern("keys"), 0),
|
|
715
|
+
rb_hash_lookup2(body_times, start, DBL2NUM(0.0))));
|
|
716
|
+
return ST_CONTINUE;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// { statement's first line => [{ relative path => [line, ...] }, [receiver
|
|
720
|
+
// class, ...], seconds] } since the body opened, or nil when none was. Lines
|
|
721
|
+
// go to the test's window again.
|
|
722
|
+
static VALUE
|
|
723
|
+
close_body(void)
|
|
724
|
+
{
|
|
725
|
+
if (!body_iseq) return Qnil;
|
|
726
|
+
|
|
727
|
+
charge_statement();
|
|
728
|
+
VALUE result = rb_hash_new();
|
|
729
|
+
rb_hash_foreach(body_windows, collect_statement, result);
|
|
730
|
+
window = RARRAY_AREF(body_outer, 0);
|
|
731
|
+
receivers = RARRAY_AREF(body_outer, 1);
|
|
732
|
+
ruby_xfree(body_starts);
|
|
733
|
+
body_starts = NULL;
|
|
734
|
+
body_count = 0;
|
|
735
|
+
body_iseq = NULL;
|
|
736
|
+
body_windows = Qnil;
|
|
737
|
+
body_times = Qnil;
|
|
738
|
+
body_outer = Qnil;
|
|
739
|
+
statement = Qnil;
|
|
740
|
+
rearm();
|
|
741
|
+
forget_last();
|
|
742
|
+
return result;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
static VALUE
|
|
746
|
+
tracer_close_body(VALUE self)
|
|
747
|
+
{
|
|
748
|
+
(void)self;
|
|
749
|
+
return close_body();
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// The first line of the statement running now, or nil outside a split body.
|
|
753
|
+
static VALUE
|
|
754
|
+
tracer_statement(VALUE self)
|
|
755
|
+
{
|
|
756
|
+
(void)self;
|
|
757
|
+
return body_iseq ? statement : Qnil;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// [{ relative path => [line, ...] }, [receiver class, ...]] for the
|
|
761
|
+
// innermost window.
|
|
762
|
+
static VALUE
|
|
763
|
+
contents(void)
|
|
764
|
+
{
|
|
765
|
+
VALUE lines = rb_hash_new();
|
|
766
|
+
rb_hash_foreach(window, collect_lines, lines);
|
|
767
|
+
return rb_assoc_new(lines, NIL_P(receivers) ? rb_ary_new() : rb_funcall(receivers, rb_intern("keys"), 0));
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
static VALUE
|
|
771
|
+
tracer_close_window(VALUE self)
|
|
772
|
+
{
|
|
773
|
+
(void)self;
|
|
774
|
+
if (RARRAY_LEN(enclosing) == 0) rb_raise(rb_eRuntimeError, "no Riptide::Tracer window is open");
|
|
775
|
+
|
|
776
|
+
// A body still split when its test's window closes ends with it.
|
|
777
|
+
if (body_iseq && RARRAY_LEN(enclosing) == body_depth) close_body();
|
|
778
|
+
rearm();
|
|
779
|
+
VALUE result = contents();
|
|
780
|
+
VALUE around = rb_ary_pop(enclosing);
|
|
781
|
+
window = RARRAY_AREF(around, 0);
|
|
782
|
+
receivers = RARRAY_AREF(around, 1);
|
|
783
|
+
forget_last();
|
|
784
|
+
return result;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// What the innermost window has seen since it opened or was last drained.
|
|
788
|
+
static VALUE
|
|
789
|
+
tracer_drain(VALUE self)
|
|
790
|
+
{
|
|
791
|
+
(void)self;
|
|
792
|
+
VALUE result = contents();
|
|
793
|
+
window = rb_hash_new();
|
|
794
|
+
if (!NIL_P(receivers)) receivers = identity_hash();
|
|
795
|
+
forget_last();
|
|
796
|
+
return result;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
static VALUE
|
|
800
|
+
drain(VALUE *slot)
|
|
801
|
+
{
|
|
802
|
+
VALUE drained = *slot;
|
|
803
|
+
*slot = rb_hash_new();
|
|
804
|
+
return drained;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
static VALUE
|
|
808
|
+
tracer_drain_load_facts(VALUE self)
|
|
809
|
+
{
|
|
810
|
+
(void)self;
|
|
811
|
+
return drain(&load_facts);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
static VALUE
|
|
815
|
+
tracer_drain_load_called(VALUE self)
|
|
816
|
+
{
|
|
817
|
+
(void)self;
|
|
818
|
+
return drain(&load_called);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
static VALUE
|
|
822
|
+
tracer_owner_files(VALUE self)
|
|
823
|
+
{
|
|
824
|
+
(void)self;
|
|
825
|
+
return owner_files;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
void
|
|
829
|
+
Init_riptide_native(void)
|
|
830
|
+
{
|
|
831
|
+
mRiptide = rb_define_module("Riptide");
|
|
832
|
+
mTracer = rb_define_module_under(mRiptide, "Tracer");
|
|
833
|
+
|
|
834
|
+
stacks = identity_hash();
|
|
835
|
+
load_facts = rb_hash_new();
|
|
836
|
+
load_called = rb_hash_new();
|
|
837
|
+
owner_files = identity_hash();
|
|
838
|
+
window = rb_hash_new();
|
|
839
|
+
enclosing = rb_ary_new();
|
|
840
|
+
|
|
841
|
+
rb_gc_register_address(&stacks);
|
|
842
|
+
rb_gc_register_address(&window);
|
|
843
|
+
rb_gc_register_address(&receivers);
|
|
844
|
+
rb_gc_register_address(&last_receiver);
|
|
845
|
+
rb_gc_register_address(&load_facts);
|
|
846
|
+
rb_gc_register_address(&load_called);
|
|
847
|
+
rb_gc_register_address(&owner_files);
|
|
848
|
+
rb_gc_register_address(&enclosing);
|
|
849
|
+
rb_gc_register_address(&last_relative);
|
|
850
|
+
rb_gc_register_address(&last_map);
|
|
851
|
+
rb_gc_register_address(&last_pinned);
|
|
852
|
+
rb_gc_register_address(&body_windows);
|
|
853
|
+
rb_gc_register_address(&body_times);
|
|
854
|
+
rb_gc_register_address(&body_outer);
|
|
855
|
+
rb_gc_register_address(&statement);
|
|
856
|
+
|
|
857
|
+
rb_define_const(mTracer, "SUPPORTED", Qtrue);
|
|
858
|
+
rb_define_singleton_method(mTracer, "_install", tracer_install, 0);
|
|
859
|
+
rb_define_singleton_method(mTracer, "installed?", tracer_installed_p, 0);
|
|
860
|
+
rb_define_singleton_method(mTracer, "_target", tracer_target, 2);
|
|
861
|
+
rb_define_singleton_method(mTracer, "open_window", tracer_open_window, 0);
|
|
862
|
+
rb_define_singleton_method(mTracer, "_close_window", tracer_close_window, 0);
|
|
863
|
+
rb_define_singleton_method(mTracer, "_drain_load_facts", tracer_drain_load_facts, 0);
|
|
864
|
+
rb_define_singleton_method(mTracer, "_drain_load_called", tracer_drain_load_called, 0);
|
|
865
|
+
rb_define_singleton_method(mTracer, "_drain", tracer_drain, 0);
|
|
866
|
+
rb_define_singleton_method(mTracer, "_owner_files", tracer_owner_files, 0);
|
|
867
|
+
rb_define_singleton_method(mTracer, "_open_body", tracer_open_body, 2);
|
|
868
|
+
rb_define_singleton_method(mTracer, "_close_body", tracer_close_body, 0);
|
|
869
|
+
rb_define_singleton_method(mTracer, "statement", tracer_statement, 0);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
#else
|
|
873
|
+
|
|
874
|
+
#include <ruby.h>
|
|
875
|
+
|
|
876
|
+
static VALUE
|
|
877
|
+
installed_p(VALUE self)
|
|
878
|
+
{
|
|
879
|
+
(void)self;
|
|
880
|
+
return Qfalse;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
void
|
|
884
|
+
Init_riptide_native(void)
|
|
885
|
+
{
|
|
886
|
+
VALUE mTracer = rb_define_module_under(rb_define_module("Riptide"), "Tracer");
|
|
887
|
+
rb_define_const(mTracer, "SUPPORTED", Qfalse);
|
|
888
|
+
rb_define_const(mTracer, "UNSUPPORTED", rb_str_freeze(rb_str_new_cstr(RIPTIDE_UNSUPPORTED)));
|
|
889
|
+
rb_define_singleton_method(mTracer, "installed?", installed_p, 0);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
#endif
|