skylight 0.4.3 → 0.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f853699be749f8141c245b8b45bea6f3b4e2b3f8
4
- data.tar.gz: 646bf5fb1f3366cc3f72f63207905738bc7b178c
3
+ metadata.gz: c7eb484b9fcd3852564008f81d9cdbc1da4ddf11
4
+ data.tar.gz: 37c8da551cbe8d0b460bfcf8346defe265e5a665
5
5
  SHA512:
6
- metadata.gz: 485eae8e30668d6da29b19ad4e44b046684bb4fc0a2ad89490d4f3637b99ef5ab803f07c7bc193b580ee948170ce2069ebb8b17cd88b6eb52861f688677bcb53
7
- data.tar.gz: d43325433073a686d209791c640c3ea1a8ed87dd5848f28b2233582fd1adb66ab8084566a64929a6dbebba82ac9af63cb15c0fd96172c8d5b4dc7f4d47db00c4
6
+ metadata.gz: 8aa90d031fe9903413d71cd4dbb1097fa9566595eadfa288326dd629d98313bd8096547fed9681e49aed8fdbe03b38b1d59621aa8b1f61411e819affebbecafb
7
+ data.tar.gz: 89722c481983864f6e1fbfec52885fa3d10a63587ed324f77356f7276c0b6c63f5da63f5862e79c7a496cf42899588bfefbddfb8cc4fe0b87da94a84fd337c3b
@@ -1,6 +1,7 @@
1
- ## 0.4.3 (November 12, 2014)
2
-
3
- * [BUGFIX] Fix Moped integration when queries include times
1
+ ## 0.5.0 (unreleased)
2
+ * [FEATURE] Track object allocations per span
3
+ * [BUGFIX] Fix exit status in 1.9.2
4
+ * [IMPROVEMENT] Fix C warnings
4
5
 
5
6
  ## 0.4.2 (November 12, 2014)
6
7
 
@@ -135,8 +135,6 @@ def find_file(file, root = nil)
135
135
  end
136
136
  end
137
137
 
138
- # Flag -std=c99 required for older build systems
139
- $CFLAGS << " -std=c99 -pedantic" # -Wall
140
138
  $VPATH << libpath
141
139
 
142
140
  # Where the ruby binding src is
@@ -161,5 +159,28 @@ unless have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
161
159
  have_func('rb_thread_blocking_region') or abort "Ruby is unexpectedly missing rb_thread_blocking_region. This should not happen."
162
160
  end
163
161
 
162
+ # Some extra checks
163
+ # -Werror is needed for the fast thread local storage
164
+ $CFLAGS << " -Werror"
165
+
166
+ checking_for 'fast thread local storage' do
167
+ if try_compile("__thread int foo;")
168
+ $defs << "-DHAVE_FAST_TLS"
169
+ true
170
+ end
171
+ end
172
+
173
+ # spec = nil
174
+ # checking_for('thread_specific', '%s') do
175
+ # spec = %w[__declspec(thread) __thread].find {|th|
176
+ # try_compile("#{th} int foo;", "", :werror => true)
177
+ # }
178
+ # spec or 'no'
179
+ # end
180
+ # $defs << "-DRB_THREAD_SPECIFIC=#{spec}" if spec
181
+
182
+ # Flag -std=c99 required for older build systems
183
+ $CFLAGS << " -std=c99 -pedantic -Wall -fno-strict-aliasing"
184
+
164
185
  # TODO: Compute the relative path to the location
165
186
  create_makefile 'skylight_native', File.expand_path('..', __FILE__) # or fail "could not create makefile"
@@ -1,6 +1,6 @@
1
1
  ---
2
- version: "0.4.0-17128bb"
2
+ version: "0.5.0-72edddd"
3
3
  checksums:
