Skip to content

Commit 4be4ea0

Browse files
handle uninitialized buffer during profile peek
1 parent f6241a5 commit 4be4ea0

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

src/signal-handling.c

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,52 @@ static const uint64_t GIGA = 1000000000ULL;
2929
JL_DLLEXPORT void jl_profile_stop_timer(void);
3030
JL_DLLEXPORT int jl_profile_start_timer(void);
3131

32+
///////////////////////
33+
// Utility functions //
34+
///////////////////////
35+
JL_DLLEXPORT int jl_profile_init(size_t maxsize, uint64_t delay_nsec)
36+
{
37+
bt_size_max = maxsize;
38+
nsecprof = delay_nsec;
39+
if (bt_data_prof != NULL)
40+
free((void*)bt_data_prof);
41+
bt_data_prof = (jl_bt_element_t*) calloc(maxsize, sizeof(jl_bt_element_t));
42+
if (bt_data_prof == NULL && maxsize > 0)
43+
return -1;
44+
bt_size_cur = 0;
45+
return 0;
46+
}
47+
48+
JL_DLLEXPORT uint8_t *jl_profile_get_data(void)
49+
{
50+
return (uint8_t*) bt_data_prof;
51+
}
52+
53+
JL_DLLEXPORT size_t jl_profile_len_data(void)
54+
{
55+
return bt_size_cur;
56+
}
57+
58+
JL_DLLEXPORT size_t jl_profile_maxlen_data(void)
59+
{
60+
return bt_size_max;
61+
}
62+
63+
JL_DLLEXPORT uint64_t jl_profile_delay_nsec(void)
64+
{
65+
return nsecprof;
66+
}
67+
68+
JL_DLLEXPORT void jl_profile_clear_data(void)
69+
{
70+
bt_size_cur = 0;
71+
}
72+
73+
JL_DLLEXPORT int jl_profile_is_running(void)
74+
{
75+
return running;
76+
}
77+
3278
// Any function that acquires this lock must be either a unmanaged thread
3379
// or in the GC safe region and must NOT allocate anything through the GC
3480
// while holding this lock.
@@ -426,52 +472,6 @@ void jl_critical_error(int sig, bt_context_t *context, jl_task_t *ct)
426472
jl_gc_debug_critical_error();
427473
}
428474

429-
///////////////////////
430-
// Utility functions //
431-
///////////////////////
432-
JL_DLLEXPORT int jl_profile_init(size_t maxsize, uint64_t delay_nsec)
433-
{
434-
bt_size_max = maxsize;
435-
nsecprof = delay_nsec;
436-
if (bt_data_prof != NULL)
437-
free((void*)bt_data_prof);
438-
bt_data_prof = (jl_bt_element_t*) calloc(maxsize, sizeof(jl_bt_element_t));
439-
if (bt_data_prof == NULL && maxsize > 0)
440-
return -1;
441-
bt_size_cur = 0;
442-
return 0;
443-
}
444-
445-
JL_DLLEXPORT uint8_t *jl_profile_get_data(void)
446-
{
447-
return (uint8_t*) bt_data_prof;
448-
}
449-
450-
JL_DLLEXPORT size_t jl_profile_len_data(void)
451-
{
452-
return bt_size_cur;
453-
}
454-
455-
JL_DLLEXPORT size_t jl_profile_maxlen_data(void)
456-
{
457-
return bt_size_max;
458-
}
459-
460-
JL_DLLEXPORT uint64_t jl_profile_delay_nsec(void)
461-
{
462-
return nsecprof;
463-
}
464-
465-
JL_DLLEXPORT void jl_profile_clear_data(void)
466-
{
467-
bt_size_cur = 0;
468-
}
469-
470-
JL_DLLEXPORT int jl_profile_is_running(void)
471-
{
472-
return running;
473-
}
474-
475475
#ifdef __cplusplus
476476
}
477477
#endif

src/signals-unix.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,14 @@ void trigger_profile_peek(void)
698698
jl_safe_printf("\n======================================================================================\n");
699699
jl_safe_printf("Information request received. A stacktrace will print followed by a %.1f second profile\n", profile_peek_duration);
700700
jl_safe_printf("======================================================================================\n");
701+
if (bt_size_max == 0){
702+
// If the buffer hasn't been initialized, initialize with default size
703+
// Keep these values synchronized with Profile.default_init()
704+
if (jl_profile_init(10000000 * jl_n_threads, 1000000) == -1){
705+
jl_safe_printf("ERROR: could not initialize the profile buffer");
706+
return;
707+
}
708+
}
701709
bt_size_cur = 0; // clear profile buffer
702710
if (jl_profile_start_timer() < 0)
703711
jl_safe_printf("ERROR: Could not start profile timer\n");

stdlib/Profile/src/Profile.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function default_init()
138138
n = 1_000_000
139139
delay = 0.01
140140
else
141+
# Keep these values synchronized with trigger_profile_peek
141142
n = 10_000_000
142143
delay = 0.001
143144
end

0 commit comments

Comments
 (0)