Implement the prof.gdump mallctl.
This feature makes it possible to toggle the gdump feature on/off during program execution, whereas the the opt.prof_dump mallctl value can only be set during program startup. This resolves #72.
This commit is contained in:
@@ -213,7 +213,8 @@ chunk_register(void *chunk, size_t size, bool base)
|
||||
} else if (config_prof)
|
||||
gdump = false;
|
||||
malloc_mutex_unlock(&chunks_mtx);
|
||||
if (config_prof && opt_prof && opt_prof_gdump && gdump)
|
||||
if (config_prof && opt_prof && prof_gdump_get_unlocked() &&
|
||||
gdump)
|
||||
prof_gdump();
|
||||
}
|
||||
if (config_valgrind)
|
||||
|
27
src/ctl.c
27
src/ctl.c
@@ -137,6 +137,7 @@ CTL_PROTO(arenas_extend)
|
||||
CTL_PROTO(prof_thread_active_init)
|
||||
CTL_PROTO(prof_active)
|
||||
CTL_PROTO(prof_dump)
|
||||
CTL_PROTO(prof_gdump)
|
||||
CTL_PROTO(prof_reset)
|
||||
CTL_PROTO(prof_interval)
|
||||
CTL_PROTO(lg_prof_sample)
|
||||
@@ -347,6 +348,7 @@ static const ctl_named_node_t prof_node[] = {
|
||||
{NAME("thread_active_init"), CTL(prof_thread_active_init)},
|
||||
{NAME("active"), CTL(prof_active)},
|
||||
{NAME("dump"), CTL(prof_dump)},
|
||||
{NAME("gdump"), CTL(prof_gdump)},
|
||||
{NAME("reset"), CTL(prof_reset)},
|
||||
{NAME("interval"), CTL(prof_interval)},
|
||||
{NAME("lg_sample"), CTL(lg_prof_sample)}
|
||||
@@ -1790,6 +1792,31 @@ label_return:
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
prof_gdump_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
{
|
||||
int ret;
|
||||
bool oldval;
|
||||
|
||||
if (!config_prof)
|
||||
return (ENOENT);
|
||||
|
||||
if (newp != NULL) {
|
||||
if (newlen != sizeof(bool)) {
|
||||
ret = EINVAL;
|
||||
goto label_return;
|
||||
}
|
||||
oldval = prof_gdump_set(*(bool *)newp);
|
||||
} else
|
||||
oldval = prof_gdump_get();
|
||||
READ(oldval, bool);
|
||||
|
||||
ret = 0;
|
||||
label_return:
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
prof_reset_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
|
34
src/prof.c
34
src/prof.c
@@ -44,6 +44,13 @@ static malloc_mutex_t prof_active_mtx;
|
||||
static bool prof_thread_active_init;
|
||||
static malloc_mutex_t prof_thread_active_init_mtx;
|
||||
|
||||
/*
|
||||
* Initialized as opt_prof_gdump, and accessed via
|
||||
* prof_gdump_[gs]et{_unlocked,}().
|
||||
*/
|
||||
bool prof_gdump_val;
|
||||
static malloc_mutex_t prof_gdump_mtx;
|
||||
|
||||
uint64_t prof_interval = 0;
|
||||
|
||||
size_t lg_prof_sample;
|
||||
@@ -1961,6 +1968,29 @@ prof_thread_active_init_set(bool active_init)
|
||||
return (active_init_old);
|
||||
}
|
||||
|
||||
bool
|
||||
prof_gdump_get(void)
|
||||
{
|
||||
bool prof_gdump_current;
|
||||
|
||||
malloc_mutex_lock(&prof_gdump_mtx);
|
||||
prof_gdump_current = prof_gdump_val;
|
||||
malloc_mutex_unlock(&prof_gdump_mtx);
|
||||
return (prof_gdump_current);
|
||||
}
|
||||
|
||||
bool
|
||||
prof_gdump_set(bool gdump)
|
||||
{
|
||||
bool prof_gdump_old;
|
||||
|
||||
malloc_mutex_lock(&prof_gdump_mtx);
|
||||
prof_gdump_old = prof_gdump_val;
|
||||
prof_gdump_val = gdump;
|
||||
malloc_mutex_unlock(&prof_gdump_mtx);
|
||||
return (prof_gdump_old);
|
||||
}
|
||||
|
||||
void
|
||||
prof_boot0(void)
|
||||
{
|
||||
@@ -2013,6 +2043,10 @@ prof_boot2(void)
|
||||
if (malloc_mutex_init(&prof_active_mtx))
|
||||
return (true);
|
||||
|
||||
prof_gdump_val = opt_prof_gdump;
|
||||
if (malloc_mutex_init(&prof_gdump_mtx))
|
||||
return (true);
|
||||
|
||||
prof_thread_active_init = opt_prof_thread_active_init;
|
||||
if (malloc_mutex_init(&prof_thread_active_init_mtx))
|
||||
return (true);
|
||||
|
Reference in New Issue
Block a user