truex-skylight 0.6.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 +277 -0
- data/CLA.md +9 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE.md +79 -0
- data/README.md +4 -0
- data/bin/skylight +3 -0
- data/ext/extconf.rb +186 -0
- data/ext/libskylight.yml +6 -0
- data/ext/skylight_memprof.c +115 -0
- data/ext/skylight_native.c +416 -0
- data/ext/skylight_native.h +20 -0
- data/lib/skylight.rb +2 -0
- data/lib/skylight/api.rb +79 -0
- data/lib/skylight/cli.rb +146 -0
- data/lib/skylight/compat.rb +47 -0
- data/lib/skylight/config.rb +498 -0
- data/lib/skylight/core.rb +122 -0
- data/lib/skylight/data/cacert.pem +3894 -0
- data/lib/skylight/formatters/http.rb +17 -0
- data/lib/skylight/gc.rb +107 -0
- data/lib/skylight/helpers.rb +137 -0
- data/lib/skylight/instrumenter.rb +290 -0
- data/lib/skylight/middleware.rb +75 -0
- data/lib/skylight/native.rb +69 -0
- data/lib/skylight/normalizers.rb +133 -0
- data/lib/skylight/normalizers/action_controller/process_action.rb +35 -0
- data/lib/skylight/normalizers/action_controller/send_file.rb +76 -0
- data/lib/skylight/normalizers/action_view/render_collection.rb +18 -0
- data/lib/skylight/normalizers/action_view/render_partial.rb +18 -0
- data/lib/skylight/normalizers/action_view/render_template.rb +18 -0
- data/lib/skylight/normalizers/active_record/sql.rb +79 -0
- data/lib/skylight/normalizers/active_support/cache.rb +50 -0
- data/lib/skylight/normalizers/active_support/cache_clear.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_decrement.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_delete.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_exist.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_generate.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_increment.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_read.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_read_multi.rb +16 -0
- data/lib/skylight/normalizers/active_support/cache_write.rb +16 -0
- data/lib/skylight/normalizers/default.rb +21 -0
- data/lib/skylight/normalizers/moped/query.rb +141 -0
- data/lib/skylight/probes.rb +91 -0
- data/lib/skylight/probes/excon.rb +25 -0
- data/lib/skylight/probes/excon/middleware.rb +65 -0
- data/lib/skylight/probes/net_http.rb +44 -0
- data/lib/skylight/probes/redis.rb +30 -0
- data/lib/skylight/probes/sequel.rb +30 -0
- data/lib/skylight/probes/sinatra.rb +74 -0
- data/lib/skylight/probes/tilt.rb +27 -0
- data/lib/skylight/railtie.rb +122 -0
- data/lib/skylight/sinatra.rb +4 -0
- data/lib/skylight/subscriber.rb +92 -0
- data/lib/skylight/trace.rb +191 -0
- data/lib/skylight/util.rb +16 -0
- data/lib/skylight/util/allocation_free.rb +17 -0
- data/lib/skylight/util/clock.rb +53 -0
- data/lib/skylight/util/gzip.rb +15 -0
- data/lib/skylight/util/hostname.rb +17 -0
- data/lib/skylight/util/http.rb +218 -0
- data/lib/skylight/util/inflector.rb +110 -0
- data/lib/skylight/util/logging.rb +87 -0
- data/lib/skylight/util/multi_io.rb +21 -0
- data/lib/skylight/util/native_ext_fetcher.rb +205 -0
- data/lib/skylight/util/platform.rb +67 -0
- data/lib/skylight/util/ssl.rb +50 -0
- data/lib/skylight/vendor/active_support/notifications.rb +207 -0
- data/lib/skylight/vendor/active_support/notifications/fanout.rb +159 -0
- data/lib/skylight/vendor/active_support/notifications/instrumenter.rb +72 -0
- data/lib/skylight/vendor/active_support/per_thread_registry.rb +52 -0
- data/lib/skylight/vendor/cli/highline.rb +1034 -0
- data/lib/skylight/vendor/cli/highline/color_scheme.rb +134 -0
- data/lib/skylight/vendor/cli/highline/compatibility.rb +16 -0
- data/lib/skylight/vendor/cli/highline/import.rb +41 -0
- data/lib/skylight/vendor/cli/highline/menu.rb +381 -0
- data/lib/skylight/vendor/cli/highline/question.rb +481 -0
- data/lib/skylight/vendor/cli/highline/simulate.rb +48 -0
- data/lib/skylight/vendor/cli/highline/string_extensions.rb +111 -0
- data/lib/skylight/vendor/cli/highline/style.rb +181 -0
- data/lib/skylight/vendor/cli/highline/system_extensions.rb +242 -0
- data/lib/skylight/vendor/cli/thor.rb +473 -0
- data/lib/skylight/vendor/cli/thor/actions.rb +318 -0
- data/lib/skylight/vendor/cli/thor/actions/create_file.rb +105 -0
- data/lib/skylight/vendor/cli/thor/actions/create_link.rb +60 -0
- data/lib/skylight/vendor/cli/thor/actions/directory.rb +119 -0
- data/lib/skylight/vendor/cli/thor/actions/empty_directory.rb +137 -0
- data/lib/skylight/vendor/cli/thor/actions/file_manipulation.rb +314 -0
- data/lib/skylight/vendor/cli/thor/actions/inject_into_file.rb +109 -0
- data/lib/skylight/vendor/cli/thor/base.rb +652 -0
- data/lib/skylight/vendor/cli/thor/command.rb +136 -0
- data/lib/skylight/vendor/cli/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/skylight/vendor/cli/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/skylight/vendor/cli/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/skylight/vendor/cli/thor/error.rb +28 -0
- data/lib/skylight/vendor/cli/thor/group.rb +282 -0
- data/lib/skylight/vendor/cli/thor/invocation.rb +172 -0
- data/lib/skylight/vendor/cli/thor/parser.rb +4 -0
- data/lib/skylight/vendor/cli/thor/parser/argument.rb +74 -0
- data/lib/skylight/vendor/cli/thor/parser/arguments.rb +171 -0
- data/lib/skylight/vendor/cli/thor/parser/option.rb +121 -0
- data/lib/skylight/vendor/cli/thor/parser/options.rb +218 -0
- data/lib/skylight/vendor/cli/thor/rake_compat.rb +72 -0
- data/lib/skylight/vendor/cli/thor/runner.rb +322 -0
- data/lib/skylight/vendor/cli/thor/shell.rb +88 -0
- data/lib/skylight/vendor/cli/thor/shell/basic.rb +393 -0
- data/lib/skylight/vendor/cli/thor/shell/color.rb +148 -0
- data/lib/skylight/vendor/cli/thor/shell/html.rb +127 -0
- data/lib/skylight/vendor/cli/thor/util.rb +270 -0
- data/lib/skylight/vendor/cli/thor/version.rb +3 -0
- data/lib/skylight/vendor/thread_safe.rb +126 -0
- data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +133 -0
- data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +76 -0
- data/lib/skylight/version.rb +4 -0
- data/lib/skylight/vm/gc.rb +70 -0
- data/lib/sql_lexer.rb +6 -0
- data/lib/sql_lexer/lexer.rb +579 -0
- data/lib/sql_lexer/string_scanner.rb +11 -0
- data/lib/sql_lexer/version.rb +3 -0
- metadata +179 -0
data/ext/libskylight.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
---
|
|
2
|
+
version: "0.5.0-fbaa3ed"
|
|
3
|
+
checksums:
|
|
4
|
+
x86-linux: "926a77991c02dfb399de5bc08a39d989803f63eb4992183285e9e663df6e3c7b"
|
|
5
|
+
x86_64-linux: "d44821e2955758d84db1f50b2c2bd0025252f67ab3d42b57e241a8a3f492dbbc"
|
|
6
|
+
x86_64-darwin: "35ac0581f439ffb66a0563f74bce957cd6ec718143a21af9f82fb5e2c43bb80e"
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#include <ruby.h>
|
|
2
|
+
#include <skylight_native.h>
|
|
3
|
+
|
|
4
|
+
#ifdef RUBY_INTERNAL_EVENT_NEWOBJ
|
|
5
|
+
|
|
6
|
+
typedef struct {
|
|
7
|
+
uint64_t allocations;
|
|
8
|
+
} sky_allocations_t;
|
|
9
|
+
|
|
10
|
+
#ifdef HAVE_FAST_TLS
|
|
11
|
+
|
|
12
|
+
// Use the __thread directive
|
|
13
|
+
static __thread sky_allocations_t sky_allocations;
|
|
14
|
+
|
|
15
|
+
static inline sky_allocations_t* get_allocations() {
|
|
16
|
+
return &sky_allocations;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#else
|
|
20
|
+
|
|
21
|
+
#include <pthread.h>
|
|
22
|
+
|
|
23
|
+
// Use pthread thread locals
|
|
24
|
+
static pthread_key_t ALLOCATIONS_KEY;
|
|
25
|
+
|
|
26
|
+
static pthread_once_t KEY_INIT_ONCE = PTHREAD_ONCE_INIT;
|
|
27
|
+
|
|
28
|
+
static void init_allocations_key() {
|
|
29
|
+
pthread_key_create(&ALLOCATIONS_KEY, free);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static sky_allocations_t* get_allocations() {
|
|
33
|
+
sky_allocations_t* ret;
|
|
34
|
+
|
|
35
|
+
// Initialize the TLS key
|
|
36
|
+
pthread_once(&KEY_INIT_ONCE, init_allocations_key);
|
|
37
|
+
|
|
38
|
+
ret = (sky_allocations_t*) pthread_getspecific(ALLOCATIONS_KEY);
|
|
39
|
+
|
|
40
|
+
if (ret == 0) {
|
|
41
|
+
ret = (sky_allocations_t*) malloc(sizeof(sky_allocations_t));
|
|
42
|
+
pthread_setspecific(ALLOCATIONS_KEY, (void*) ret);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return ret;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
static void sky_increment_allocation(rb_event_flag_t flag, VALUE data, VALUE self, ID mid, VALUE klass) {
|
|
51
|
+
UNUSED(flag);
|
|
52
|
+
UNUSED(data);
|
|
53
|
+
UNUSED(self);
|
|
54
|
+
UNUSED(mid);
|
|
55
|
+
UNUSED(klass);
|
|
56
|
+
|
|
57
|
+
get_allocations()->allocations++;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void sky_activate_memprof(void) {
|
|
61
|
+
rb_add_event_hook(sky_increment_allocation, RUBY_INTERNAL_EVENT_NEWOBJ, Qnil);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
void sky_deactivate_memprof(void) {
|
|
65
|
+
rb_remove_event_hook(sky_increment_allocation);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
uint64_t sky_allocation_count(void) {
|
|
69
|
+
return get_allocations()->allocations;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
uint64_t sky_consume_allocations() {
|
|
73
|
+
uint64_t ret = get_allocations()->allocations;
|
|
74
|
+
sky_clear_allocation_count();
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void sky_clear_allocation_count(void) {
|
|
79
|
+
get_allocations()->allocations = 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
int sky_have_memprof(void) {
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#else
|
|
87
|
+
/*
|
|
88
|
+
*
|
|
89
|
+
* ===== No memory profiling ======
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
void sky_activate_memprof(void) {
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void sky_deactivate_memprof(void) {
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
uint64_t sky_allocation_count(void) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
uint64_t sky_consume_allocations() {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void sky_clear_allocation_count(void) {
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
int sky_have_memprof(void) {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
#endif
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
#include <dlfcn.h>
|
|
2
|
+
#include <ruby.h>
|
|
3
|
+
#include <skylight_dlopen.h>
|
|
4
|
+
#include <skylight_native.h>
|
|
5
|
+
|
|
6
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
|
7
|
+
#include <ruby/encoding.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
#define TO_S(VAL) \
|
|
11
|
+
RSTRING_PTR(rb_funcall(VAL, rb_intern("to_s"), 0))
|
|
12
|
+
|
|
13
|
+
#define CHECK_TYPE(VAL, T) \
|
|
14
|
+
do { \
|
|
15
|
+
if (TYPE(VAL) != T) { \
|
|
16
|
+
rb_raise(rb_eArgError, "expected " #VAL " to be " #T " but was '%s' (%s [%i])", \
|
|
17
|
+
TO_S(VAL), rb_obj_classname(VAL), TYPE(VAL)); \
|
|
18
|
+
return Qnil; \
|
|
19
|
+
} \
|
|
20
|
+
} while(0)
|
|
21
|
+
|
|
22
|
+
#define CHECK_NUMERIC(VAL) \
|
|
23
|
+
do { \
|
|
24
|
+
if (TYPE(VAL) != T_BIGNUM && \
|
|
25
|
+
TYPE(VAL) != T_FIXNUM) { \
|
|
26
|
+
rb_raise(rb_eArgError, "expected " #VAL " to be numeric but was '%s' (%s [%i])", \
|
|
27
|
+
TO_S(VAL), rb_obj_classname(VAL), TYPE(VAL)); \
|
|
28
|
+
return Qnil; \
|
|
29
|
+
} \
|
|
30
|
+
} while(0) \
|
|
31
|
+
|
|
32
|
+
static inline VALUE
|
|
33
|
+
BUF2STR(sky_buf_t buf) {
|
|
34
|
+
VALUE str = rb_str_new(buf.data, buf.len);
|
|
35
|
+
rb_enc_associate(str, rb_utf8_encoding());
|
|
36
|
+
return str;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static inline sky_buf_t
|
|
40
|
+
STR2BUF(VALUE str) {
|
|
41
|
+
return (sky_buf_t) {
|
|
42
|
+
.data = RSTRING_PTR(str),
|
|
43
|
+
.len = RSTRING_LEN(str),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#define CHECK_FFI(success, message) \
|
|
48
|
+
do { \
|
|
49
|
+
if ((success) < 0 ) { \
|
|
50
|
+
rb_raise(rb_eRuntimeError, message); \
|
|
51
|
+
return Qnil; \
|
|
52
|
+
} \
|
|
53
|
+
} while(0)
|
|
54
|
+
|
|
55
|
+
#define My_Struct(name, Type, msg) \
|
|
56
|
+
Get_Struct(name, self, Type, msg); \
|
|
57
|
+
|
|
58
|
+
#define Transfer_My_Struct(name, Type, msg) \
|
|
59
|
+
My_Struct(name, Type, msg); \
|
|
60
|
+
DATA_PTR(self) = NULL; \
|
|
61
|
+
|
|
62
|
+
#define Transfer_Struct(name, obj, Type, msg) \
|
|
63
|
+
Get_Struct(name, obj, Type, msg); \
|
|
64
|
+
DATA_PTR(obj) = NULL; \
|
|
65
|
+
|
|
66
|
+
#define Get_Struct(name, obj, Type, msg) \
|
|
67
|
+
Data_Get_Struct(obj, Type, name); \
|
|
68
|
+
if (name == NULL) { \
|
|
69
|
+
rb_raise(rb_eRuntimeError, "%s", msg); \
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Ruby GVL helpers
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
|
|
77
|
+
defined(HAVE_RUBY_THREAD_H)
|
|
78
|
+
|
|
79
|
+
// Ruby 2.0+
|
|
80
|
+
#include <ruby/thread.h>
|
|
81
|
+
typedef void* (*blocking_fn_t)(void*);
|
|
82
|
+
#define WITHOUT_GVL(fn, a) \
|
|
83
|
+
rb_thread_call_without_gvl((blocking_fn_t)(fn), (a), 0, 0)
|
|
84
|
+
|
|
85
|
+
// Ruby 1.9
|
|
86
|
+
#elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
|
87
|
+
|
|
88
|
+
typedef VALUE (*blocking_fn_t)(void*);
|
|
89
|
+
#define WITHOUT_GVL(fn, a) \
|
|
90
|
+
rb_thread_blocking_region((blocking_fn_t)(fn), (a), 0, 0)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
#endif
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Ruby types defined here
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
VALUE rb_mSkylight;
|
|
101
|
+
VALUE rb_mUtil;
|
|
102
|
+
VALUE rb_cClock;
|
|
103
|
+
VALUE rb_cTrace;
|
|
104
|
+
VALUE rb_cInstrumenter;
|
|
105
|
+
|
|
106
|
+
static const char* no_instrumenter_msg =
|
|
107
|
+
"Instrumenter not currently running";
|
|
108
|
+
|
|
109
|
+
static const char* consumed_trace_msg =
|
|
110
|
+
"Trace objects cannot be used once it has been submitted to the instrumenter";
|
|
111
|
+
|
|
112
|
+
static VALUE
|
|
113
|
+
load_libskylight(VALUE klass, VALUE path) {
|
|
114
|
+
int res;
|
|
115
|
+
|
|
116
|
+
UNUSED(klass);
|
|
117
|
+
CHECK_TYPE(path, T_STRING);
|
|
118
|
+
|
|
119
|
+
// Already loaded
|
|
120
|
+
if (sky_hrtime != 0) {
|
|
121
|
+
return Qnil;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
res = sky_load_libskylight(StringValueCStr(path));
|
|
125
|
+
|
|
126
|
+
if (res < 0) {
|
|
127
|
+
rb_raise(rb_eRuntimeError, "[SKYLIGHT] dlerror; msg=%s", dlerror());
|
|
128
|
+
return Qnil;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return Qnil;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
*
|
|
136
|
+
* class Skylight::Util::Clock
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
static VALUE
|
|
141
|
+
clock_high_res_time(VALUE self) {
|
|
142
|
+
UNUSED(self);
|
|
143
|
+
return ULL2NUM(sky_hrtime());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
*
|
|
148
|
+
* class Skylight::Instrumenter
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
static VALUE
|
|
153
|
+
instrumenter_new(VALUE klass, VALUE rb_env) {
|
|
154
|
+
sky_instrumenter_t* instrumenter;
|
|
155
|
+
sky_buf_t env[256];
|
|
156
|
+
int i, envc;
|
|
157
|
+
|
|
158
|
+
UNUSED(klass);
|
|
159
|
+
CHECK_TYPE(rb_env, T_ARRAY);
|
|
160
|
+
|
|
161
|
+
if (RARRAY_LEN(rb_env) >= 256) {
|
|
162
|
+
rb_raise(rb_eArgError, "environment array too long");
|
|
163
|
+
return Qnil;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
envc = (int) RARRAY_LEN(rb_env);
|
|
167
|
+
|
|
168
|
+
for (i = 0; i < envc; ++i) {
|
|
169
|
+
VALUE val = rb_ary_entry(rb_env, i);
|
|
170
|
+
|
|
171
|
+
// Make sure it is a string
|
|
172
|
+
CHECK_TYPE(val, T_STRING);
|
|
173
|
+
|
|
174
|
+
env[i] = STR2BUF(val);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
CHECK_FFI(
|
|
178
|
+
sky_instrumenter_new(env, envc, &instrumenter),
|
|
179
|
+
"failed to initialize instrumenter");
|
|
180
|
+
|
|
181
|
+
return Data_Wrap_Struct(rb_cInstrumenter, NULL, sky_instrumenter_free, instrumenter);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
static void*
|
|
185
|
+
instrumenter_start_nogvl(sky_instrumenter_t* instrumenter) {
|
|
186
|
+
/*
|
|
187
|
+
* Cannot use CHECK_FFI in here
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
if (sky_instrumenter_start(instrumenter) == 0) {
|
|
191
|
+
sky_activate_memprof();
|
|
192
|
+
|
|
193
|
+
return (void*) Qtrue;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return (void*) Qfalse;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static VALUE
|
|
201
|
+
instrumenter_start(VALUE self) {
|
|
202
|
+
sky_instrumenter_t* instrumenter;
|
|
203
|
+
|
|
204
|
+
My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
|
|
205
|
+
|
|
206
|
+
return (VALUE) WITHOUT_GVL(instrumenter_start_nogvl, instrumenter);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static VALUE
|
|
210
|
+
instrumenter_stop(VALUE self) {
|
|
211
|
+
sky_instrumenter_t* instrumenter;
|
|
212
|
+
|
|
213
|
+
My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
|
|
214
|
+
|
|
215
|
+
CHECK_FFI(
|
|
216
|
+
sky_instrumenter_stop(instrumenter),
|
|
217
|
+
"native Instrumenter#stop failed");
|
|
218
|
+
|
|
219
|
+
sky_deactivate_memprof();
|
|
220
|
+
|
|
221
|
+
return Qnil;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static VALUE
|
|
225
|
+
instrumenter_submit_trace(VALUE self, VALUE rb_trace) {
|
|
226
|
+
sky_instrumenter_t* instrumenter;
|
|
227
|
+
sky_trace_t* trace;
|
|
228
|
+
|
|
229
|
+
My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
|
|
230
|
+
Transfer_Struct(trace, rb_trace, sky_trace_t, consumed_trace_msg);
|
|
231
|
+
|
|
232
|
+
CHECK_FFI(
|
|
233
|
+
sky_instrumenter_submit_trace(instrumenter, trace),
|
|
234
|
+
"native Instrumenter#submit_trace failed");
|
|
235
|
+
|
|
236
|
+
return Qnil;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/*
|
|
240
|
+
*
|
|
241
|
+
* class Skylight::Trace
|
|
242
|
+
*
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
static VALUE
|
|
246
|
+
trace_new(VALUE klass, VALUE start, VALUE uuid, VALUE endpoint) {
|
|
247
|
+
sky_trace_t* trace;
|
|
248
|
+
|
|
249
|
+
UNUSED(klass);
|
|
250
|
+
CHECK_NUMERIC(start);
|
|
251
|
+
CHECK_TYPE(uuid, T_STRING);
|
|
252
|
+
CHECK_TYPE(endpoint, T_STRING);
|
|
253
|
+
|
|
254
|
+
CHECK_FFI(
|
|
255
|
+
sky_trace_new(NUM2ULL(start), STR2BUF(uuid), STR2BUF(endpoint), &trace),
|
|
256
|
+
"native Trace#new failed");
|
|
257
|
+
|
|
258
|
+
sky_clear_allocation_count();
|
|
259
|
+
|
|
260
|
+
return Data_Wrap_Struct(rb_cTrace, NULL, sky_trace_free, trace);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static VALUE
|
|
264
|
+
trace_get_started_at(VALUE self) {
|
|
265
|
+
uint64_t start;
|
|
266
|
+
sky_trace_t* trace;
|
|
267
|
+
|
|
268
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
269
|
+
|
|
270
|
+
CHECK_FFI(
|
|
271
|
+
sky_trace_start(trace, &start),
|
|
272
|
+
"native Trace#started_at failed");
|
|
273
|
+
|
|
274
|
+
return ULL2NUM(start);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
static VALUE
|
|
278
|
+
trace_get_endpoint(VALUE self) {
|
|
279
|
+
sky_trace_t* trace;
|
|
280
|
+
sky_buf_t endpoint;
|
|
281
|
+
|
|
282
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
283
|
+
|
|
284
|
+
CHECK_FFI(
|
|
285
|
+
sky_trace_endpoint(trace, &endpoint),
|
|
286
|
+
"native Trace#endpoint failed");
|
|
287
|
+
|
|
288
|
+
return BUF2STR(endpoint);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
static VALUE
|
|
292
|
+
trace_set_endpoint(VALUE self, VALUE endpoint) {
|
|
293
|
+
sky_trace_t* trace;
|
|
294
|
+
|
|
295
|
+
CHECK_TYPE(endpoint, T_STRING);
|
|
296
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
297
|
+
|
|
298
|
+
CHECK_FFI(
|
|
299
|
+
sky_trace_set_endpoint(trace, STR2BUF(endpoint)),
|
|
300
|
+
"native Trace#set_endpoint failed");
|
|
301
|
+
|
|
302
|
+
return Qnil;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
static VALUE
|
|
306
|
+
trace_get_uuid(VALUE self) {
|
|
307
|
+
sky_trace_t* trace;
|
|
308
|
+
sky_buf_t uuid;
|
|
309
|
+
|
|
310
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
311
|
+
|
|
312
|
+
CHECK_FFI(
|
|
313
|
+
sky_trace_uuid(trace, &uuid),
|
|
314
|
+
"native Trace#uuid failed");
|
|
315
|
+
|
|
316
|
+
return BUF2STR(uuid);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
static VALUE
|
|
320
|
+
trace_start_span(VALUE self, VALUE time, VALUE category) {
|
|
321
|
+
sky_trace_t* trace;
|
|
322
|
+
uint32_t span;
|
|
323
|
+
|
|
324
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
325
|
+
|
|
326
|
+
CHECK_NUMERIC(time);
|
|
327
|
+
CHECK_TYPE(category, T_STRING);
|
|
328
|
+
|
|
329
|
+
CHECK_FFI(
|
|
330
|
+
sky_trace_instrument(trace, NUM2ULL(time), STR2BUF(category), &span),
|
|
331
|
+
"native Trace#start_span failed");
|
|
332
|
+
|
|
333
|
+
if (sky_have_memprof()) {
|
|
334
|
+
sky_trace_span_add_uint_annotation(trace, span, 2, sky_consume_allocations());
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return UINT2NUM(span);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
static VALUE
|
|
341
|
+
trace_stop_span(VALUE self, VALUE span, VALUE time) {
|
|
342
|
+
sky_trace_t* trace;
|
|
343
|
+
|
|
344
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
345
|
+
|
|
346
|
+
CHECK_NUMERIC(time);
|
|
347
|
+
CHECK_TYPE(span, T_FIXNUM);
|
|
348
|
+
|
|
349
|
+
if (sky_have_memprof()) {
|
|
350
|
+
sky_trace_span_add_uint_annotation(trace, FIX2UINT(span), 1, sky_consume_allocations());
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
CHECK_FFI(
|
|
354
|
+
sky_trace_span_done(trace, FIX2UINT(span), NUM2ULL(time)),
|
|
355
|
+
"native Trace#stop_span failed");
|
|
356
|
+
|
|
357
|
+
return Qnil;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
static VALUE
|
|
361
|
+
trace_span_set_title(VALUE self, VALUE span, VALUE title) {
|
|
362
|
+
sky_trace_t* trace;
|
|
363
|
+
|
|
364
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
365
|
+
|
|
366
|
+
CHECK_TYPE(span, T_FIXNUM);
|
|
367
|
+
CHECK_TYPE(title, T_STRING);
|
|
368
|
+
|
|
369
|
+
CHECK_FFI(
|
|
370
|
+
sky_trace_span_set_title(trace, FIX2UINT(span), STR2BUF(title)),
|
|
371
|
+
"native Trace#span_set_title failed");
|
|
372
|
+
|
|
373
|
+
return Qnil;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
static VALUE
|
|
377
|
+
trace_span_set_description(VALUE self, VALUE span, VALUE desc) {
|
|
378
|
+
sky_trace_t* trace;
|
|
379
|
+
|
|
380
|
+
My_Struct(trace, sky_trace_t, consumed_trace_msg);
|
|
381
|
+
|
|
382
|
+
CHECK_TYPE(span, T_FIXNUM);
|
|
383
|
+
CHECK_TYPE(desc, T_STRING);
|
|
384
|
+
|
|
385
|
+
CHECK_FFI(
|
|
386
|
+
sky_trace_span_set_desc(trace, FIX2UINT(span), STR2BUF(desc)),
|
|
387
|
+
"native Trace#span_set_description failed");
|
|
388
|
+
|
|
389
|
+
return Qnil;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
void Init_skylight_native() {
|
|
393
|
+
rb_mSkylight = rb_define_module("Skylight");
|
|
394
|
+
rb_define_singleton_method(rb_mSkylight, "load_libskylight", load_libskylight, 1);
|
|
395
|
+
|
|
396
|
+
rb_mUtil = rb_define_module_under(rb_mSkylight, "Util");
|
|
397
|
+
rb_cClock = rb_define_class_under(rb_mUtil, "Clock", rb_cObject);
|
|
398
|
+
rb_define_method(rb_cClock, "native_hrtime", clock_high_res_time, 0);
|
|
399
|
+
|
|
400
|
+
rb_cTrace = rb_define_class_under(rb_mSkylight, "Trace", rb_cObject);
|
|
401
|
+
rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 3);
|
|
402
|
+
rb_define_method(rb_cTrace, "native_get_started_at", trace_get_started_at, 0);
|
|
403
|
+
rb_define_method(rb_cTrace, "native_get_endpoint", trace_get_endpoint, 0);
|
|
404
|
+
rb_define_method(rb_cTrace, "native_set_endpoint", trace_set_endpoint, 1);
|
|
405
|
+
rb_define_method(rb_cTrace, "native_get_uuid", trace_get_uuid, 0);
|
|
406
|
+
rb_define_method(rb_cTrace, "native_start_span", trace_start_span, 2);
|
|
407
|
+
rb_define_method(rb_cTrace, "native_stop_span", trace_stop_span, 2);
|
|
408
|
+
rb_define_method(rb_cTrace, "native_span_set_title", trace_span_set_title, 2);
|
|
409
|
+
rb_define_method(rb_cTrace, "native_span_set_description", trace_span_set_description, 2);
|
|
410
|
+
|
|
411
|
+
rb_cInstrumenter = rb_define_class_under(rb_mSkylight, "Instrumenter", rb_cObject);
|
|
412
|
+
rb_define_singleton_method(rb_cInstrumenter, "native_new", instrumenter_new, 1);
|
|
413
|
+
rb_define_method(rb_cInstrumenter, "native_start", instrumenter_start, 0);
|
|
414
|
+
rb_define_method(rb_cInstrumenter, "native_stop", instrumenter_stop, 0);
|
|
415
|
+
rb_define_method(rb_cInstrumenter, "native_submit_trace", instrumenter_submit_trace, 1);
|
|
416
|
+
}
|