Skip to content

Commit

Permalink
handle uninitialized buffer during profile peek
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Aug 6, 2022
1 parent f6241a5 commit acd1fc0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
93 changes: 47 additions & 46 deletions src/signal-handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,53 @@ static const uint64_t GIGA = 1000000000ULL;
JL_DLLEXPORT void jl_profile_stop_timer(void);
JL_DLLEXPORT int jl_profile_start_timer(void);

///////////////////////
// Utility functions //
///////////////////////
JL_DLLEXPORT int jl_profile_init(size_t maxsize, uint64_t delay_nsec)
{
bt_size_max = maxsize;
nsecprof = delay_nsec;
if (bt_data_prof != NULL)
free((void*)bt_data_prof);
bt_data_prof = (jl_bt_element_t*) calloc(maxsize, sizeof(jl_bt_element_t));
if (bt_data_prof == NULL && maxsize > 0)
return -1;
bt_size_cur = 0;
return 0;
}

JL_DLLEXPORT uint8_t *jl_profile_get_data(void)
{
return (uint8_t*) bt_data_prof;
}

JL_DLLEXPORT size_t jl_profile_len_data(void)
{
return bt_size_cur;
}

JL_DLLEXPORT size_t jl_profile_maxlen_data(void)
{
return bt_size_max;
}

JL_DLLEXPORT uint64_t jl_profile_delay_nsec(void)
{
return nsecprof;
}

JL_DLLEXPORT void jl_profile_clear_data(void)
{
bt_size_cur = 0;
}

JL_DLLEXPORT int jl_profile_is_running(void)
{
return running;
}


// Any function that acquires this lock must be either a unmanaged thread
// or in the GC safe region and must NOT allocate anything through the GC
// while holding this lock.
Expand Down Expand Up @@ -426,52 +473,6 @@ void jl_critical_error(int sig, bt_context_t *context, jl_task_t *ct)
jl_gc_debug_critical_error();
}

///////////////////////
// Utility functions //
///////////////////////
JL_DLLEXPORT int jl_profile_init(size_t maxsize, uint64_t delay_nsec)
{
bt_size_max = maxsize;
nsecprof = delay_nsec;
if (bt_data_prof != NULL)
free((void*)bt_data_prof);
bt_data_prof = (jl_bt_element_t*) calloc(maxsize, sizeof(jl_bt_element_t));
if (bt_data_prof == NULL && maxsize > 0)
return -1;
bt_size_cur = 0;
return 0;
}

JL_DLLEXPORT uint8_t *jl_profile_get_data(void)
{
return (uint8_t*) bt_data_prof;
}

JL_DLLEXPORT size_t jl_profile_len_data(void)
{
return bt_size_cur;
}

JL_DLLEXPORT size_t jl_profile_maxlen_data(void)
{
return bt_size_max;
}

JL_DLLEXPORT uint64_t jl_profile_delay_nsec(void)
{
return nsecprof;
}

JL_DLLEXPORT void jl_profile_clear_data(void)
{
bt_size_cur = 0;
}

JL_DLLEXPORT int jl_profile_is_running(void)
{
return running;
}

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,14 @@ 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\n", profile_peek_duration);
jl_safe_printf("======================================================================================\n");
if (bt_size_max == 0){
// If the buffer hasn't been initialized, initialize with default size
// Keep these values synchronized with Profile.default_init()
if (jl_profile_init(10000000 * jl_n_threads, 1000000) == -1){
jl_safe_printf("ERROR: could not initialize the profile buffer");
return;
}
}
bt_size_cur = 0; // clear profile buffer
if (jl_profile_start_timer() < 0)
jl_safe_printf("ERROR: Could not start profile timer\n");
Expand Down
1 change: 1 addition & 0 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function default_init()
n = 1_000_000
delay = 0.01
else
# Keep these values synchronized with trigger_profile_peek
n = 10_000_000
delay = 0.001
end
Expand Down

0 comments on commit acd1fc0

Please sign in to comment.