4
- x86-linux: "82f4cbee3ea37896c3f6197799a42750513bcc05e11ab60d897913db56d70be9"
5
- x86_64-linux: "812557897d1713e2e4580644230488edc9f9217fe9e73c312c4353357b3be909"
6
- x86_64-darwin: "9adc46857840d85d5158db6b395b5e1430535a8e15b3b4c880bbd1bdff4a377d"
4
+ x86-linux: "d5935c1b135e1ff63050e4997d5b09324a1fc9249dd2331480c60cca188a64da"
5
+ x86_64-linux: "10229cc6a3fe6e793089ab78c8c01f70b0c4f8d7c6298184cf86ae252b91ffe5"
6
+ x86_64-darwin: "131de21acd4ebe5ae1502a2ae73880af1bc98b78506ee604c522bb0005ef7ff2"
@@ -0,0 +1,109 @@
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
+ get_allocations()->allocations++;
52
+ }
53
+
54
+ void sky_activate_memprof(void) {
55
+ rb_add_event_hook(sky_increment_allocation, RUBY_INTERNAL_EVENT_NEWOBJ, Qnil);
56
+ }
57
+
58
+ void sky_deactivate_memprof(void) {
59
+ rb_remove_event_hook(sky_increment_allocation);
60
+ }
61
+
62
+ uint64_t sky_allocation_count(void) {
63
+ return get_allocations()->allocations;
64
+ }
65
+
66
+ uint64_t sky_consume_allocations() {
67
+ uint64_t ret = get_allocations()->allocations;
68
+ sky_clear_allocation_count();
69
+ return ret;
70
+ }
71
+
72
+ void sky_clear_allocation_count(void) {
73
+ get_allocations()->allocations = 0;
74
+ }
75
+
76
+ int sky_have_memprof(void) {
77
+ return 1;
78
+ }
79
+
80
+ #else
81
+ /*
82
+ *
83
+ * ===== No memory profiling ======
84
+ *
85
+ */
86
+
87
+ void sky_activate_memprof(void) {
88
+ }
89
+
90
+ void sky_deactivate_memprof(void) {
91
+ }
92
+
93
+ uint64_t sky_allocation_count(void) {
94
+ return 0;
95
+ }
96
+
97
+ uint64_t sky_consume_allocations() {
98
+ return 0;
99
+ }
100
+
101
+ void sky_clear_allocation_count(void) {
102
+ }
103
+
104
+ int sky_have_memprof(void) {
105
+ return 0;
106
+ }
107
+
108
+
109
+ #endif
@@ -1,11 +1,14 @@
1
1
  #include <dlfcn.h>
2
2
  #include <ruby.h>
3
3
  #include <skylight_dlopen.h>
4
+ #include <skylight_native.h>
4
5
 
5
6
  #ifdef HAVE_RUBY_ENCODING_H
6
7
  #include <ruby/encoding.h>
7
8
  #endif
8
9
 
10
+ #define UNUSED(x) (void)(x)
11
+
9
12
  #define TO_S(VAL) \
10
13
  RSTRING_PTR(rb_funcall(VAL, rb_intern("to_s"), 0))
11
14
 
@@ -28,22 +31,20 @@
28
31
  } \
29
32
  } while(0) \
30
33
 
31
- #define BUF2STR(buf) \
32
- ({ \
33
- sky_buf_t b = (buf); \
34
- VALUE str = rb_str_new(b.data, b.len); \
35
- rb_enc_associate(str, rb_utf8_encoding()); \
36
- str; \
37
- })
38
-
39
- #define STR2BUF(str) \
40
- ({ \
41
- sky_buf_t buf; \
42
- VALUE s = (str); \
43
- buf.data = RSTRING_PTR(s); \
44
- buf.len = RSTRING_LEN(s); \
45
- buf; \
46
- })
34
+ static inline VALUE
35
+ BUF2STR(sky_buf_t buf) {
36
+ VALUE str = rb_str_new(buf.data, buf.len);
37
+ rb_enc_associate(str, rb_utf8_encoding());
38
+ return str;
39
+ }
40
+
41
+ static inline sky_buf_t
42
+ STR2BUF(VALUE str) {
43
+ return (sky_buf_t) {
44
+ .data = RSTRING_PTR(str),
45
+ .len = RSTRING_LEN(str),
46
+ };
47
+ }
47
48
 
