ext/stackprof/stackprof.c in stackprof-0.2.20 vs ext/stackprof/stackprof.c in stackprof-0.2.21
- old
+ new
@@ -144,10 +144,11 @@
struct sigaction sa;
struct itimerval timer;
VALUE opts = Qnil, mode = Qnil, interval = Qnil, metadata = rb_hash_new(), out = Qfalse;
int ignore_gc = 0;
int raw = 0, aggregate = 1;
+ VALUE metadata_val;
if (_stackprof.running)
return Qfalse;
rb_scan_args(argc, argv, "0:", &opts);
@@ -158,11 +159,11 @@
out = rb_hash_aref(opts, sym_out);
if (RTEST(rb_hash_aref(opts, sym_ignore_gc))) {
ignore_gc = 1;
}
- VALUE metadata_val = rb_hash_aref(opts, sym_metadata);
+ metadata_val = rb_hash_aref(opts, sym_metadata);
if (RTEST(metadata_val)) {
if (!RB_TYPE_P(metadata_val, T_HASH))
rb_raise(rb_eArgError, "metadata should be a hash");
metadata = metadata_val;
@@ -595,18 +596,19 @@
// This must be async-signal-safe
// Returns immediately if another set of frames are already in the buffer
void
stackprof_buffer_sample(void)
{
+ uint64_t start_timestamp = 0;
+ int64_t timestamp_delta = 0;
+ int num;
+
if (_stackprof.buffer_count > 0) {
// Another sample is already pending
return;
}
- uint64_t start_timestamp = 0;
- int64_t timestamp_delta = 0;
- int num;
if (_stackprof.raw) {
struct timestamp_t t;
capture_timestamp(&t);
start_timestamp = timestamp_usec(&t);
timestamp_delta = delta_usec(&_stackprof.last_sample_at, &t);
@@ -826,18 +828,16 @@
}
void
Init_stackprof(void)
{
+ size_t i;
/*
* As of Ruby 3.0, it should be safe to read stack frames at any time, unless YJIT is enabled
* See https://github.com/ruby/ruby/commit/0e276dc458f94d9d79a0f7c7669bde84abe80f21
*/
- #if RUBY_API_VERSION_MAJOR < 3
- stackprof_use_postponed_job = 0;
- #endif
+ stackprof_use_postponed_job = RUBY_API_VERSION_MAJOR < 3;
- size_t i;
#define S(name) sym_##name = ID2SYM(rb_intern(#name));
S(object);
S(custom);
S(wall);
S(cpu);