-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm_probes.c
106 lines (101 loc) · 3.83 KB
/
vm_probes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <ruby/ruby.h>
#include "tracing_mechanism.h"
#define ALL_EVENTS (RUBY_EVENT_LINE \
| RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN \
| RUBY_EVENT_RAISE \
| RUBY_EVENT_SWITCH | RUBY_EVENT_TH_INIT | RUBY_EVENT_TH_TERM \
| RUBY_EVENT_RESCUE \
| RUBY_EVENT_OBJ_ALLOC | RUBY_EVENT_OBJ_FREE \
| RUBY_EVENT_GC_START | RUBY_EVENT_GC_END)
static void
event_hook(rb_event_flag_t flags, VALUE data, VALUE obj, VALUE id, VALUE klass)
{
if ((flags & RUBY_EVENT_LINE) && TRACE_LINE_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_LINE(filename, line);
}
if ((flags & (RUBY_EVENT_CALL|RUBY_EVENT_C_CALL)) && TRACE_METHOD_ENTRY_ENABLED()) {
const char *meth;
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
switch (id) {
case 0:
meth = "<unknown>";
break;
case 1: /* ID_ALLOCATOR */
meth = "allocate";
break;
default:
meth = rb_id2name(id);
if (!meth)
meth = "<unknown>";
break;
}
FIRE_METHOD_ENTRY(obj, rb_class2name(klass), meth, filename, line);
}
if ((flags & (RUBY_EVENT_RETURN|RUBY_EVENT_C_RETURN)) && TRACE_METHOD_RETURN_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_METHOD_RETURN(obj, rb_class2name(klass), rb_id2name(id), filename, line);
}
if ((flags & (RUBY_EVENT_RAISE)) && TRACE_RAISE_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
obj = rb_gv_get("$!");
klass = CLASS_OF(obj);
FIRE_RAISE(obj, rb_class2name(klass), filename, line);
}
if ((flags & (RUBY_EVENT_SWITCH)) && TRACE_THREAD_LEAVE_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_THREAD_LEAVE(obj, filename, line);
}
if (flags & RUBY_EVENT_TH_INIT) {
rb_thread_add_event_hook(obj, event_hook, ALL_EVENTS, Qnil);
if (TRACE_THREAD_INIT_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_THREAD_INIT(obj, filename, line);
}
}
if ((flags & (RUBY_EVENT_TH_TERM)) && TRACE_THREAD_TERM_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_THREAD_TERM(obj, filename, line);
}
if ((flags & (RUBY_EVENT_RESCUE)) && TRACE_RESCUE_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
obj = rb_gv_get("$!");
klass = CLASS_OF(obj);
FIRE_RESCUE(obj, rb_class2name(klass), filename, line);
}
if ((flags & (RUBY_EVENT_OBJ_ALLOC)) && TRACE_OBJECT_CREATE_ENABLED()) {
const char *filename = rb_sourcefile();
int line = rb_sourceline();
if (!filename) filename = "<unknown>";
FIRE_OBJECT_CREATE(obj, filename, line);
}
if ((flags & (RUBY_EVENT_OBJ_FREE)) && TRACE_OBJECT_FREE_ENABLED()) {
FIRE_OBJECT_FREE(obj);
}
if ((flags & (RUBY_EVENT_GC_START)) && TRACE_GC_START_ENABLED()) {
FIRE_GC_START();
}
if ((flags & (RUBY_EVENT_GC_END)) && TRACE_GC_END_ENABLED()) {
FIRE_GC_END();
}
}
void Init_vm_probes()
{
rb_add_event_hook(event_hook, ALL_EVENTS, Qnil);
}