Skip to content

Commit 01b4268

Browse files
use SIGINFO instead
1 parent 1c82817 commit 01b4268

File tree

3 files changed

+48
-49
lines changed

3 files changed

+48
-49
lines changed

base/Base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ for match = _methods(+, (Int, Int), -1, get_world_counter())
457457
break # only actually need to do this once
458458
end
459459

460-
# triggers printing the report after a SIGTSTP profile
460+
# triggers printing the report after a SIGINFO profile
461461
const PROF_PEEK_COND = Ref{Base.AsyncCondition}()
462462
function prof_peek()
463463
wait(PROF_PEEK_COND[])

src/signal-handling.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,35 @@ static size_t jl_safe_read_mem(const volatile char *ptr, char *out, size_t len)
129129
return i;
130130
}
131131

132+
static double profile_autostop_time = -1.0;
133+
static double profile_peek_duration = 1.0; // seconds
134+
135+
double jl_get_profile_peek_duration(void) {
136+
return profile_peek_duration;
137+
}
138+
void jl_set_profile_peek_duration(double t) {
139+
profile_peek_duration = t;
140+
return;
141+
}
142+
143+
uint64_t profile_show_peek_cond_loc;
144+
JL_DLLEXPORT void jl_set_peek_cond(uint64_t cond)
145+
{
146+
profile_show_peek_cond_loc = cond;
147+
return;
148+
}
149+
150+
static void jl_check_profile_autostop(void) {
151+
if ((profile_autostop_time != -1.0) && (jl_hrtime() > profile_autostop_time)) {
152+
profile_autostop_time = -1.0;
153+
jl_profile_stop_timer();
154+
jl_safe_printf("\n==============================================================\n");
155+
jl_safe_printf("Profile collected. A report will print at the next yield point\n");
156+
jl_safe_printf("==============================================================\n\n");
157+
uv_async_send(profile_show_peek_cond_loc);
158+
}
159+
}
160+
132161
#if defined(_WIN32)
133162
#include "signals-win.c"
134163
#else

src/signals-unix.c

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ bt_context_t *jl_to_bt_context(void *sigctx)
6161
#endif
6262
}
6363

64-
uint64_t profile_show_peek_cond_loc;
65-
JL_DLLEXPORT void jl_set_peek_cond(uint64_t cond)
66-
{
67-
profile_show_peek_cond_loc = cond;
68-
return;
69-
}
70-
7164
static int thread0_exit_count = 0;
7265
static void jl_exit_thread0(int exitstate, jl_bt_element_t *bt_data, size_t bt_size);
7366

@@ -269,26 +262,6 @@ int exc_reg_is_write_fault(uintptr_t esr) {
269262
}
270263
#endif
271264

272-
static double profile_autostop_time = -1.0;
273-
static double profile_peek_duration = 1.0; // seconds
274-
275-
double jl_get_profile_peek_duration(void) {
276-
return profile_peek_duration;
277-
}
278-
void jl_set_profile_peek_duration(double t) {
279-
profile_peek_duration = t;
280-
return;
281-
}
282-
283-
static void jl_check_profile_autostop(void) {
284-
if ((profile_autostop_time != -1.0) && (jl_hrtime() > profile_autostop_time)) {
285-
profile_autostop_time = -1.0;
286-
jl_profile_stop_timer();
287-
jl_safe_printf("Profile collected. A report will print at the next yield point.\n");
288-
uv_async_send(profile_show_peek_cond_loc);
289-
}
290-
}
291-
292265
#if defined(HAVE_MACH)
293266
#include "signals-mach.c"
294267
#else
@@ -649,9 +622,6 @@ static void jl_sigsetset(sigset_t *sset)
649622
#else
650623
sigaddset(sset, SIGUSR1);
651624
#endif
652-
#ifdef SIGTSTP
653-
sigaddset(sset, SIGTSTP);
654-
#endif
655625
#if defined(HAVE_TIMER)
656626
sigaddset(sset, SIGUSR1);
657627
#elif defined(HAVE_ITIMER)
@@ -676,6 +646,18 @@ static void kqueue_signal(int *sigqueue, struct kevent *ev, int sig)
676646
}
677647
#endif
678648

649+
void trigger_profile_peek(void)
650+
{
651+
jl_safe_printf("\n=============================================================================================\n");
652+
jl_safe_printf("Information request received. A stacktrace will print followed by a %.1f second profile report\n", profile_peek_duration);
653+
jl_safe_printf("=============================================================================================\n");
654+
bt_size_cur = 0; // clear profile buffer
655+
if (jl_profile_start_timer() < 0)
656+
jl_safe_printf("ERROR: Could not start profile timer\n");
657+
else
658+
profile_autostop_time = jl_hrtime() + (profile_peek_duration * 1e9);
659+
}
660+
679661
static void *signal_listener(void *arg)
680662
{
681663
static jl_bt_element_t bt_data[JL_MAX_BT_SIZE + 1];
@@ -697,9 +679,6 @@ static void *signal_listener(void *arg)
697679
kqueue_signal(&sigqueue, &ev, SIGTERM);
698680
kqueue_signal(&sigqueue, &ev, SIGABRT);
699681
kqueue_signal(&sigqueue, &ev, SIGQUIT);
700-
#ifdef SIGTSTP
701-
kqueue_signal(&sigqueue, &ev, SIGTSTP);
702-
#endif
703682
#ifdef SIGINFO
704683
kqueue_signal(&sigqueue, &ev, SIGINFO);
705684
#else
@@ -784,27 +763,18 @@ static void *signal_listener(void *arg)
784763

785764
int doexit = critical;
786765
#ifdef SIGINFO
787-
if (sig == SIGINFO)
766+
if (sig == SIGINFO) {
767+
if (running != 1)
768+
trigger_profile_peek();
788769
doexit = 0;
770+
}
789771
#else
790772
if (sig == SIGUSR1)
773+
if (running != 1)
774+
trigger_profile_peek();
791775
doexit = 0;
792776
#endif
793777

794-
#ifdef SIGTSTP
795-
if (sig == SIGTSTP) {
796-
if (running != 1) {
797-
jl_safe_printf(" SIGTSTP received. Collecting a %.1f second profile report...\n", profile_peek_duration);
798-
bt_size_cur = 0; // clear profile buffer
799-
if (jl_profile_start_timer() < 0)
800-
jl_safe_printf("ERROR: Could not start profile timer\n");
801-
else
802-
profile_autostop_time = jl_hrtime() + (profile_peek_duration * 1e9);
803-
}
804-
doexit = 0;
805-
}
806-
#endif
807-
808778
bt_size = 0;
809779
#if !defined(JL_DISABLE_LIBUNWIND)
810780
unw_context_t *signal_context;

0 commit comments

Comments
 (0)