48
49
  #define CHECK_FFI(success, message) \
49
50
  do { \
@@ -65,7 +66,6 @@
65
66
  DATA_PTR(obj) = NULL; \
66
67
 
67
68
  #define Get_Struct(name, obj, Type, msg) \
68
- Type name; \
69
69
  Data_Get_Struct(obj, Type, name); \
70
70
  if (name == NULL) { \
71
71
  rb_raise(rb_eRuntimeError, "%s", msg); \
@@ -115,6 +115,7 @@ static VALUE
115
115
  load_libskylight(VALUE klass, VALUE path) {
116
116
  int res;
117
117
 
118
+ UNUSED(klass);
118
119
  CHECK_TYPE(path, T_STRING);
119
120
 
120
121
  // Already loaded
@@ -140,6 +141,7 @@ load_libskylight(VALUE klass, VALUE path) {
140
141
 
141
142
  static VALUE
142
143
  clock_high_res_time(VALUE self) {
144
+ UNUSED(self);
143
145
  return ULL2NUM(sky_hrtime());
144
146
  }
145
147
 
@@ -153,7 +155,9 @@ static VALUE
153
155
  instrumenter_new(VALUE klass, VALUE rb_env) {
154
156
  sky_instrumenter_t* instrumenter;
155
157
  sky_buf_t env[256];
158
+ int i, envc;
156
159
 
160
+ UNUSED(klass);
157
161
  CHECK_TYPE(rb_env, T_ARRAY);
158
162
 
159
163
  if (RARRAY_LEN(rb_env) >= 256) {
@@ -161,8 +165,7 @@ instrumenter_new(VALUE klass, VALUE rb_env) {
161
165
  return Qnil;
162
166
  }
163
167
 
164
- int i;
165
- int envc = (int) RARRAY_LEN(rb_env);
168
+ envc = (int) RARRAY_LEN(rb_env);
166
169
 
167
170
  for (i = 0; i < envc; ++i) {
168
171
  VALUE val = rb_ary_entry(rb_env, i);
@@ -187,6 +190,8 @@ instrumenter_start_nogvl(sky_instrumenter_t* instrumenter) {
187
190
  */
188
191
 
189
192
  if (sky_instrumenter_start(instrumenter) == 0) {
193
+ sky_activate_memprof();
194
+
190
195
  return (void*) Qtrue;
191
196
  }
192
197
  else {
@@ -196,26 +201,35 @@ instrumenter_start_nogvl(sky_instrumenter_t* instrumenter) {
196
201
 
197
202
  static VALUE
198
203
  instrumenter_start(VALUE self) {
199
- My_Struct(instrumenter, sky_instrumenter_t*, no_instrumenter_msg);
204
+ sky_instrumenter_t* instrumenter;
205
+
206
+ My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
200
207
 
201
208
  return (VALUE) WITHOUT_GVL(instrumenter_start_nogvl, instrumenter);
202
209
  }
203
210
 
204
211
  static VALUE
205
212
  instrumenter_stop(VALUE self) {
206
- My_Struct(instrumenter, sky_instrumenter_t*, no_instrumenter_msg);
213
+ sky_instrumenter_t* instrumenter;
214
+
215
+ My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
207
216
 
208
217
  CHECK_FFI(
209
218
  sky_instrumenter_stop(instrumenter),
210
219
  "native Instrumenter#stop failed");
211
220
 
221
+ sky_deactivate_memprof();
222
+
212
223
  return Qnil;
213
224
  }
214
225
 
215
226
  static VALUE
216
227
  instrumenter_submit_trace(VALUE self, VALUE rb_trace) {
217
- My_Struct(instrumenter, sky_instrumenter_t*, no_instrumenter_msg);
218
- Transfer_Struct(trace, rb_trace, sky_trace_t*, consumed_trace_msg);
228
+ sky_instrumenter_t* instrumenter;
229
+ sky_trace_t* trace;
230
+
231
+ My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
232
+ Transfer_Struct(trace, rb_trace, sky_trace_t, consumed_trace_msg);
219
233
 
220
234
  CHECK_FFI(
221
235
  sky_instrumenter_submit_trace(instrumenter, trace),
@@ -232,23 +246,28 @@ instrumenter_submit_trace(VALUE self, VALUE rb_trace) {
232
246
 
233
247
  static VALUE
234
248
  trace_new(VALUE klass, VALUE start, VALUE uuid, VALUE endpoint) {
249
+ sky_trace_t* trace;
250
+
251
+ UNUSED(klass);
235
252
  CHECK_NUMERIC(start);
236
253
  CHECK_TYPE(uuid, T_STRING);
237
254
  CHECK_TYPE(endpoint, T_STRING);
238
255
 
239
- sky_trace_t* trace;
240
-
241
256
  CHECK_FFI(
242
257
  sky_trace_new(NUM2ULL(start), STR2BUF(uuid), STR2BUF(endpoint), &trace),
243
258
  "native Trace#new failed");
244
259
 
260
+ sky_clear_allocation_count();
261
+
245
262
  return Data_Wrap_Struct(rb_cTrace, NULL, sky_trace_free, trace);
246
263
  }
247
264
 
248
265
  static VALUE
249
266
  trace_get_started_at(VALUE self) {
250
267
  uint64_t start;
251
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
268
+ sky_trace_t* trace;
269
+
270
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
252
271
 
253
272
  CHECK_FFI(
254
273
  sky_trace_start(trace, &start),
@@ -259,8 +278,10 @@ trace_get_started_at(VALUE self) {
259
278
 
260
279
  static VALUE
261
280
  trace_get_endpoint(VALUE self) {
281
+ sky_trace_t* trace;
262
282
  sky_buf_t endpoint;
263
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
283
+
284
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
264
285
 
265
286
  CHECK_FFI(
266
287
  sky_trace_endpoint(trace, &endpoint),
@@ -271,8 +292,10 @@ trace_get_endpoint(VALUE self) {
271
292
 
272
293
  static VALUE
273
294
  trace_set_endpoint(VALUE self, VALUE endpoint) {
295
+ sky_trace_t* trace;
296
+
274
297
  CHECK_TYPE(endpoint, T_STRING);
275
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
298
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
276
299
 
277
300
  CHECK_FFI(
278
301
  sky_trace_set_endpoint(trace, STR2BUF(endpoint)),
@@ -283,8 +306,10 @@ trace_set_endpoint(VALUE self, VALUE endpoint) {
283
306
 
284
307
  static VALUE
285
308
  trace_get_uuid(VALUE self) {
309
+ sky_trace_t* trace;
286
310
  sky_buf_t uuid;
287
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
311
+
312
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
288
313
 
289
314
  CHECK_FFI(
290
315
  sky_trace_uuid(trace, &uuid),
@@ -295,8 +320,10 @@ trace_get_uuid(VALUE self) {
295
320
 
296
321
  static VALUE
297
322
  trace_start_span(VALUE self, VALUE time, VALUE category) {
323
+ sky_trace_t* trace;
298
324
  uint32_t span;
299
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
325
+
326
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
300
327
 
301
328
  CHECK_NUMERIC(time);
302
329
  CHECK_TYPE(category, T_STRING);
@@ -305,16 +332,26 @@ trace_start_span(VALUE self, VALUE time, VALUE category) {
305
332
  sky_trace_instrument(trace, NUM2ULL(time), STR2BUF(category), &span),
306
333
  "native Trace#start_span failed");
307
334
 
335
+ if (sky_have_memprof()) {
336
+ sky_trace_span_add_uint_annotation(trace, span, 2, sky_consume_allocations());
337
+ }
338
+
308
339
  return UINT2NUM(span);
309
340
  }
310
341
 
311
342
  static VALUE
312
343
  trace_stop_span(VALUE self, VALUE span, VALUE time) {
313
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
344
+ sky_trace_t* trace;
345
+
346
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
314
347
 
315
348
  CHECK_NUMERIC(time);
316
349
  CHECK_TYPE(span, T_FIXNUM);
317
350
 
351
+ if (sky_have_memprof()) {
352
+ sky_trace_span_add_uint_annotation(trace, FIX2UINT(span), 1, sky_consume_allocations());
353
+ }
354
+
318
355
  CHECK_FFI(
319
356
  sky_trace_span_done(trace, FIX2UINT(span), NUM2ULL(time)),
320
357
  "native Trace#stop_span failed");
@@ -324,7 +361,9 @@ trace_stop_span(VALUE self, VALUE span, VALUE time) {
324
361
 
325
362
  static VALUE
326
363
  trace_span_set_title(VALUE self, VALUE span, VALUE title) {
327
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
364
+ sky_trace_t* trace;
365
+
366
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
328
367
 
329
368
  CHECK_TYPE(span, T_FIXNUM);
330
369
  CHECK_TYPE(title, T_STRING);
@@ -338,7 +377,9 @@ trace_span_set_title(VALUE self, VALUE span, VALUE title) {
338
377
 
339
378
  static VALUE
340
379
  trace_span_set_description(VALUE self, VALUE span, VALUE desc) {
341
- My_Struct(trace, sky_trace_t*, consumed_trace_msg);
380
+ sky_trace_t* trace;
381
+
382
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
342
383
 
343
384
  CHECK_TYPE(span, T_FIXNUM);
344
385
  CHECK_TYPE(desc, T_STRING);
@@ -0,0 +1,18 @@
1
+ #ifndef __SKYLIGHT_NATIVE__
2
+ #define __SKYLIGHT_NATIVE__
3
+
4
+ #include <stdint.h>
5
+
6
+ void sky_activate_memprof(void);
7
+
8
+ void sky_deactivate_memprof(void);
9
+
10
+ uint64_t sky_allocation_count(void);
11
+
12
+ uint64_t sky_consume_allocations();
13
+
14
+ void sky_clear_allocation_count(void);
15
+
16
+ int sky_have_memprof(void);
17
+
18
+ #endif
@@ -117,18 +117,18 @@ module Skylight
117
117
  end
118
118
 
119
119
  def extract_binds(hash, binds=[])
120
- ret = {}
120
+ hash = hash.dup
121
121
 
122
122
  hash.each do |k,v|
123
123
  if v.is_a?(Hash)
124
- ret[k] = extract_binds(v, binds)[0]
124
+ hash[k] = extract_binds(v, binds)[0]
125
125
  else
126
126
  binds << stringify(hash[k])
127
- ret[k] = '?'
127
+ hash[k] = '?'
128
128
  end
129
129
  end
130
130
 
131
- [ret, binds]
131
+ [hash, binds]
132
132
  end
133
133
 
134
134
  def stringify(value)
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.4.3'
2
+ VERSION = '0.5.0-beta1'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
@@ -41,7 +41,9 @@ files:
41
41
  - bin/skylight
42
42
  - ext/extconf.rb
43
43
  - ext/libskylight.yml
44
+ - ext/skylight_memprof.c
44
45
  - ext/skylight_native.c
46
+ - ext/skylight_native.h
45
47
  - lib/skylight.rb
46
48
  - lib/skylight/api.rb
47
49
  - lib/skylight/cli.rb
@@ -160,9 +162,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
162
  version: 1.9.2
161
163
  required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  requirements:
163
- - - ">="
165
+ - - ">"
164
166
  - !ruby/object:Gem::Version
165
- version: '0'
167
+ version: 1.3.1
166
168
  requirements: []
167
169
  rubyforge_project:
168
170
  rubygems_version: 2.2.2