Skip to content

Commit

Permalink
use SIGINFO instead
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Dec 4, 2021
1 parent 1c82817 commit 01b4268
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ for match = _methods(+, (Int, Int), -1, get_world_counter())
break # only actually need to do this once
end

# triggers printing the report after a SIGTSTP profile
# triggers printing the report after a SIGINFO profile
const PROF_PEEK_COND = Ref{Base.AsyncCondition}()
function prof_peek()
wait(PROF_PEEK_COND[])
Expand Down
29 changes: 29 additions & 0 deletions src/signal-handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ static size_t jl_safe_read_mem(const volatile char *ptr, char *out, size_t len)
return i;
}

static double profile_autostop_time = -1.0;
static double profile_peek_duration = 1.0; // seconds

double jl_get_profile_peek_duration(void) {
return profile_peek_duration;
}
void jl_set_profile_peek_duration(double t) {
profile_peek_duration = t;
return;
}

uint64_t profile_show_peek_cond_loc;
JL_DLLEXPORT void jl_set_peek_cond(uint64_t cond)
{
profile_show_peek_cond_loc = cond;
return;
}

static void jl_check_profile_autostop(void) {
if ((profile_autostop_time != -1.0) && (jl_hrtime() > profile_autostop_time)) {
profile_autostop_time = -1.0;
jl_profile_stop_timer();
jl_safe_printf("\n==============================================================\n");
jl_safe_printf("Profile collected. A report will print at the next yield point\n");
jl_safe_printf("==============================================================\n\n");
uv_async_send(profile_show_peek_cond_loc);
}
}

#if defined(_WIN32)
#include "signals-win.c"
#else
Expand Down
66 changes: 18 additions & 48 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ bt_context_t *jl_to_bt_context(void *sigctx)
#endif
}

uint64_t profile_show_peek_cond_loc;
JL_DLLEXPORT void jl_set_peek_cond(uint64_t cond)
{
profile_show_peek_cond_loc = cond;
return;
}

static int thread0_exit_count = 0;
static void jl_exit_thread0(int exitstate, jl_bt_element_t *bt_data, size_t bt_size);

Expand Down Expand Up @@ -269,26 +262,6 @@ int exc_reg_is_write_fault(uintptr_t esr) {
}
#endif

static double profile_autostop_time = -1.0;
static double profile_peek_duration = 1.0; // seconds

double jl_get_profile_peek_duration(void) {
return profile_peek_duration;
}
void jl_set_profile_peek_duration(double t) {
profile_peek_duration = t;
return;
}

static void jl_check_profile_autostop(void) {
if ((profile_autostop_time != -1.0) && (jl_hrtime() > profile_autostop_time)) {
profile_autostop_time = -1.0;
jl_profile_stop_timer();
jl_safe_printf("Profile collected. A report will print at the next yield point.\n");
uv_async_send(profile_show_peek_cond_loc);
}
}

#if defined(HAVE_MACH)
#include "signals-mach.c"
#else
Expand Down Expand Up @@ -649,9 +622,6 @@ static void jl_sigsetset(sigset_t *sset)
#else
sigaddset(sset, SIGUSR1);
#endif
#ifdef SIGTSTP
sigaddset(sset, SIGTSTP);
#endif
#if defined(HAVE_TIMER)
sigaddset(sset, SIGUSR1);
#elif defined(HAVE_ITIMER)
Expand All @@ -676,6 +646,18 @@ static void kqueue_signal(int *sigqueue, struct kevent *ev, int sig)
}
#endif

void trigger_profile_peek(void)
{
jl_safe_printf("\n=============================================================================================\n");
jl_safe_printf("Information request received. A stacktrace will print followed by a %.1f second profile report\n", profile_peek_duration);
jl_safe_printf("=============================================================================================\n");
bt_size_cur = 0; // clear profile buffer
if (jl_profile_start_timer() < 0)
jl_safe_printf("ERROR: Could not start profile timer\n");
else
profile_autostop_time = jl_hrtime() + (profile_peek_duration * 1e9);
}

static void *signal_listener(void *arg)
{
static jl_bt_element_t bt_data[JL_MAX_BT_SIZE + 1];
Expand All @@ -697,9 +679,6 @@ static void *signal_listener(void *arg)
kqueue_signal(&sigqueue, &ev, SIGTERM);
kqueue_signal(&sigqueue, &ev, SIGABRT);
kqueue_signal(&sigqueue, &ev, SIGQUIT);
#ifdef SIGTSTP
kqueue_signal(&sigqueue, &ev, SIGTSTP);
#endif
#ifdef SIGINFO
kqueue_signal(&sigqueue, &ev, SIGINFO);
#else
Expand Down Expand Up @@ -784,27 +763,18 @@ static void *signal_listener(void *arg)

int doexit = critical;
#ifdef SIGINFO
if (sig == SIGINFO)
if (sig == SIGINFO) {
if (running != 1)
trigger_profile_peek();
doexit = 0;
}
#else
if (sig == SIGUSR1)
if (running != 1)
trigger_profile_peek();
doexit = 0;
#endif

#ifdef SIGTSTP
if (sig == SIGTSTP) {
if (running != 1) {
jl_safe_printf(" SIGTSTP received. Collecting a %.1f second profile report...\n", profile_peek_duration);
bt_size_cur = 0; // clear profile buffer
if (jl_profile_start_timer() < 0)
jl_safe_printf("ERROR: Could not start profile timer\n");
else
profile_autostop_time = jl_hrtime() + (profile_peek_duration * 1e9);
}
doexit = 0;
}
#endif

bt_size = 0;
#if !defined(JL_DISABLE_LIBUNWIND)
unw_context_t *signal_context;
Expand Down

0 comments on commit 01b4268

Please sign in to comment.