Skip to content

Commit 6c3f4d7

Browse files
jhawthorntenderlove
andcommitted
Collect stack frames immediately on interrupt
Co-authored-by: Aaron Patterson <[email protected]>
1 parent cf67aff commit 6c3f4d7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/stackprof/stackprof.c

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
#define FAKE_FRAME_MARK INT2FIX(1)
2323
#define FAKE_FRAME_SWEEP INT2FIX(2)
2424

25+
/*
26+
* As of Ruby 3.0, it should be safe to read stack frames at any time
27+
* See https://github.com/ruby/ruby/commit/0e276dc458f94d9d79a0f7c7669bde84abe80f21
28+
*/
29+
#if RUBY_API_VERSION_MAJOR < 3
30+
#define USE_POSTPONED_JOB
31+
#endif
32+
2533
static const char *fake_frame_cstrs[] = {
2634
"(garbage collection)",
2735
"(marking)",
@@ -630,7 +638,11 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
630638
_stackprof.unrecorded_gc_samples++;
631639
rb_postponed_job_register_one(0, stackprof_gc_job_handler, (void*)0);
632640
} else {
641+
#ifdef USE_POSTPONED_JOB
633642
rb_postponed_job_register_one(0, stackprof_job_handler, (void*)0);
643+
#else
644+
stackprof_job_handler(0);
645+
#endif
634646
}
635647
pthread_mutex_unlock(&lock);
636648
}

0 commit comments

Comments
 (0)